git.iko.soy/typeable/pandoc
on master help sign in
RST reader: Folded figureBlock into directive.
commit779e02126d61ff67dda3ae1ad8b77f2fe5782689 authorJohn MacFarlane <jgm@berkeley.edu> dateSat 29 Sep 2012, 18:12 (14 years ago) parentd3b52e4
1 file changed+10−14
src/Text/Pandoc/Readers/RST.hs+10−14
src/Text/Pandoc/Readers/RST.hs+10−14
@@ -134,7 +134,6 @@ block = choice [ codeBlock
134134 , rawBlock
135135 , blockQuote
136136 , fieldList
137− , figureBlock
138137 , directive
139138 , comment
140139 , header
@@ -336,19 +335,6 @@ codeBlock = try $ codeBlockStart >> codeBlockBody
336335codeBlockBody :: Parser [Char] st Blocks
337336codeBlockBody = try $ B.codeBlock . stripTrailingNewlines <$> indentedBlock
338337
339−figureBlock :: RSTParser Blocks
340−figureBlock = try $ do
341− string ".. figure::"
342− src <- escapeURI . trim <$> manyTill anyChar newline
343− body <- indentedBlock
344− caption <- parseFromString extractCaption body
345− return $ B.para $ B.image src "" caption
346−
347−extractCaption :: RSTParser Inlines
348−extractCaption = try $ do
349− manyTill anyLine blanklines
350− trimInlines . mconcat <$> many inline
351−
352338lhsCodeBlock :: RSTParser Blocks
353339lhsCodeBlock = try $ do
354340 getPosition >>= guard . (==1) . sourceColumn
@@ -544,6 +530,10 @@ directive' = do
544530 "code-block" -> codeblock (lookup "number-lines" fields) (trim top) body
545531 "math" -> return $ B.para $ mconcat $ map B.displayMath
546532 $ toChunks $ top ++ "\n\n" ++ body
533+ "figure" -> do
534+ (caption, legend) <- parseFromString extractCaption body'
535+ let src = escapeURI $ trim top
536+ return $ B.para (B.image src "" caption) <> legend
547537 "image" -> do
548538 let src = escapeURI $ trim top
549539 let alt = B.str $ maybe "image" trim $ lookup "alt" fields
@@ -554,6 +544,12 @@ directive' = do
554544 Nothing -> B.image src "" alt
555545 _ -> return mempty
556546
547+extractCaption :: RSTParser (Inlines, Blocks)
548+extractCaption = do
549+ capt <- trimInlines . mconcat <$> many inline
550+ legend <- optional blanklines >> (mconcat <$> many block)
551+ return (capt,legend)
552+
557553-- divide string by blanklines
558554toChunks :: String -> [String]
559555toChunks = dropWhile null