How do I set a label to HTML using the C API

I'm writing a graphviz viewer integrated into a Qt application. How do I set the label to be HTML? I've tried things like: agset(n, "label", "<b>some bold text"</b>");

agset(n, "label", "<html><b>some bold text</b></html>");

agset(n, "label", "<some bold text>");

agset(n, "html", "<b>some bold text<b>"); 

Nothing seems to work. Do I have to use aghtmlstr(), if so how?


[Sorry, I can't get the < and > working correctly]

To make HTML-like labels work

To make HTML-like labels work transparently with ordinary labels, we had to use a bit of magic. In the library, this is handled by the function agstrdup_html():

char* l = agstrdup_html("<B>some bold text</B>");

agset (n,"label",l);

agstrfree (l);

The function aghtmlstr() returns TRUE if the argument string was created using agstrdup_html.

should be in manual

It would be great to have that information in the manual (Using Graphviz as  Library).  I scoured the December 2013 edition looking for an answer to this question and found only one mention of agstrdup_html, and it didn't seem to cover this.

The example above would be wonderful in the manual.

BTW, when I do it, agstrdup_html() wants an additional graph argument.


Well, it is at least a

Well, it is at least a pointer. And the information really belongs in the cgraph manual. But your point is valid, and I've fixed the library manual to better document this.

You're also correct about the missing argument to agstrdup_html. In the old graph library, there was one global string table. In cgraph, each graph has its own table, so the strdup calls need a graph pointer. My fingers obviously just slipped into the old pattern.

Recent comments