-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
Bug/5123 allow attribute names to be escaped on er diagram #5138
base: develop
Are you sure you want to change the base?
Bug/5123 allow attribute names to be escaped on er diagram #5138
Conversation
✅ Deploy Preview for mermaid-js ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #5138 +/- ##
============================================
+ Coverage 43.04% 79.35% +36.31%
============================================
Files 23 167 +144
Lines 5018 13873 +8855
Branches 21 707 +686
============================================
+ Hits 2160 11009 +8849
+ Misses 2857 2711 -146
- Partials 1 153 +152
Flags with carried forward coverage won't be shown. Click here to find out more. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Some minor changes and this will be ok
@@ -26,6 +26,7 @@ accDescr\s*"{"\s* { this.begin("acc_descr_multili | |||
<block>\b((?:PK)|(?:FK)|(?:UK))\b return 'ATTRIBUTE_KEY' | |||
<block>(.*?)[~](.*?)*[~] return 'ATTRIBUTE_WORD'; | |||
<block>[\*A-Za-z_][A-Za-z0-9\-_\[\]\(\)]* return 'ATTRIBUTE_WORD' | |||
<block>\`[^`\n]*\` return 'BACKTICK_STRING'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to add backtick within attribute name as well? I am asking because we are trying to allow basically any characters within attribute name with this PR. Minor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding one more backtick in the name causes a parse error, and adding a second one breaks it into two attributes. For example:
String `geo.`acc`uracy`
I'm not sure if there is a way around this behavior, other than maybe changing the escape characters from backticks to something else. Let me know if you have suggestions here 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They should be escaped then. Common practice is to use escapement character, like \
(\\
and \`
respectively for \
and `
) or duplicating characters, like "hello""quotes"
(csv uses that approach), or using another character as wrapper (like double backtick for markdown)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure which approach to pick up, they all have some flaws but it's better to think about such a feature beforehand because it is a real pain to introduce something like this later without braking backwards compatibility
…ped-on-ER-diagram
…ram' of github.com:ejscribner/mermaid into bug/5123_allow-attribute-names-to-be-escaped-on-ER-diagram
Thanks for the review @nirname, fixed the easy ones. Let me know if you have any ideas or thoughts on the backticks in attribute name one. |
Please, do not forget to add some documentation describing this, otherwise people wont be aware of that feature. |
Sorry for the long response. @ejscribner please add some documentation describing this feature @sidharthv96 @aloisklink what do you think on escapement syntax for backtics? |
There are 2 main options Escape using
|
source | outcome |
---|---|
backticked string with `` in it |
backticked string with ` in it |
backticked string with \ in it |
backticked string with \ in it |
backticked string with in it` |
error |
Escape using \
backslash
source | outcome |
---|---|
backticked string with \ in it` |
backticked string with ` in it |
backticked string with \\ in it |
backticked string with \ in it |
backticked string with in it` |
error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code is OK. We need some documentation covering this feature to continue
I would love to see this land. We use https://github.com/k1LoW/tbls/ to generate database documentation including Mermaid ER diagrams. However, I currently have to disable generating Mermaid ERDs for a specific database view that uses some special characters in the column names ( Is there any way I can help pull this over the line? |
@mjpieters Yes, you definitely can. This is half-ready. Whether @ejscribner is going to continue on this or not, you can always take what has already been done, open new PR to the issue #5123 and we can continue over there. Anyway you can help with a piece of advise so we could come up with convenient format for escaping, and I could complete the feature myself. It's up to you, any help appreciated. |
I'll assign myself to this PR so it would be easier to find this among other issues. Doesn't necessarily mean we continue this very branch. |
Also very interested in seeing this feature land. Oracle table column names frequently have a dollar-sign in them and would love to be able to render data types like |
There is another option: accept character references, so Normally, I'd say you should pick an option that is consistent with the syntax used by other mermaid diagrams. Unfortunately, there is no consistency here:
GIven that mermaid is specifically designed to be embedded inside Markdown documents, I'd go with the backslash to escape backticks (and backslashes, because you need to support escaping a backslash too). |
📑 Summary
Enables special characters within backticked strings for the attributeName in an ER Diagram.
Resolves #5123
📏 Design Decisions
To allow more flexibility in an
attributeName
, I've used backticks to escape all special characters that a user might need to put there.This approach:
📋 Tasks
Make sure you
MERMAID_RELEASE_VERSION
is used for all new features.develop
branch