diff options
author | John MacFarlane <jgm@berkeley.edu> | 2012-09-29 18:12:46 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2012-09-29 18:12:46 -0700 |
commit | 779e02126d61ff67dda3ae1ad8b77f2fe5782689 (patch) | |
tree | 1e58c894aeea8b1c205711c6feaf65db3ea7eb7a /src/Text | |
parent | d3b52e42eb88b1cff6ce2f4fca05f86b5651f83d (diff) | |
download | pandoc-779e02126d61ff67dda3ae1ad8b77f2fe5782689.tar.gz |
RST reader: Folded figureBlock into directive.
Diffstat (limited to 'src/Text')
-rw-r--r-- | src/Text/Pandoc/Readers/RST.hs | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/src/Text/Pandoc/Readers/RST.hs b/src/Text/Pandoc/Readers/RST.hs index 95bd6d9c7..e8708e50b 100644 --- a/src/Text/Pandoc/Readers/RST.hs +++ b/src/Text/Pandoc/Readers/RST.hs @@ -134,7 +134,6 @@ block = choice [ codeBlock , rawBlock , blockQuote , fieldList - , figureBlock , directive , comment , header @@ -336,19 +335,6 @@ codeBlock = try $ codeBlockStart >> codeBlockBody codeBlockBody :: Parser [Char] st Blocks codeBlockBody = try $ B.codeBlock . stripTrailingNewlines <$> indentedBlock -figureBlock :: RSTParser Blocks -figureBlock = try $ do - string ".. figure::" - src <- escapeURI . trim <$> manyTill anyChar newline - body <- indentedBlock - caption <- parseFromString extractCaption body - return $ B.para $ B.image src "" caption - -extractCaption :: RSTParser Inlines -extractCaption = try $ do - manyTill anyLine blanklines - trimInlines . mconcat <$> many inline - lhsCodeBlock :: RSTParser Blocks lhsCodeBlock = try $ do getPosition >>= guard . (==1) . sourceColumn @@ -544,6 +530,10 @@ directive' = do "code-block" -> codeblock (lookup "number-lines" fields) (trim top) body "math" -> return $ B.para $ mconcat $ map B.displayMath $ toChunks $ top ++ "\n\n" ++ body + "figure" -> do + (caption, legend) <- parseFromString extractCaption body' + let src = escapeURI $ trim top + return $ B.para (B.image src "" caption) <> legend "image" -> do let src = escapeURI $ trim top let alt = B.str $ maybe "image" trim $ lookup "alt" fields @@ -554,6 +544,12 @@ directive' = do Nothing -> B.image src "" alt _ -> return mempty +extractCaption :: RSTParser (Inlines, Blocks) +extractCaption = do + capt <- trimInlines . mconcat <$> many inline + legend <- optional blanklines >> (mconcat <$> many block) + return (capt,legend) + -- divide string by blanklines toChunks :: String -> [String] toChunks = dropWhile null |