-
Notifications
You must be signed in to change notification settings - Fork 49
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
Link tokens [] are escaped #311
Comments
Hey there! The latter two links do not have a valid link destination, so a CommonMark compliant parser will not parse them as links. Here's the spec for link destination https://spec.commonmark.org/0.30/#link-destination |
I hear that "it's not valid CommonMark compliant', but mdformat is changing the meaning of the tokens by adding backslashes that are not needed. Now, I appreciate that mdformat is trying to make non compliant code more compliant, but I'ld prefer that it does this in a way that is functionnally compatible with what I can already observe. Strangely enough, gitlab still accepts On
Why spaces in the link? That would mean spaces are replaced with dashes (-) or '%20' sequences. As web browsers convert spaces to '%20' and dashes are still dashes in the end, it's preferable to convert spaces to %20 (Example with-space . It can be argued that It can also that adding a backslash before '[' as for '*' has some usability for cases where this is the user's intention. An algorithm could use the heuristic that the opening and closing parentheses and bracket ( Under the CommonMark reference which is referenced to justify to not change Another possibility is to let the user choose through some option(s) to choose either one or the other behavior. I tested the following markdown in both environments, including after applying mdformat. I show the result before applying mdformat, after applying it the rendering seems to be the same. - [[abc]](link)
- [my link](my link)
- [(abc)](link)
- [(abc)](link "Link Title")
- [link with link title](/uri "My Link Title")
- [[abc](https://github.githubassets.com/favicons/favicon-dark.png)](NotALinkBecauseNotAnImage "Link Title")
- [](link "Link Title()")
- [](link "Link Title\(\)")
- [](link (Link Title))
- [](link (Invalid Link (Title)) There is a difference only for link targets with spaces: On gitlab: On github:
So I still plead to cope with this case differently. |
It's not changing any meaning. The invalid links are still invalid links, and the escape character is not significant in any way in CommonMark AST.
I agree that this is very weird. It's an issue with GitLab's parser/renderer however, not mdformat.
The change you suggest is altering Markdown AST (converting text to link). Mdformat will never do such changes.
This is a separate issue #112 |
Yes and no. That issue seems to be mainly arguing that there is overuse of backslashes. I am arguing that this may change meaning according to the environement, and (high) that what is done for other characters could be done for spaces as well. I was mentioning Gitlab's behavior to highlight what they do and that's it's rather intuitive. Innovation is often "wrong" until the specification or norm changes.
Then the interpretation of Anyway, I am closing this as it is clear I am not going to change opinions here. |
I see. Mdformat doesn't target any environments, however. It is CommonMark compliant, and if the environment is not, then that is the environment's issue. |
I may be stretching the Robustness principle a bit, but I'ld say that not adding '' to [ still maintains the "compliancy" of input documents when they are and supposing that spaces in link targets are part of the link is inline with "accept non-conformant input as long as the meaning is clear" in documents that weren't officially compliant in the first place. |
While checking if tickboxes are part of the CommonMark specification, I stumbled on this discussion on the CommonMark forum: https://talk.commonmark.org/t/support-for-gfm-like-checkboxes/2007/9 . So it seems that CommonMark is frozen to cover features from John Gruber's Markdown only which leaves little room for adding features to mdformat's "core" to keep up with what is happening in the field - unless the extensions or plugins scope with variations on common mark. So let's say this particularity of the link feature should be part of some plugin like mdformat-gitlab . |
👍 It is definitely possible to achieve what you want with a plugin. There's info on how to make a plugin in the docs. Also the plugin template may prove useful https://github.com/executablebooks/mdformat-plugin/ |
Describe the bug
is converted to
Rendering the links useless.
There are links that are properly resolved in gitlab.
expectation
The link is maintained.
problem
This is a problem because this breaks the expected behaviour after applying mdformat.
Reproduce the bug
Apply mdformat on
List your environment
I suggest you update the hint to get the version (jupyter-hook does not exist).
pre-commit configuration:
The text was updated successfully, but these errors were encountered: