@@ -1,5 +1,6 @@
1−module Text.Pandoc.CSS ( foldOrElse,
2− pickStyleAttrProps
1+module Text.Pandoc.CSS ( foldOrElse
2+ , pickStyleAttrProps
3+ , pickStylesToKVs
34 )
45where
56
@@ -26,6 +27,16 @@ eitherToMaybe :: Either a b -> Maybe b
2627eitherToMaybe (Right x) = Just x
2728eitherToMaybe _ = Nothing
2829
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
35+ Left _ -> []
36+ Right styles -> filter (\s -> fst s `elem` props) styles
37+
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)
2940pickStyleAttrProps :: [String] -> String -> Maybe String
3041pickStyleAttrProps lookupProps styleAttr = do
3142 styles <- eitherToMaybe $ parse styleAttrParser "" styleAttr