From 8632526fc20c59df635d9cad77e1453155f8680d Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Thu, 14 Mar 2019 21:43:25 -0700 Subject: Markdown writer: be sure implicit figures work in list contexts. Previously they would sometimes not work: e.g., when they occured in final paragraphs in lists that were originally parsed as Plain and converted later using PlainToPara. Closes #5368. --- src/Text/Pandoc/Readers/Markdown.hs | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'src/Text/Pandoc/Readers') diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs index 2ae07c6a1..442c34511 100644 --- a/src/Text/Pandoc/Readers/Markdown.hs +++ b/src/Text/Pandoc/Readers/Markdown.hs @@ -1039,7 +1039,18 @@ normalDefinitionList = do para :: PandocMonad m => MarkdownParser m (F Blocks) para = try $ do exts <- getOption readerExtensions - result <- trimInlinesF <$> inlines1 + let implicitFigures x + | extensionEnabled Ext_implicit_figures exts = do + x' <- x + case B.toList x' of + [Image attr alt (src,tit)] + | not (null alt) -> + -- the fig: at beginning of title indicates a figure + return $ B.singleton + $ Image attr alt (src,'f':'i':'g':':':tit) + _ -> return x' + | otherwise = x + result <- implicitFigures . trimInlinesF <$> inlines1 option (B.plain <$> result) $ try $ do newline @@ -1062,16 +1073,7 @@ para = try $ do if divLevel > 0 then lookAhead divFenceEnd else mzero - return $ do - result' <- result - case B.toList result' of - [Image attr alt (src,tit)] - | not (null alt) && - Ext_implicit_figures `extensionEnabled` exts -> - -- the fig: at beginning of title indicates a figure - return $ B.para $ B.singleton - $ Image attr alt (src,'f':'i':'g':':':tit) - _ -> return $ B.para result' + return $ B.para <$> result plain :: PandocMonad m => MarkdownParser m (F Blocks) plain = fmap B.plain . trimInlinesF <$> inlines1 -- cgit v1.2.3