Skip to content

Commit 0d2114e

Browse files
committed
Markdown writer: improve use of implicit figures when possible.
Closes #10758. When the alt differs from the caption, but only as regards formatting, we still use an implicit figure.
1 parent 0cf4169 commit 0d2114e

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

src/Text/Pandoc/Writers/Markdown.hs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -709,16 +709,20 @@ blockToMarkdown' opts (DefinitionList items) = do
709709
return $ mconcat contents <> blankline
710710
blockToMarkdown' opts (Figure figattr capt body) = do
711711
let combinedAttr imgattr = case imgattr of
712-
("", cls, kv) | (figid, [], []) <- figattr -> Just (figid, cls, kv)
712+
("", cls, kv)
713+
| (figid, [], []) <- figattr -> Just (figid, cls, kv)
714+
| otherwise -> Just ("", cls, kv)
713715
_ -> Nothing
714716
let combinedAlt alt = case capt of
715717
Caption Nothing [] -> if null alt
716718
then Just [Str "image"]
717719
else Just alt
718720
Caption Nothing [Plain captInlines]
719-
| captInlines == alt || null alt -> Just captInlines
721+
| null alt || stringify captInlines == stringify alt
722+
-> Just captInlines
720723
Caption Nothing [Para captInlines]
721-
| captInlines == alt || null alt -> Just captInlines
724+
| null alt || stringify captInlines == stringify alt
725+
-> Just captInlines
722726
_ -> Nothing
723727
case body of
724728
[Plain [Image imgAttr alt (src, ttl)]]

test/command/10758.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
```
2+
% pandoc -f native -t markdown
3+
[ Figure
4+
( "" , [] , [] )
5+
(Caption
6+
Nothing
7+
[ Para [ Str "Foo" , Space , Emph [ Str "emphasis" ] ] ])
8+
[ Plain
9+
[ Image
10+
( ""
11+
, []
12+
, []
13+
)
14+
[ Str "Foo" , Space , Str "emphasis" ]
15+
( "media/rId20.jpg" , "" )
16+
]
17+
]
18+
]
19+
^D
20+
![Foo *emphasis*](media/rId20.jpg)
21+
```

0 commit comments

Comments
 (0)