jamisonjiang / graph-support

Java re-implementation of tiny graphviz
Apache License 2.0
24 stars 7 forks source link

HTML entities are emitted in SVG which is invalid #1

Closed atextor closed 11 months ago

atextor commented 11 months ago

When the text of an element contains a character for which an HTML entity exists, this entity appears in the SVG output, even though this is not valid. HTML entities are not defined there; renderers/browsers will complain that they are not. For example, if the text contains "ü", the SVG output contains "\ü". Instead,

To reproduce:

The following code:

public class Test {
   public static void main( final String[] args ) throws ExecuteException {
      final Graphviz graphviz = Graphviz.digraph()
            .addNode( Node.builder().label( "ü" ).build() )
            .build();
      System.out.println( graphviz.toSvgStr() );
   }
}

creates:

<?xml version="1.0" encoding="UTF-8"?>
  <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
 height="116.0pt" width="94.0pt" viewBox="0.00 0.00 94.0 116.0"><g id="graph_root"
class="graph" transform="scale(1.0 1.0) rotate(0)"><g id="graph_0" class="graph">
<polygon id="graph_root_polygon" fill="#ffffff" points="0.0,0.0 94.0,0.0 94.0,116.0 0.0,
116.0 0.0,0.0"></polygon></g><g id="node_0" class="node"><ellipse id="node_0_ellipse" 
cx="47.0" cy="58.0" rx="27.0" ry="18.0" fill="none" stroke="#000000"></ellipse>
<text id="node_0_text_0" x="47.875" y="62.666666666666664" text-anchor="middle" 
font-size="14.0" fill="#000000">&uuml;</text></g></g></svg>
jamisonjiang commented 11 months ago

@atextor Thanks for your feedback, it will be fixed in the next release.

jamisonjiang commented 11 months ago

Done in 1.1.5