git.iko.soy/typeable/pandoc
on master help sign in
Merge pull request #2568 from mb21/readers-images

Textile Reader: image attributes

commit48b7d250bb5cc7656754dbd9288ee30491933397 authorJohn MacFarlane <jgm@berkeley.edu> dateWed 2 Dec 2015, 18:18 (11 years ago) parentad6578fd901a3d
2 files changed+10−3
src/Text/Pandoc/CSS.hs+1−1 src/Text/Pandoc/Readers/Textile.hs+9−2
src/Text/Pandoc/CSS.hs+1−1
@@ -10,7 +10,7 @@ import Text.Parsec.String
1010ruleParser :: Parser (String, String)
1111ruleParser = do
1212 p <- many1 (noneOf ":") <* char ':'
13− v <- many1 (noneOf ":;") <* char ';' <* spaces
13+ v <- many1 (noneOf ":;") <* (optional $ char ';') <* spaces
1414 return (trim p, trim v)
1515
1616styleAttrParser :: Parser [(String, String)]
src/Text/Pandoc/Readers/Textile.hs+9−2
@@ -51,6 +51,7 @@ TODO : refactor common patterns across readers :
5151
5252
5353module Text.Pandoc.Readers.Textile ( readTextile) where
54+import Text.Pandoc.CSS
5455import Text.Pandoc.Definition
5556import Text.Pandoc.Builder (Inlines, Blocks, trimInlines)
5657import qualified Text.Pandoc.Builder as B
@@ -535,11 +536,17 @@ link = try $ do
535536image :: Parser [Char] ParserState Inlines
536537image = try $ do
537538 char '!' >> notFollowedBy space
538− _ <- attributes -- ignore for now, until we have image 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
544+ Just stls -> (ident, cls, getAtt "width" stls ++ getAtt "height" stls)
545+ Nothing -> (ident, cls, kvs)
539546 src <- manyTill anyChar' (lookAhead $ oneOf "!(")
540547 alt <- option "" (try $ (char '(' >> manyTill anyChar' (char ')')))
541548 char '!'
542− return $ B.image src alt (B.str alt)
549+ return $ B.imageWith attr src alt (B.str alt)
543550
544551escapedInline :: Parser [Char] ParserState Inlines
545552escapedInline = escapedEqs <|> escapedTag