mirror of
https://github.com/jgm/pandoc.git
synced 2026-08-28 17:20:47 +08:00
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.
This commit is contained in:
@@ -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 =
|
||||
|
||||
@@ -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
|
||||

|
||||
```
|
||||
|
||||
```
|
||||
% 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
|
||||

|
||||
|
||||
::: caption
|
||||
An image.
|
||||
:::
|
||||
::::
|
||||
```
|
||||
Reference in New Issue
Block a user