diff options
author | John MacFarlane <jgm@berkeley.edu> | 2017-02-20 20:52:00 +0100 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2017-02-20 20:52:00 +0100 |
commit | ce8226f1a7d64da56117d2f7f351e06225a84614 (patch) | |
tree | 9f2d716df0230f5f17372f19b8718dcf86039fd9 /src/Text/Pandoc/CSS.hs | |
parent | e86e44b98e592d5a5e4c6b43d9b57b195f091ed9 (diff) | |
parent | 12d96508c62189b4ff8c8b797d34cc9ef177f5ee (diff) | |
download | pandoc-ce8226f1a7d64da56117d2f7f351e06225a84614.tar.gz |
Merge commit '9e52ac6bb02afd7b4ed5dad61021a1fa33051203' as 'data/templates'
Diffstat (limited to 'src/Text/Pandoc/CSS.hs')
-rw-r--r-- | src/Text/Pandoc/CSS.hs | 43 |
1 files changed, 0 insertions, 43 deletions
diff --git a/src/Text/Pandoc/CSS.hs b/src/Text/Pandoc/CSS.hs deleted file mode 100644 index f479ed9d0..000000000 --- a/src/Text/Pandoc/CSS.hs +++ /dev/null @@ -1,43 +0,0 @@ -module Text.Pandoc.CSS ( foldOrElse - , pickStyleAttrProps - , pickStylesToKVs - ) -where - -import Text.Pandoc.Shared (trim) -import Text.Parsec -import Text.Parsec.String - -ruleParser :: Parser (String, String) -ruleParser = do - p <- many1 (noneOf ":") <* char ':' - v <- many1 (noneOf ":;") <* (optional $ char ';') <* spaces - return (trim p, trim v) - -styleAttrParser :: Parser [(String, String)] -styleAttrParser = many1 ruleParser - -orElse :: Eq a => a -> a -> a -> a -orElse v x y = if v == x then y else x - -foldOrElse :: Eq a => a -> [a] -> a -foldOrElse v xs = foldr (orElse v) v xs - -eitherToMaybe :: Either a b -> Maybe b -eitherToMaybe (Right x) = Just x -eitherToMaybe _ = Nothing - --- | takes a list of keys/properties and a CSS string and --- returns the corresponding key-value-pairs. -pickStylesToKVs :: [String] -> String -> [(String, String)] -pickStylesToKVs props styleAttr = - case parse styleAttrParser "" styleAttr of - Left _ -> [] - Right styles -> filter (\s -> fst s `elem` props) styles - --- | takes a list of key/property synonyms and a CSS string and maybe --- returns the value of the first match (in order of the supplied list) -pickStyleAttrProps :: [String] -> String -> Maybe String -pickStyleAttrProps lookupProps styleAttr = do - styles <- eitherToMaybe $ parse styleAttrParser "" styleAttr - foldOrElse Nothing $ map (flip lookup styles) lookupProps |