How to modify a HTML label via gvpr?

I am getting into gvpr scripts! :upside_down_face:

I have labels like the following in my dot file:

mynode  [shape=myitem, label=< toki pona | sina pilin seme? >]

and I want to convert them with gvpr to

mynode [shape=record, label=< { <i>toki pona</i> | sina pilin seme? } >]

So I tried:

BEG_G {
  string parts[int];
}

N[shape=="myitem"]{
  $.shape="record";
  if (index($.label, "|") > 0) {
    split($.label, parts, "|");
    $.label = "{<i>" + parts[1] + "</i>|" + parts[2]+"}";
  }
}

However I get the error “bad label format {| sina pilin seme? }”. I guess this is due to the HTML-like nature of the source label. Do I need to use the html() function? (If so what do I use for graph g?)

Even when I take the italics directive <i>...</i> out, I get only

mynode [label="{| sina pilin seme? }", shape=record];

which shows parts[1] does not seem to polulte the first part “toki pona” of the source string.

How can I fix these two issues?
want to

Yes you need the magic html function. Also remember that split starts indexing at 0, not 1.

BEG_G {
  string parts[int];
}
N[shape=="myitem"]{
  $.shape="record";
  if (index($.label, "|") > 0) {
    split($.label, parts, "|");
    // added call to **html** and reduced indexes by 1
    $.label = html($G,"{<i>" + parts[0] + "</i>|" + parts[1]+"}");
  }
}

Thanks Steve. Good to know about $G! :slight_smile:

However, when I try the html() function exactly as suggested, I get gibberish back as the label text in the gvpr output:

mynode    [label="`ÕÉ", shape=record];

(plus some warnings on the command line like “Pango-WARNING **: Invalid UTF-8 string passed to pango_layout_set_text()”)

Even if i don’t use the parts array at all and set the label to a fixed string:

N[shape=="myitem"]{
 if (index($.label, "|") > 0) {
    $.shape="record";
    $.label = html($G, "Hallo");
  }
}

I get

mynode    [label="¨15", shape=record];

Any idea what to do?

Please show the input (.gv) file

I attach the dot file and the gvpr script (renamed to
from adjust.gvpr to adjust.txt):

ad-changed.dot (978 Bytes)
adjust.txt (209 Bytes)

To get a graph image I call it like:

cat ad-changed.dot | gvpr -v -cf adjust.gvpr | dot -Tpng -oad-changed.png

Thanks for looking at this!

It works fine for me (see below).

  1. What Graphviz version? (dot -V)
  2. It makes me want to say font problem (see Font FAQ | Graphviz), but can’t see why gvpr would be dealing with fonts. Please check if the Pango error message was coming from gvpr or dot

My result:

Interesting that it works for you!

dot - graphviz version 2.30.1 (20200304.1809)

It comes from dot, not from gvpr, but the funny characters are in the intermediate dot file gvpr produces:

mynode    [label="¨15", shape=record];

Time for a newer version of Graphviz

True.

Just checked it with a current version on my Macbook and it works correctly like for you.

Now I just have to figure out a way to get a more current version on this older linux machine which is air-gapped / off-net…

Just to follow up:

I was able to compile and install version 10.0.1. (Version 12 did not co,pile because c++ under RHEL 7 is to old.)

And now I don’t get the Unicode issue anymore. Everything runs beautifully.

Thanks for your help, @steveroush!