@@ -1,5 +1,6 @@
1−module Text.Pandoc.CSS ( foldOrElse,
1+module Text.Pandoc.CSS ( foldOrElse
2− pickStyleAttrProps
2+ , pickStyleAttrProps
@@ -26,6 +27,16 @@ eitherToMaybe :: Either a b -> Maybe b
26eitherToMaybe (Right x) = Just x
27eitherToMaybe (Right x) = Just x
27eitherToMaybe _ = Nothing
28eitherToMaybe _ = Nothing
30+-- | takes a list of keys/properties and a CSS string and
31+-- returns the corresponding key-value-pairs.
32+pickStylesToKVs :: [String] -> String -> [(String, String)]
33+pickStylesToKVs 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)
29pickStyleAttrProps :: [String] -> String -> Maybe String
40pickStyleAttrProps :: [String] -> String -> Maybe String
30pickStyleAttrProps lookupProps styleAttr = do
41pickStyleAttrProps lookupProps styleAttr = do
31 styles <- eitherToMaybe $ parse styleAttrParser "" styleAttr
42 styles <- eitherToMaybe $ parse styleAttrParser "" styleAttr