quarto-dev / quarto-dev/quarto-cli
Caption not showing when using inline SVG in Figure AST node
@cscheid is already working on this.
Since Apr 24, 2023.
- Dominant language
- JavaScript
- Stars
- 6k
- Forks
- 458
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 41
Description
This is to track possible enhancement/fix when inline HTML such as SVG is included in a Figure Pandoc AST node (such as the one emitted by diagram.lua below).
Note that the issue was raised in the discussion below when using a version of https://github.com/pandoc-ext/diagram under active development.
A workaround has been found and is documented in the discussion.
Discussed in https://github.com/quarto-dev/quarto-cli/discussions/5266
Originally posted by netw0rkf10w April 21, 2023
Hello,
I'm using this filter for converting TikZ code to SVG in Quarto. When using the filter as is, it works (an example can be found at https://raw.githubusercontent.com/pandoc-ext/diagram/main/test/input-tikz.md). However, when I changed the code to replace the SVG file with inline SVG, the caption is not showing (I checked the output HTML and the figure container was not even generated).
More precisely, in the original code, an SVG image is created and store in img, then:
-- Use the block's filename attribute or create a new name by hashing the image content.
local basename, _extension = pandoc.path.split_extension(
props.filename or pandoc.sha1(img)
)
local fname = basename .. '.' .. extension_for_mimetype[imgtype]
-- Store the data in the media bag:
pandoc.mediabag.insert(fname, imgtype, img)
-- Create a figure that contains just this image.
local img_obj = pandoc.Image(props.alt, fname, "", props['image-attr'])
return pandoc.Figure(pandoc.Plain{img_obj}, props.caption, props['fig-attr'])
What I did is, instead of creating a file in the media bag, I used directly the SVG as an inline HTML element:
return pandoc.Figure(pandoc.RawInline('html', img), props.caption, props['fig-attr'])
(the above line replaces the entire previous code block)
Using Pandoc alone, it worked:
quarto pandoc --lua-filter filters/diagram.lua -s tikz.qmd -o tikz.html
However, when rendering tikz.qmd containing
filters:
- diagram.lua
with Quarto, the SVG is displayed but not in a figure container and thus there's no caption.
Could you please help? Thank you very much in advance!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.