svg2pdf.js icon indicating copy to clipboard operation
svg2pdf.js copied to clipboard

Allow (partially) whitespace: pre

Open Fuzzyma opened this issue 4 months ago • 3 comments

Right now, the only way to achieve whitespace presevation is by using xml:space. According to mdn this is outdated.

Nowadays there is the whitespace css properly. So whitespace: pre should show all whitespaces (including newlines). This is supported by Firefox. Chrome only supports multiple whitespaces and no newlines.

I vote for implementing chromes behavior because its trivial to implement. Just add an extra condition to this line:

https://github.com/yWorks/svg2pdf.js/blob/de6f4722b45eda4b2f9359059fd23cd9e09f0f34/src/nodes/text.ts#L53

If it is possible we should look into rendering newlines as well but that would probably take a bit more effort

Fuzzyma avatar Aug 22 '25 22:08 Fuzzyma

Thank you for opening this feature request. I agree that we should implement it like Chrome does and don't support newlines for now. If Chrome does not support newlines it's unlikely that many SVGs will use this feature.

Could you prepare a PR? Here are some steps you could follow:

  • add a whiteSpace property to the AttributeState, handle it like the other properties
  • adjust the usages of the xmlSpace property to also check for the whiteSpace property
  • add test cases similar to the "xml-space" tests

Please also see our contribution guidelines.

HackbrettXXX avatar Aug 25 '25 08:08 HackbrettXXX

pr in https://github.com/yWorks/svg2pdf.js/pull/333

Fuzzyma avatar Aug 26 '25 08:08 Fuzzyma

Partial support was implemented in #333. Newlines are still not supported.

HackbrettXXX avatar Sep 16 '25 12:09 HackbrettXXX