From 1a4b47e93368bfbd31daccdfedbd9527ee740201 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Mon, 14 Jan 2013 20:53:08 -0800 Subject: Implemented Ext_implicit_figures. * In markdown reader, add a '\1' character to the beginning of the title of an image that is alone in its paragraph, if implicit_figures extension is selected. * In writers, check for Para [Image alt (src,'\1':tit)] and treat it as a figure if possible. * Updated tests. This is a bit of a hack, but it allows us to make implicit_figures an extension of the markdown reader, rather than the writers. --- src/Text/Pandoc/Readers/Markdown.hs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'src/Text/Pandoc/Readers') diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs index 6ca699d20..1fb361585 100644 --- a/src/Text/Pandoc/Readers/Markdown.hs +++ b/src/Text/Pandoc/Readers/Markdown.hs @@ -770,13 +770,23 @@ compactify'DL items = para :: MarkdownParser (F Blocks) para = try $ do + exts <- getOption readerExtensions result <- trimInlinesF . mconcat <$> many1 inline - option (B.plain <$> result) $ try $ do - newline - (blanklines >> return mempty) - <|> (guardDisabled Ext_blank_before_blockquote >> lookAhead blockQuote) - <|> (guardDisabled Ext_blank_before_header >> lookAhead header) - return $ B.para <$> result + option (B.plain <$> result) + $ try $ do + newline + (blanklines >> return mempty) + <|> (guardDisabled Ext_blank_before_blockquote >> lookAhead blockQuote) + <|> (guardDisabled Ext_blank_before_header >> lookAhead header) + return $ do + result' <- result + case B.toList result' of + [Image alt (src,tit)] + | Ext_implicit_figures `Set.member` exts -> + -- the \1 at beginning of title indicates a figure + return $ B.para $ B.singleton + $ Image alt (src,'\1':tit) + _ -> return $ B.para result' plain :: MarkdownParser (F Blocks) plain = fmap B.plain . trimInlinesF . mconcat <$> many1 inline <* spaces -- cgit v1.2.3