aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2025-04-04 10:16:23 -0700
committerJohn MacFarlane <[email protected]>2025-04-04 10:16:23 -0700
commit2155b5f9bc5a08fa1044f8a7ba75ce40af630fb7 (patch)
tree2fc63d4e8bea4d9e7769d8713e19e8150ddf7ab9
parent84946bf819a373527f03b5f4091ca0bbe695aaa0 (diff)
Markdown writer: render a figure with Para caption as implicit figure.
Also, when falling back to a Div with class `figure` for a figure that can't be represented any other way, include a Div with class `caption` containing the caption. Closes #10755.
-rw-r--r--src/Text/Pandoc/Writers/Markdown.hs9
-rw-r--r--test/command/10755.md71
2 files changed, 78 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs
index 60cd4b370..c2e7e7f5e 100644
--- a/src/Text/Pandoc/Writers/Markdown.hs
+++ b/src/Text/Pandoc/Writers/Markdown.hs
@@ -717,6 +717,8 @@ blockToMarkdown' opts (Figure figattr capt body) = do
else Just alt
Caption Nothing [Plain captInlines]
| captInlines == alt || null alt -> Just captInlines
+ Caption Nothing [Para captInlines]
+ | captInlines == alt || null alt -> Just captInlines
_ -> Nothing
case body of
[Plain [Image imgAttr alt (src, ttl)]]
@@ -763,8 +765,11 @@ figureToMarkdown opts attr@(ident, classes, kvs) capt body
writeHtml5String
opts{ writerTemplate = Nothing }
(Pandoc nullMeta [Figure attr capt body])
- | otherwise = let attr' = (ident, ["figure"] `union` classes, kvs)
- in blockToMarkdown' opts (Div attr' body)
+ | otherwise = do
+ let attr' = (ident, ["figure"] `union` classes, kvs)
+ let Caption _mbshort caption = capt
+ let captionBs = [Div ("",["caption"],[]) caption | not (null caption)]
+ blockToMarkdown' opts (Div attr' (body <> captionBs))
itemEndsWithTightList :: [Block] -> Bool
itemEndsWithTightList bs =
diff --git a/test/command/10755.md b/test/command/10755.md
new file mode 100644
index 000000000..5a603cdfc
--- /dev/null
+++ b/test/command/10755.md
@@ -0,0 +1,71 @@
+```
+% pandoc -f native -t markdown
+[ Figure
+ ( "" , [] , [] )
+ (Caption
+ Nothing [ Para [ Str "An" , Space , Str "image." ] ])
+ [ Plain
+ [ Image
+ ( ""
+ , []
+ , []
+ )
+ [ Str "An" , Space , Str "image." ]
+ ( "media/rId20.jpg" , "" )
+ ]
+ ]
+]
+^D
+![An image.](media/rId20.jpg)
+```
+
+```
+% pandoc -f native -t markdown -t markdown-implicit_figures
+[ Figure
+ ( "" , [] , [] )
+ (Caption
+ Nothing [ Para [ Str "An" , Space , Str "image." ] ])
+ [ Plain
+ [ Image
+ ( ""
+ , []
+ , []
+ )
+ [ Str "An" , Space , Str "image." ]
+ ( "media/rId20.jpg" , "" )
+ ]
+ ]
+]
+^D
+<figure>
+<img src="media/rId20.jpg" alt="An image." />
+<figcaption aria-hidden="true"><p>An image.</p></figcaption>
+</figure>
+```
+
+```
+% pandoc -f native -t markdown -t markdown-implicit_figures-raw_html
+[ Figure
+ ( "" , [] , [] )
+ (Caption
+ Nothing [ Para [ Str "An" , Space , Str "image." ] ])
+ [ Plain
+ [ Image
+ ( ""
+ , []
+ , []
+ )
+ [ Str "An" , Space , Str "image." ]
+ ( "media/rId20.jpg" , "" )
+ ]
+ ]
+]
+^D
+:::: figure
+![An image.](media/rId20.jpg)
+
+::: caption
+An image.
+:::
+::::
+```