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 by carlheinmostert (200 points)
Any update to this?  I have the same requirement.
0 votes
answered May 20 by anonymous
I have the same issue.
0 votes
answered May 20 by The-Lu (2,600 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.

...