From 779e02126d61ff67dda3ae1ad8b77f2fe5782689 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sat, 29 Sep 2012 18:12:46 -0700 Subject: RST reader: Folded figureBlock into directive. --- src/Text/Pandoc/Readers/RST.hs | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'src/Text/Pandoc/Readers/RST.hs') 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 -- cgit v1.2.3