-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Figure numbering is broken in HTML output with pandoc 3.x when using Markdown image syntax #1467
Comments
Using a code cell to include the image works ```{r md-logo, fig.cap = "Markdown logo", echo = FALSE}
knitr::include_graphics("https://upload.wikimedia.org/wikipedia/commons/thumb/4/48/Markdown-mark.svg/208px-Markdown-mark.svg.png")
```
The html produced at the end is <div class="figure"><span style="display:block;" id="fig:md-logo"></span>
<img role="img" aria-label="Markdown logo" src="data:image/png;base64<...encoded...>" alt="Markdown logo" />
<p class="caption">
Figure 1.1: Markdown logo
</p>
</div> When using the Markdown syntax as in example, Pandoc will produce this HTML <div class="float">
<img role="img" aria-label=" Markdown logo" src="data:image/png;base64<...encoded...>" alt=" Markdown logo" />
<div class="figcaption"> Markdown logo</div>
</div> bookdown is counting based on Line 694 in 5dcce03
and it does try to match Lines 718 to 724 in 5dcce03
This is due to change in how images are rendered in Pandoc I believe This new API for figure was introduced in Pandoc 3 Pandoc 2.19.2For the image syntax, we still get a > pandoc::pandoc_convert(text = "![(\\#fig:md-logo) Markdown logo](https://upload.wikimedia.org/wikipedia/commons/thumb/4/48/Markdown-mark.svg/208px-Markdown-mark.svg.png)", to = "native", version = "2.19.2")
[ Para
[ Image
( "" , [] , [] )
[ Str "(#fig:md-logo)"
, Space
, Str "Markdown"
, Space
, Str "logo"
]
( "https://upload.wikimedia.org/wikipedia/commons/thumb/4/48/Markdown-mark.svg/208px-Markdown-mark.svg.png"
, "fig:"
)
]
] Converted to html using > pandoc::pandoc_convert(text = "![(\\#fig:md-logo) Markdown logo](https://upload.wikimedia.org/wikipedia/commons/thumb/4/48/Markdown-mark.svg/208px-Markdown-mark.svg.png)", to = "html4", version = "2.19.2")
<div class="figure">
<img
src="https://upload.wikimedia.org/wikipedia/commons/thumb/4/48/Markdown-mark.svg/208px-Markdown-mark.svg.png"
alt="" />
<p class="caption">(#fig:md-logo) Markdown logo</p>
</div> Pandoc 3.0This now is a Figure node > pandoc::pandoc_convert(text = "![(\\#fig:md-logo) Markdown logo](https://upload.wikimedia.org/wikipedia/commons/thumb/4/48/Markdown-mark.svg/208px-Markdown-mark.svg.png)", to = "native", version = "3.0")
[ Figure
( "" , [] , [] )
(Caption
Nothing
[ Plain
[ Str "(#fig:md-logo)"
, Space
, Str "Markdown"
, Space
, Str "logo"
]
])
[ Plain
[ Image
( "" , [] , [] )
[ Str "(#fig:md-logo)"
, Space
, Str "Markdown"
, Space
, Str "logo"
]
( "https://upload.wikimedia.org/wikipedia/commons/thumb/4/48/Markdown-mark.svg/208px-Markdown-mark.svg.png"
, ""
)
]
]
] which leads to a different HTML > pandoc::pandoc_convert(text = "![(\\#fig:md-logo) Markdown logo](https://upload.wikimedia.org/wikipedia/commons/thumb/4/48/Markdown-mark.svg/208px-Markdown-mark.svg.png)", to = "html4", version = "3.0")
<div class="float">
<img
src="https://upload.wikimedia.org/wikipedia/commons/thumb/4/48/Markdown-mark.svg/208px-Markdown-mark.svg.png"
alt="(#fig:md-logo) Markdown logo" />
<div class="figcaption">(#fig:md-logo) Markdown logo</div>
</div> @yihui we need to adapt bookdown for this specific change when Markdown figure are used with labels @N0rbert using |
I feel it's not a matter of simply changing two regular expressions, but will require us to write a Lua filter to transform the figure, which may not be trivial. Since a workaround exists, I tend to suggest using the workaround (i.e., |
Thanks for your look into it.
I'll see what I can come up with. Maybe there is way to not produce this
This is surely the best workaround in this case ! |
Below is the minimal reproducible example (
index.Rmd
file):While knitting this document using RStudio 2024.04.0 Build 735 with integrated latest pandoc 3.1.11 to HTML I get the wrong rendering
Here my figure is not numbered. So the cross-reference works as expected, but "Figure 1.1: " is not shown.
It is fresh installation of Ubuntu MATE 24.04 LTS.
Other details:
Running
remotes::install_github("rstudio/bookdown")
does not help.Also please note that RStudio 2023.03.2-454 with pandoc 2.19.2 produces correct rendering.
The text was updated successfully, but these errors were encountered: