How to preserve space character in SVG

0 votes
asked Dec 6, 2018 in Question / help by anonymous

I am creating a component diagram.  In which, I would like the spaces given in between words to be preserved.

e.g.

@startuml
["Hello                World"]
@enduml

The generated PNG preserves the spaces accordingly.

image

https://www.plantuml.com/plantuml/img/SoWkIImgAStDuOfMyaZDoSbNG0FX-KKvAKgnN0wfUIb0PG00

But the generated SVG is not preserving the spaces.  Its like this

https://www.plantuml.com/plantuml/svg/SoWkIImgAStDuOfMyaZDoSbNG0FX-KKvAKgnN0wfUIb0PG00

How can I preserve the spaces in SVG as well?

commented Dec 10, 2018 by Vivek
I also figured out that the <text> tag of svg has an attribute called "xml:space" which can be set to "preserve" in order to preserve the spacing.

<svg>
<text xml:space="preserve">Hello           world</text>
</svg>

or even the top level stylesheet like the below can also preserve the spacing:

<svg>
<style>
text {
  white-space: pre;
}
</style>
<text>Hello           world</text>
</svg>


So now the question is, how can we specify these attributes or the CSS property in PUML file so that the generated SVG can contain these modifiers for the desired results.

3 Answers

0 votes
answered May 15, 2020 by carlheinmostert (200 points)
Any update to this?  I have the same requirement.
0 votes
answered May 20, 2020 by anonymous
I have the same issue.
0 votes
answered May 20, 2020 by The-Lu (64,340 points)

Hello all,

A first workaround will be to use horizontal tabulation '\t':

@startuml
["Hello\t\tWorld"]
@enduml
www.plantuml.com/plantuml/uml/SoWkIImgAStDuOfMyaZDoScFAOaf2SyloabHYkLoICrB0Ke10000

Here is the PNG result:

PlantUML diagram

Here is the SVG result:

If that can help,
Regards,
Th.

commented Jun 19, 2021 by anonymous

In Plantuml  you can also use Unicode characters...
The "non-breaking space" (<U+00A0>) works to preserve width...

for instance:   

      !$blankSpace = "<U+00A0><U+00A0><U+00A0>"

will not collapse to a single space...

...