xflr6 / graphviz

Simple Python interface for Graphviz
https://graphviz.readthedocs.io
MIT License
1.63k stars 211 forks source link

Allow HTML tags in the middle of strings #148

Closed codeofdusk closed 2 years ago

codeofdusk commented 2 years ago

I'd like to be able to do something like:

g = graphviz.Digraph()
g.node("a", "TP")
g.node("b", "DP")
g.node("c", "D<br/>I")
g.edge("a", "b")
g.edge("b", "c")

And have a newline appear between "D" and "I" in the label of node c.

xflr6 commented 2 years ago

AFAICT, this is supported (cf. manual.html#quoting-and-html-like-labels, also: upstream docs on HTML-like labels):

In [1]: import graphviz
   ...: 
   ...: g = graphviz.Digraph()
   ...: 
   ...: g.node('a', 'TP')
   ...: g.node('b', 'DP')
   ...: g.node('c', '<D<br/>I>')
   ...: 
   ...: g.edge('a', 'b')
   ...: g.edge('b', 'c')
   ...: 
   ...: g

spam

Another option is using manual.html#backslash-escapes:

g.node('c', r'D\nI')