1module Text.Pandoc.CSS ( foldOrElse
7import Text.Pandoc.Shared (trim)
9import Text.Parsec.String
11ruleParser :: Parser (String, String)
13 p <- many1 (noneOf ":") <* char ':'
14 v <- many1 (noneOf ":;") <* (optional $ char ';') <* spaces
15 return (trim p, trim v)
17styleAttrParser :: Parser [(String, String)]
18styleAttrParser = many1 ruleParser
20orElse :: Eq a => a -> a -> a -> a
21orElse v x y = if v == x then y else x
23foldOrElse :: Eq a => a -> [a] -> a
24foldOrElse v xs = foldr (orElse v) v xs
26eitherToMaybe :: Either a b -> Maybe b
27eitherToMaybe (Right x) = Just x
28eitherToMaybe _ = Nothing
30-- | takes a list of keys/properties and a CSS string and
31-- returns the corresponding key-value-pairs.
32pickStylesToKVs :: [String] -> String -> [(String, String)]
33pickStylesToKVs props styleAttr =
34 case parse styleAttrParser "" styleAttr of
36 Right styles -> filter (\s -> fst s `elem` props) styles
38-- | takes a list of key/property synonyms and a CSS string and maybe
39-- returns the value of the first match (in order of the supplied list)
40pickStyleAttrProps :: [String] -> String -> Maybe String
41pickStyleAttrProps lookupProps styleAttr = do
42 styles <- eitherToMaybe $ parse styleAttrParser "" styleAttr
43 foldOrElse Nothing $ map (flip lookup styles) lookupProps
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list