git.iko.soy/typeable/pandoc
on master help sign in
new function to extract multiple properties at once in CSS.hs
2060f5fmb21
src/Text/Pandoc/CSS.hs+13−2
@@ -1,5 +1,6 @@
1−module Text.Pandoc.CSS ( foldOrElse,
1+module Text.Pandoc.CSS ( foldOrElse
2− pickStyleAttrProps
2+ , pickStyleAttrProps
3+ , pickStylesToKVs
3 )
4 )
4where
5where
5
6
@@ -26,6 +27,16 @@ eitherToMaybe :: Either a b -> Maybe b
26eitherToMaybe (Right x) = Just x
27eitherToMaybe (Right x) = Just x
27eitherToMaybe _ = Nothing
28eitherToMaybe _ = Nothing
28
29
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)
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
src/Text/Pandoc/Readers/Textile.hs+1−4
@@ -537,11 +537,8 @@ image :: Parser [Char] ParserState Inlines
537image = try $ do
537image = try $ do
538 char '!' >> notFollowedBy space
538 char '!' >> notFollowedBy space
539 (ident, cls, kvs) <- attributes
539 (ident, cls, kvs) <- attributes
540− let getAtt k styles = case pickStyleAttrProps [k] styles of
541− Just v -> [(k, v)]
542− Nothing -> []
543 let attr = case lookup "style" kvs of
540 let attr = case lookup "style" kvs of
544− Just stls -> (ident, cls, getAtt "width" stls ++ getAtt "height" stls)
541+ Just stls -> (ident, cls, pickStylesToKVs ["width", "height"] stls)
545 Nothing -> (ident, cls, kvs)
542 Nothing -> (ident, cls, kvs)
546 src <- manyTill anyChar' (lookAhead $ oneOf "!(")
543 src <- manyTill anyChar' (lookAhead $ oneOf "!(")
547 alt <- option "" (try $ (char '(' >> manyTill anyChar' (char ')')))
544 alt <- option "" (try $ (char '(' >> manyTill anyChar' (char ')')))