Skip to content
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

Labels aren't escaped and/or quoted when necessary #21

Open
smheidrich opened this issue Sep 8, 2024 · 0 comments
Open

Labels aren't escaped and/or quoted when necessary #21

smheidrich opened this issue Sep 8, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@smheidrich
Copy link

smheidrich commented Sep 8, 2024

Description

Problem description

Consider e.g. a label with a newline in it:

from py_d2 import D2Diagram, D2Shape

shape = D2Shape(name="SomeShape", label="Some\nlabel")
diagram = D2Diagram(shapes=[shape])
print(str(diagram))

py-d2 renders this as

SomeShape: Some
label

which D2, in turn, renders as a node with label Some:

But surely, what the user wanted here was to have the newline escaped

SomeShape: Some\nlabel

so that D2 renders it as a node with a multi-line label:

The same issue applies to other characters interpreted specially by D2, specifically \, {, }, " and ' (there might be others, not sure).

Would fixing this constitute a breaking change?

One problem I foresee is that other users of this library might have started to work around this by quoting/escaping the labels they give to py-d2 themselves, so once this gets fixed, their \ characters are escaped to \\, " are escaped to \" etc., breaking their code.

I don't know if there is a good way around this. One option would be to leave label as it is and introduce a new parameter smart_label or whatever, but that makes things needlessly complicated for new users.

So maybe it should just get fixed in the normal, potentially-breaking manner but be held back until a new major version release?

Related issues / PRs

@smheidrich smheidrich added the bug Something isn't working label Sep 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant