git.iko.soy/typeable/pandoc
on master help sign in
Markdown writer: preserve `implicit_figures` with attributes...

...even if `implicit_attributes` is not set, by rendering in raw HTML. Fixes #4677.

commit252ab9b77323230fa58e3b877101b061d77f673c authorJohn MacFarlane <jgm@berkeley.edu> dateWed 30 May 2018, 09:24 (8 years ago) parent1100bfc
2 files changed+18−5
src/Text/Pandoc/Writers/Markdown.hs+11−5 test/command/4677.md+7
src/Text/Pandoc/Writers/Markdown.hs+11−5
@@ -452,8 +452,14 @@ blockToMarkdown' opts (Plain inlines) = do
452452 | otherwise -> contents
453453 return $ contents' <> cr
454454-- title beginning with fig: indicates figure
455−blockToMarkdown' opts (Para [Image attr alt (src,'f':'i':'g':':':tit)]) =
456− blockToMarkdown opts (Para [Image attr alt (src,tit)])
455+blockToMarkdown' opts (Para [Image attr alt (src,'f':'i':'g':':':tit)])
456+ | isEnabled Ext_raw_html opts &&
457+ not (isEnabled Ext_link_attributes opts) &&
458+ attr /= nullAttr = -- use raw HTML
459+ (text . T.unpack . T.strip) <$>
460+ writeHtml5String opts{ writerTemplate = Nothing }
461+ (Pandoc nullMeta [Para [Image attr alt (src,"fig:" ++ tit)]])
462+ | otherwise = blockToMarkdown opts (Para [Image attr alt (src,tit)])
457463blockToMarkdown' opts (Para inlines) =
458464 (<> blankline) `fmap` blockToMarkdown opts (Plain inlines)
459465blockToMarkdown' opts (LineBlock lns) =
@@ -619,7 +625,7 @@ blockToMarkdown' opts t@(Table caption aligns widths headers rows) = do
619625 (all null headers) aligns' widths' headers rows
620626 | isEnabled Ext_raw_html opts -> fmap (id,) $
621627 (text . T.unpack) <$>
622− (writeHtml5String def $ Pandoc nullMeta [t])
628+ (writeHtml5String opts{ writerTemplate = Nothing } $ Pandoc nullMeta [t])
623629 | hasSimpleCells &&
624630 isEnabled Ext_pipe_tables opts -> do
625631 rawHeaders <- padRow <$> mapM (blockListToMarkdown opts) headers
@@ -1172,7 +1178,7 @@ inlineToMarkdown opts lnk@(Link attr txt (src, tit))
11721178 not (isEnabled Ext_link_attributes opts) &&
11731179 attr /= nullAttr = -- use raw HTML
11741180 (text . T.unpack . T.strip) <$>
1175− writeHtml5String def (Pandoc nullMeta [Plain [lnk]])
1181+ writeHtml5String opts{ writerTemplate = Nothing } (Pandoc nullMeta [Plain [lnk]])
11761182 | otherwise = do
11771183 plain <- asks envPlain
11781184 linktext <- inlineListToMarkdown opts txt
@@ -1212,7 +1218,7 @@ inlineToMarkdown opts img@(Image attr alternate (source, tit))
12121218 not (isEnabled Ext_link_attributes opts) &&
12131219 attr /= nullAttr = -- use raw HTML
12141220 (text . T.unpack . T.strip) <$>
1215− writeHtml5String def (Pandoc nullMeta [Plain [img]])
1221+ writeHtml5String opts{ writerTemplate = Nothing } (Pandoc nullMeta [Plain [img]])
12161222 | otherwise = do
12171223 plain <- asks envPlain
12181224 let txt = if null alternate || alternate == [Str source]
test/command/4677.mdnew file+7
@@ -0,0 +1,7 @@
1+```
2+% echo '![Caption](img.png){#img:1}' | pandoc --to "markdown-bracketed_spans-fenced_divs-link_attributes-simple_tables-multiline_tables-grid_tables-pipe_tables-fenced_code_attributes-markdown_in_html_blocks-table_captions-smart"
3+^D
4+<figure>
5+<img src="img.png" alt="Caption" id="img:1" /><figcaption>Caption</figcaption>
6+</figure>
7+```