1{-# LANGUAGE NoImplicitPrelude #-}
2module Text.Pandoc.CSS ( foldOrElse
9import Text.Pandoc.Shared (trim)
11import Text.Parsec.String
13ruleParser :: Parser (String, String)
15 p <- many1 (noneOf ":") <* char ':'
16 v <- many1 (noneOf ":;") <* optional (char ';') <* spaces
17 return (trim p, trim v)
19styleAttrParser :: Parser [(String, String)]
20styleAttrParser = many1 ruleParser
22orElse :: Eq a => a -> a -> a -> a
23orElse v x y = if v == x then y else x
25foldOrElse :: Eq a => a -> [a] -> a
26foldOrElse v xs = foldr (orElse v) v xs
28eitherToMaybe :: Either a b -> Maybe b
29eitherToMaybe (Right x) = Just x
30eitherToMaybe _ = Nothing
32-- | takes a list of keys/properties and a CSS string and
33-- returns the corresponding key-value-pairs.
34pickStylesToKVs :: [String] -> String -> [(String, String)]
35pickStylesToKVs props styleAttr =
36 case parse styleAttrParser "" styleAttr of
38 Right styles -> filter (\s -> fst s `elem` props) styles
40-- | takes a list of key/property synonyms and a CSS string and maybe
41-- returns the value of the first match (in order of the supplied list)
42pickStyleAttrProps :: [String] -> String -> Maybe String
43pickStyleAttrProps lookupProps styleAttr = do
44 styles <- eitherToMaybe $ parse styleAttrParser "" styleAttr
45 foldOrElse Nothing $ map (`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