Myriad-Dreamin/typst.ts

nbsp; in svgs.

Closed this issue · 4 comments

When I use the tool to generate svgs - they contain   but   isn't actually legal in svg files. When I try to open them as svg file instead of embedded into an html, they produce errors.

As far as I know, there isn't a good reason to be escaping spaces. Certainly, its not correct to uniformly convert spaces into non-breaking spaces.

How does you use the tool? CLI or the JS library.
In CLI I do distinguish the context on whether a SVG would like to be inlined in HTML or as a individual SVG file.

let text_content = if aware_html_entity {
escape::escape_str::<TextContentDataEscapes>(content)
} else {
escape::escape_str::<PcDataEscapes>(content)
};

const AWARE_HTML_ENTITY: bool = false;

But in JS library I was lazy and assumed users always embed them into some HTML element. But anyway, I'll let JS library aware of that that in next release.

I am using the JS library.

Rather than putting an option in, I'd suggest using &#160; instead of &nbsp; This should work no matter how the svg is used.

Still better, I think, would be to not escape whitespace at all, but set white-space: pre in the css file.

I'd like to contribute back by sending you a PR, if you'd be amenable to one of my proposals.

I like the second one. That is very smart. We can set white-space for only the pseudo text elements by a css class selector .tsel, which should work.

close in flavor of #482 and #489