git.iko.soy/typeable/pandoc
on master help sign in
new function to extract multiple properties at once in CSS.hs

and use it in Textile reader

commit2060f5fe83db613f878c712378a68cb88f452669 authormb21 <mb21@users.noreply.github.com> dateSat 5 Dec 2015, 14:12 (11 years ago) parent30644b2
2 files changed+14−6
src/Text/Pandoc/CSS.hs+13−2 src/Text/Pandoc/Readers/Textile.hs+1−4
src/Text/Pandoc/CSS.hs+13−2
@@ -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
src/Text/Pandoc/Readers/Textile.hs+1−4
@@ -537,11 +537,8 @@ image :: Parser [Char] ParserState Inlines
537537image = try $ do
538538 char '!' >> notFollowedBy space
539539 (ident, cls, kvs) <- attributes
540− let getAtt k styles = case pickStyleAttrProps [k] styles of
541− Just v -> [(k, v)]
542− Nothing -> []
543540 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)
545542 Nothing -> (ident, cls, kvs)
546543 src <- manyTill anyChar' (lookAhead $ oneOf "!(")
547544 alt <- option "" (try $ (char '(' >> manyTill anyChar' (char ')')))