# How to modify a HTML label via gvpr?

**URL:** <https://forum.graphviz.org/t/how-to-modify-a-html-label-via-gvpr/2509>\
**Category:** Help\
**Created:** [October 24, 2024, 5:39am UTC](https://forum.graphviz.org/t/how-to-modify-a-html-label-via-gvpr/2509 "2024-10-24T05:39:21Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![halloleo](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/halloleo/32/1066_2.png) [@halloleo](https://forum.graphviz.org/u/halloleo)\
**Post date:** [October 24, 2024, 5:39am UTC](https://forum.graphviz.org/t/how-to-modify-a-html-label-via-gvpr/2509/1 "2024-10-24T05:39:22Z")

</div>

I am getting into gvpr scripts! 🙃

I have labels like the following in my dot file:

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

```

and I want to convert them with `gvpr` to

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

```

So I tried:

```auto
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

```auto
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

---

<div class="post-metadata">

**Author:** ![steveroush](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@steveroush](https://forum.graphviz.org/u/steveroush)\
**Post date:** [October 24, 2024, 3:15pm UTC](https://forum.graphviz.org/t/how-to-modify-a-html-label-via-gvpr/2509/2 "2024-10-24T15:15:11Z")

</div>

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

```auto
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]+"}");
  }
}

```

---

<div class="post-metadata">

**Author:** ![halloleo](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/halloleo/32/1066_2.png) [@halloleo](https://forum.graphviz.org/u/halloleo)\
**Post date:** [October 24, 2024, 11:22pm UTC](https://forum.graphviz.org/t/how-to-modify-a-html-label-via-gvpr/2509/3 "2024-10-24T23:22:09Z")

</div>

Thanks Steve. Good to know about `$G`! 🙂

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:

```auto
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?

---

<div class="post-metadata">

**Author:** ![steveroush](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@steveroush](https://forum.graphviz.org/u/steveroush)\
**Post date:** [October 25, 2024, 1:10am UTC](https://forum.graphviz.org/t/how-to-modify-a-html-label-via-gvpr/2509/4 "2024-10-25T01:10:36Z")

</div>

Please show the input (.gv) file

---

<div class="post-metadata">

**Author:** ![halloleo](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/halloleo/32/1066_2.png) [@halloleo](https://forum.graphviz.org/u/halloleo)\
**Post date:** [October 25, 2024, 3:17am UTC](https://forum.graphviz.org/t/how-to-modify-a-html-label-via-gvpr/2509/5 "2024-10-25T03:17:58Z")

</div>

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

[ad-changed.dot](https://forum.graphviz.org/uploads/short-url/1iK33mrzYtuLixggMNZBHkhjkNs.dot) (978 Bytes)  
[adjust.txt](https://forum.graphviz.org/uploads/short-url/1J2KVPKNJ41RrvEBKYo30Hl15fY.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!

---

<div class="post-metadata">

**Author:** ![steveroush](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@steveroush](https://forum.graphviz.org/u/steveroush)\
**Post date:** [October 25, 2024, 4:00am UTC](https://forum.graphviz.org/t/how-to-modify-a-html-label-via-gvpr/2509/6 "2024-10-25T04:00:47Z")

</div>

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](https://www.graphviz.org/faq/font/)), 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:

 ![o](https://global.discourse-cdn.com/graphviz/original/2X/c/c78991ff2fa47bfd3a82d589f9adccafe5c1ae50.png)

---

<div class="post-metadata">

**Author:** ![halloleo](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/halloleo/32/1066_2.png) [@halloleo](https://forum.graphviz.org/u/halloleo)\
**Post date:** [October 25, 2024, 4:21am UTC](https://forum.graphviz.org/t/how-to-modify-a-html-label-via-gvpr/2509/7 "2024-10-25T04:21:37Z")

</div>

Interesting that it works for you!

> [@steveroush](#):
>
> What Graphviz version? (dot -V)

dot - graphviz version 2.30.1 (20200304.1809)

> [@steveroush](#):
>
> Please check if the _Pango_ error message was coming from **gvpr** or **dot**

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

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

```

---

<div class="post-metadata">

**Author:** ![steveroush](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@steveroush](https://forum.graphviz.org/u/steveroush)\
**Post date:** [October 25, 2024, 4:41am UTC](https://forum.graphviz.org/t/how-to-modify-a-html-label-via-gvpr/2509/8 "2024-10-25T04:41:05Z")

</div>

Time for a newer version of Graphviz

---

<div class="post-metadata">

**Author:** ![halloleo](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/halloleo/32/1066_2.png) [@halloleo](https://forum.graphviz.org/u/halloleo)\
**Post date:** [October 26, 2024, 1:41am UTC](https://forum.graphviz.org/t/how-to-modify-a-html-label-via-gvpr/2509/9 "2024-10-26T01:41:37Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![halloleo](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/halloleo/32/1066_2.png) [@halloleo](https://forum.graphviz.org/u/halloleo)\
**Post date:** [October 28, 2024, 2:28am UTC](https://forum.graphviz.org/t/how-to-modify-a-html-label-via-gvpr/2509/10 "2024-10-28T02:28:38Z")

</div>

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!
