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
Provide HTML5 writer option to embed SVG instead of converting it. #8948
Comments
This should be doable. All we would need is an XML parser & renderer, which we depend on already. |
I don't think we should have an additional option. I think this should just be default behavior for HTML5. We could keep the other behavior for HTML4. |
OK, thanks. Another potential issue I see: duplicate Then you would just have to ensure that the As for it being default or not, it is your choice. I tend to be conservative, sometimes people expect "bug-to-bug compatibility". Maybe someone relies on the SVGs being converted to PNGs and included in data-URIs... |
The only reason I can think of for wanting to do this would be if inline SVG support isn't universal for HTML5 renderers. Is that an issue? In general, I have to balance between satisfying everyone's expectations and adding additional complexity (more options). |
As for the ids, I think I'd just generate ids based on the sha1 hash of the contents. Keep track of generated ids that have been used, and if we get a duplicate, use the href form to refer back to the already included one. |
Not for me. |
One thing seems wrong in your request. I wonder if you're using a really old version of pandoc? We don't convert to png; we just include a data URI that encodes the SVG itself. So: there is no loss in resolution, and only a modest increase in data size. (e.g. a 9K SVG expands to around 15K in the data URI; though if there are many references to the same SVG, you'll get duplicates, and that still might motivate this change). |
My immediate question is how to handle other attributes on the |
You can put all these attributes into the new |
To be more precise: if an image has attributes ( An inline ![image](foo.svg){#myid .myclass width=300 height=200px} In this case, the user-specified attributes should override the attributes imported or generated from the svg file.
|
I had some issues with SVG a few years ago, on a Linux (Suse 12, if I recall correctly) where it complained that librsvg was missing, and I could not install it for whatever reason. As librsvg converts svg to png, I assumed that it was the missing part. |
- Ensure unique ids for elements by prefixing SVG id. - Ensure SVG `id` attribute except when `use` element is used. - Remove `width`, `height` attributes from svg element when `use` element is used. Instead, add `width` and `height` 100% to the `use` element. This seems to get the sizing right. Closes #9206. Ref: #8948.
Describe your proposed improvement and the problem it solves.
I convert from Markdown to HTML5 with options
--embed-resources --standalone
.When the document contains SVG images, they are converted by
librsvg
, and then embedded with a data URI.Problems: this causes a loss of resolution and a big increase in the output size. Moreover, librsvg may not be available on all systems.
Because the HTML 5 syntax accepts inline SVG, Pandoc could simply include these files with an additional option like
--inline-svg
.A few changes in the included SVG are necessary. But I think that it does not need a full-featured SVG parser.
For example, a typical SVG file contains:
The
<?xml>
and<!DOCTYPE>
must be dropped.In the
<svg>
tag, you can safely remove remove bothxmlns
attributes andversion
too.The resulting HTML code would contain:
Some SVG files do not include width and height attributes. The default values from the HTML stylesheet (300px and 150px) may not be appropriate, therefore I propose the following additional logic:
<svg>
contains only theviewBox
attribute, compute and add thewidth
andheight
from these values.For example
viewBox="1 2 300 400"
would mean additional attributes:width="299" height="398"
(Unitpx
is not necessary).viewBox
is missing butwidth
andheight
are present, similarly create aviewBox
.Fox example,
width="100px" height="200px"
would create aviewBox="0 0 100 200"
Other improvements are possible, but they require more logic:
id
attribute for it. Then the next reference would be only a<svg width=...><use href="#the-previously-included-svg-id"/></svg>
<view>
, with the:target
or with<symbol>
):Idea would be to create in the HTML a
<section style="display: none;">
and include those external<svg>
inside it.Then reference them with
<svg width=...><use href="...
as previously. Width, height and viewBox computed from the target element attributes if possible, else from its parent SVG element.Describe alternatives you've considered.
Maybe an additional SVG library could do the job, but it would add an external dependency, like with
librsvg
.Unless there is a library you can embed with the cabal build system ?
The text was updated successfully, but these errors were encountered: