Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Markdown reader: use title of implicit figure as short caption. #8617

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Text/Pandoc/Readers/Markdown.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,9 @@ implicitFigure (ident, classes, attribs) capt url title =
_ -> capt
attribs' = filter ((/= "alt") . fst) attribs
figattr = (ident, mempty, mempty)
caption = B.simpleCaption $ B.plain capt
caption = if T.null title
then B.simpleCaption $ B.plain capt
else B.caption (Just . B.toList $ B.text title) $ B.plain capt
figbody = B.plain $ B.imageWith ("", classes, attribs') url title alt
in B.figureWith figattr caption figbody

Expand Down
11 changes: 6 additions & 5 deletions src/Text/Pandoc/Writers/Markdown.hs
Original file line number Diff line number Diff line change
Expand Up @@ -672,21 +672,22 @@ blockToMarkdown' opts (Figure figattr capt body) = do
let combinedAttr imgattr = case imgattr of
("", cls, kv) | (figid, [], []) <- figattr -> Just (figid, cls, kv)
_ -> Nothing
let combinedAlt alt = case capt of
let combinedAlt alt title = case capt of
Caption Nothing [] -> if null alt
then Just [Str "image"]
else Just alt
Caption Nothing [Plain captInlines]
| captInlines == alt -> Just captInlines
Caption short [Plain captInlines]
| captInlines == alt
, title == maybe "" stringify short -> Just captInlines
_ -> Nothing
case body of
[Plain [Image imgAttr alt (src, ttl)]]
| isEnabled Ext_implicit_figures opts
, Just descr <- combinedAlt alt
, Just descr <- combinedAlt alt ttl
, Just imgAttr' <- combinedAttr imgAttr
, isEnabled Ext_link_attributes opts || imgAttr' == nullAttr
-> do
-- use implicit figures if possible
-- Lossless representation as implicit figure is possible
let tgt' = (src, fromMaybe ttl $ T.stripPrefix "fig:" ttl)
contents <- inlineListToMarkdown opts [Image imgAttr' descr tgt']
return $ contents <> blankline
Expand Down
12 changes: 11 additions & 1 deletion test/testsuite.native
Original file line number Diff line number Diff line change
Expand Up @@ -1908,7 +1908,17 @@ Pandoc
]
, Figure
( "" , [] , [] )
(Caption Nothing [ Plain [ Str "lalune" ] ])
(Caption
(Just
[ Str "Voyage"
, Space
, Str "dans"
, Space
, Str "la"
, Space
, Str "Lune"
])
[ Plain [ Str "lalune" ] ])
[ Plain
[ Image
( "" , [] , [] )
Expand Down
2 changes: 1 addition & 1 deletion test/writer.context
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ or here: <http://example.com/>

From \quotation{Voyage dans la Lune} by Georges Melies (1902):

\startplacefigure[title={lalune}]
\startplacefigure[title={lalune},list={Voyage dans la Lune}]
{\externalfigure[lalune.jpg]}
\stopplacefigure

Expand Down
2 changes: 1 addition & 1 deletion test/writer.latex
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ From ``Voyage dans la Lune'' by Georges Melies (1902):
\begin{figure}
\centering
\includegraphics{lalune.jpg}
\caption{lalune}
\caption[Voyage dans la Lune]{lalune}
\end{figure}

Here is a movie \includegraphics{movie.jpg} icon.
Expand Down
12 changes: 11 additions & 1 deletion test/writer.native
Original file line number Diff line number Diff line change
Expand Up @@ -1843,7 +1843,17 @@ Pandoc
]
, Figure
( "" , [] , [] )
(Caption Nothing [ Plain [ Str "lalune" ] ])
(Caption
(Just
[ Str "Voyage"
, Space
, Str "dans"
, Space
, Str "la"
, Space
, Str "Lune"
])
[ Plain [ Str "lalune" ] ])
[ Plain
[ Image
( "" , [] , [] )
Expand Down