Ruby-Graphviz icon indicating copy to clipboard operation
Ruby-Graphviz copied to clipboard

Dot2ruby parsing html nodes chops off angle brackets

Open awidegreen opened this issue 11 years ago • 1 comments

When dot2ruby is parsing dot-files with nodes using html labels, the leading '<' and tailoring '>' in the labels are chopped off.

See dot from graphviz doc:

digraph structs {
    node [shape=plaintext]
    struct1 [label=<
      <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
      <TR><TD>left</TD><TD PORT="f1">middle</TD><TD PORT="f2">right</TD></TR>
      </TABLE>>];
    struct2 [label=<
      <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
        <TR><TD PORT="f0">one</TD><TD>two</TD></TR>
      </TABLE>>];
    struct1:f1 -> struct2:f0;
}

output:

# This code was generated by dot2ruby.g

require 'rubygems'
require 'graphviz'
graph_structs = GraphViz.digraph( "structs" ) { |graph_structs|
  node_struct1 = graph_structs.add_nodes( "struct1", :label => '
      <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
      <TR><TD>left</TD><TD PORT="f1">middle</TD><TD PORT="f2">right</TD></TR>
      </TABLE>', :shape => 'plaintext' )
  graph_structs.add_edges( "struct1", "struct2", :headport => 'f0', :tailport => 'f1' )
  node_struct2 = graph_structs.add_nodes( "struct2", :label => '
      <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
        <TR><TD PORT="f0">one</TD><TD>two</TD></TR>
      </TABLE>', :shape => 'plaintext' )
}

generating e.g. a png doesn't work unless I add < before and > after the table tag.

<<TABLE> ... </TABLE>>

tested with latest gem: v1.0.9

awidegreen avatar Sep 09 '13 20:09 awidegreen

Similarly, I'm sure it shares the same underlaying infrastructure, parsing a dot that contains HTML labels removes the extra < and >, causing the resulting chart to show the html instead of rendering it.

I'm on 1.2.4

GraphViz.parse_string(dot_str).output(none: String)

Quick and dirty work around

Adding an extra < did the trick for me. It still removes one, but now the two that are left work as expected.

GraphViz.parse_string(dot.gsub('<<', '<<<').gsub('>>', '>>>')).output(none: String)

leonelgalan avatar Oct 24 '19 19:10 leonelgalan