-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTML-like labels should be opt-in #168
Comments
There is a workaround: you can wrap your labels in |
Thanks for the detailed report. This is indeed working as documented, see https://graphviz.readthedocs.io/en/stable/manual.html#quoting-and-html-like-labels Hint: In case you are want to pass arbitrary user input (e.g. for labels), you might want to consider using Side note: use the official public API names (which are also simpler): https://graphviz.readthedocs.io/en/stable/api.html#quoting-escaping (all directly under
This interpretation of import graphviz
graphviz.Source('''
digraph {
a [label=<lambda> <map>]
}
''').render()
Error: <stdin>: syntax error in line 3 near ']' IIUC you might be implying that I completely agree that this is something for users to stumble upon and it would probably better for HTML-like labels to be opt-in. The same reasoning might apply to backslash-escapes, should they be opt-in as well? #53 is another wart that probably requires a backwards-incompatible behavioural change or maybe duplicating some arguments or function names to provide for the different use cases (treat strings literally vs. let them be interpreted). My plan/proposal is to address all these shortcomings that might involve subtle API/behavioural changes in a single version jump that might be allowed break backwards-compatibility, e.g. for the |
Thank you for all the links to documentation! I learned some things about DOT today...
I think so!
No, actually I was surprised to see a regex looking for HTML in the first place! In all the time I've used the Now that I know about the idea of id:port:compass, which is very fancy, I think it would have been nice if port and compass had been kwargs, as opposed to things parsed out of the name; or even if name was allowed to be any of:
That sounds excellent. It's good to know you were already thinking about this stuff; and I'm sorry for the inconvenience of having people like me who use the library for ages without reading through all of the documentation first. :) |
Actually, I think it might be nice to mention So the first code example one sees on that page is: dot = graphviz.Digraph('round-table', comment='The Round Table') ...and for most people, I think the takeaway is "I can pass an arbitrary string as the name, e.g. dot = graphviz.Digraph(graphviz.escape('round-table'), comment='The Round Table') |
Thanks, and +1 to your proposal to add a better visible warning about possivle quoting/escaping gotchas. See 25043ed.
Yeah, this is a very simple library (only around a thousand lines) and +1 the main thing it helps with is quoting/escaping. Because I did not manage to get that completely right on the first try and at least some users might depend on the ability to interpret e.g. backslash escapes, we need to be careful with fixing that (major version change).
+1. I have thought about that earlier: add support for tuples as a backwards-compatible first step towards fixing #53, so we can change the behaviour in a second step and require the use of tuples for port/compass later. Feel free to add that proposal to the issue thread (with the introduction of type annotations, Python provides nicer ways to document that by now as well). Let me know in case you would like to contribute on this feature. |
Ah, that's exactly what I had in mind! Thanks for that.
Okay -- I'll mention it in there, and actually yes I would be interested in seeing if I can add tuple support as a first step :) |
Thanks, fixed the typo in 4aa4d24. |
I'm seconding the call for more documentation, and for documentation in the places it is most critical. I came here to file an issue because as far as what I could tell from the API reference There's nothing there that hints at the possibility that there is a Quoting and HTML-like labels kind of functionality that reacts differently to different strings. If I was a novice reading the documentation from beginning to end, I might have known that, but an experienced programmer often just goes to the API documentation and looks for examples of how to invoke the functions. Thus I had no idea why the first of these node labels had no quotes (and was of course syntactic garbage that led the renderer to barf) while the second one did have quotes:
|
There is a warning at the end of |
I'm not saying it's not documented; once I found this thread I was able to find the documentation (hence link it above). I'm saying that someone who bookmarks the API documentation and goes there to try to understand the behavior doesn't get any hints. It could be as simple as editing the description for the argument to say something like: |
Oh okay, fair point: how about master...api_docs_escape? |
Added callouts: |
Thanks for this! |
I'm starting this based on this Prefect issue: PrefectHQ/prefect#5656
Long story short, in graphviz library's
quoting.py
, there is this regex:...which incorrectly matches strings like
'<lambda> <map>'
.To reproduce:
...this results in:
...and the generated Digraph.gv looks like:
The text was updated successfully, but these errors were encountered: