1{-# LANGUAGE NoImplicitPrelude #-}
3Module : Text.Pandoc.CSS
4Copyright : © 2006-2019 John MacFarlane <jgm@berkeley.edu>,
6 2015 Ophir Lifshitz <hangfromthefloor@gmail.com>
7License : GNU GPL, version 2 or above
9Maintainer : John MacFarlane <jgm@berkeley@edu>
13Tools for working with CSS.
15module Text.Pandoc.CSS ( foldOrElse
22import Text.Pandoc.Shared (trim)
24import Text.Parsec.String
26ruleParser :: Parser (String, String)
28 p <- many1 (noneOf ":") <* char ':'
29 v <- many1 (noneOf ":;") <* optional (char ';') <* spaces
30 return (trim p, trim v)
32styleAttrParser :: Parser [(String, String)]
33styleAttrParser = many1 ruleParser
35orElse :: Eq a => a -> a -> a -> a
36orElse v x y = if v == x then y else x
38foldOrElse :: Eq a => a -> [a] -> a
39foldOrElse v xs = foldr (orElse v) v xs
41eitherToMaybe :: Either a b -> Maybe b
42eitherToMaybe (Right x) = Just x
43eitherToMaybe _ = Nothing
45-- | takes a list of keys/properties and a CSS string and
46-- returns the corresponding key-value-pairs.
47pickStylesToKVs :: [String] -> String -> [(String, String)]
48pickStylesToKVs props styleAttr =
49 case parse styleAttrParser "" styleAttr of
51 Right styles -> filter (\s -> fst s `elem` props) styles
53-- | takes a list of key/property synonyms and a CSS string and maybe
54-- returns the value of the first match (in order of the supplied list)
55pickStyleAttrProps :: [String] -> String -> Maybe String
56pickStyleAttrProps lookupProps styleAttr = do
57 styles <- eitherToMaybe $ parse styleAttrParser "" styleAttr
58 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