2Module : Text.Pandoc.CSS
3Copyright : © 2006-2021 John MacFarlane <jgm@berkeley.edu>,
5 2015 Ophir Lifshitz <hangfromthefloor@gmail.com>
6License : GNU GPL, version 2 or above
8Maintainer : John MacFarlane <jgm@berkeley@edu>
12Tools for working with CSS.
21import Data.Maybe (mapMaybe, listToMaybe)
22import Data.Text (Text, pack)
23import Text.Pandoc.Shared (trim)
25import Text.Parsec.Text
27ruleParser :: Parser (Text, Text)
29 p <- many1 (noneOf ":") <* char ':'
30 v <- many1 (noneOf ":;") <* optional (char ';') <* spaces
31 return (trim $ pack p, trim $ pack v)
33styleAttrParser :: Parser [(Text, Text)]
34styleAttrParser = many1 ruleParser
36-- | Parses a style string, returning the CSS attributes.
37-- Returns an empty list on failure.
38cssAttributes :: Text -> [(Text, Text)]
39cssAttributes styleString =
40 -- Use Data.Either.fromRight once GHC 8.0 is no longer supported
41 case parse styleAttrParser "" styleString of
45-- | takes a list of keys/properties and a CSS string and
46-- returns the corresponding key-value-pairs.
47pickStylesToKVs :: [Text] -> Text -> [(Text, Text)]
48pickStylesToKVs props styleAttr =
49 filter (\s -> fst s `elem` props) $ cssAttributes styleAttr
51-- | takes a list of key/property synonyms and a CSS string and maybe
52-- returns the value of the first match (in order of the supplied list)
53pickStyleAttrProps :: [Text] -> Text -> Maybe Text
54pickStyleAttrProps lookupProps styleAttr = do
55 styles <- either (const Nothing) Just $ parse styleAttrParser "" styleAttr
56 listToMaybe $ mapMaybe (`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