mgieseki / dvisvgm

A fast DVI, EPS, and PDF to SVG converter
https://dvisvgm.de
GNU General Public License v3.0
312 stars 34 forks source link

Feature request: optionally use html id to scope svg's css #234

Open stertooy opened 1 year ago

stertooy commented 1 year ago

Currently, dvisvgm outputs svg files containing css like this:

<svg [...]>
<style type='text/css'>
<![CDATA[
[...font faces...]
text.f0 { [...] }
text.f1 { [...] }
[...more fonts...]
]]>
</style>
[...]
</svg>

I would like to use multiple svg's created by dvisvgm inline on a given html page. However, this causes these svg's to overwrite each other's css. One solution would be to generate a unique id for the svg, and then using that id in the css to scope it:

<svg [...] id='myAwesomeIdHere' >
<style type='text/css'>
<![CDATA[
[...font faces...]
#myAwesomeIdHere text.f0 { [...] }
#myAwesomeIdHere text.f1 { [...] }
[...more fonts...]
]]>
</style>
[...]
</svg>

Would it be possible to implement an option for dvisvgm to do this automatically?

mgieseki commented 1 year ago

I have to look into this more closely but don't have time to work on dvisvgm in the next few weeks. As a workaround you could use option --no-styles maybe in combination with --optimize.