2021-04-29 05:52:44 -04:00
|
|
|
|
module Lang where
|
|
|
|
|
|
|
|
|
|
import Text.Pandoc.Definition
|
|
|
|
|
import Data.Char (toLower)
|
|
|
|
|
import qualified Data.Text as Text
|
|
|
|
|
import System.IO
|
2024-06-02 21:33:36 -04:00
|
|
|
|
import Data.Text (Text)
|
2021-04-29 05:52:44 -04:00
|
|
|
|
|
|
|
|
|
data Lang = Lántas deriving (Eq, Show)
|
|
|
|
|
|
2024-06-02 21:33:36 -04:00
|
|
|
|
type Vars = (?lang :: Maybe Lang, ?defColor :: Text)
|
2021-04-29 05:52:44 -04:00
|
|
|
|
|
2024-06-02 21:33:36 -04:00
|
|
|
|
toText :: Maybe MetaValue -> IO (Maybe Text)
|
|
|
|
|
toText (Just (MetaInlines [Str s])) = toText (Just (MetaString s)) -- ugh
|
|
|
|
|
toText (Just (MetaString s)) = pure $ Just s
|
|
|
|
|
toText Nothing = pure Nothing
|
|
|
|
|
toText (Just ℓ) = do
|
|
|
|
|
hPutStrLn stderr $ "[WARN] expected a string, got: " <> show ℓ
|
2021-04-29 05:52:44 -04:00
|
|
|
|
pure Nothing
|
2024-06-02 21:33:36 -04:00
|
|
|
|
|
|
|
|
|
toLang :: Maybe MetaValue -> IO (Maybe Lang)
|
|
|
|
|
toLang m = do
|
|
|
|
|
mres <- fmap (Text.map toLower) <$> toText m
|
|
|
|
|
case mres of
|
|
|
|
|
Just res -> do
|
|
|
|
|
if res `elem` ["laantas", "lántas"] then
|
|
|
|
|
pure $ Just Lántas
|
|
|
|
|
else do
|
|
|
|
|
hPutStrLn stderr $ "[WARN] unknown language: " <> show res
|
|
|
|
|
pure Nothing
|
|
|
|
|
Nothing -> pure Nothing
|