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

in HTML format, embedded SVG gets modified #9206

Closed
cderv opened this issue Nov 21, 2023 · 4 comments
Closed

in HTML format, embedded SVG gets modified #9206

cderv opened this issue Nov 21, 2023 · 4 comments
Labels

Comments

@cderv
Copy link
Contributor

cderv commented Nov 21, 2023

Here are two svg plot produced (with a SVG graphic device in R)

plot1

plot2

Let's use those .svg files in a .md document to convert to HTML with embed-resources

> pandoc -t html -f markdown -s -o test.html --embed-resources
---
title: Test
---

# Plot 1

![](https://user-images.githubusercontent.com/6791940/284527411-15509b05-33ca-4341-ac98-82311741df88.svg)

# Plot 2

![](https://user-images.githubusercontent.com/6791940/284527415-a93c5319-073f-4ab9-bb76-79c2931bc515.svg)

This is the html produced:

image

See how the second plot has

  • Wrong Y axis numbers
  • Wrong X axis label
Without `--embed-resources` we get correct plots

image

So it seems something in the embedding process modifies the SVG...

With Pandoc 3.1.5, the old way to embed SVG was used (src data uri for img) and the issue does not happen. It happens since Pandoc 3.1.6, since #8948

Also, if only the second SVG is file provided, then it is not modified.

Details
> pandoc -t html -f markdown -s -o test.html --embed-resources
---
title: Test
---

# Plot 2

![](https://user-images.githubusercontent.com/6791940/284527415-a93c5319-073f-4ab9-bb76-79c2931bc515.svg)

image

Pandoc version?

Pandoc 3.1.9 on Windows

This comes from

@jgm
Copy link
Owner

jgm commented Nov 25, 2023

Currently we're using tagsoup to parse, adjust, and rerender the SVG. That seems to create problems, e.g. tagsoup will generate a bare attribute d instead of d="", leading to an invalid SVG. It would be better to switch to using an XML parser/renderer for this part of the code. [EDIT:] But this might be hard since this part of the code is operating on a tagsoup Tag stream.

@jgm
Copy link
Owner

jgm commented Nov 25, 2023

This is extremely weird.
Pandoc isn't modifying anything significant in these SVGs.
But if you produce the HTML file, then manually delete the first svg (plot 1), then the second one renders fine. Somehow the two SVGs are interfering with each other.

@jgm
Copy link
Owner

jgm commented Nov 25, 2023

I think the problem is that the two SVGs contain elements with duplicate IDs, e.g.

<symbol overflow="visible" id="glyph0-0">

Manually making the ids unique fixes the problem.
We will need to do something to ensure unique ids.

@jgm jgm closed this as completed in fc3d202 Nov 25, 2023
@cderv
Copy link
Contributor Author

cderv commented Nov 29, 2023

Thanks a lot for investigating this @jgm !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants