librarify langfilter too
This commit is contained in:
parent
1098cbdc1b
commit
89270a82fb
9 changed files with 35 additions and 23 deletions
31
langfilter/lib/Lang.hs
Normal file
31
langfilter/lib/Lang.hs
Normal file
|
@ -0,0 +1,31 @@
|
|||
module Lang where
|
||||
|
||||
import Text.Pandoc.Definition
|
||||
import Data.Char (toLower)
|
||||
import qualified Data.Text as Text
|
||||
import System.IO
|
||||
import Data.Text (Text)
|
||||
|
||||
data Lang = Lántas deriving (Eq, Show)
|
||||
|
||||
type Vars = (?lang :: Maybe Lang, ?defColor :: Text)
|
||||
|
||||
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 ℓ
|
||||
pure Nothing
|
||||
|
||||
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
|
Loading…
Add table
Add a link
Reference in a new issue