mirror of
https://github.com/xoofx/markdig.git
synced 2026-02-03 21:36:36 +00:00
Pipe characters detected as part of URL #419
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @hamvocke on GitHub (Dec 1, 2020).
Over at Stack Exchange we're seeing an issue with Markdig's link detection within pipe tables (example post here for the curious). I think it breaks down to Markdig's
LinkHelperdetecting pipes as part of a URL.Let's assume I've got the following snippet (from a pipe table structure)
Ideally, there'd be a space after the
example.comURL - but sometimes users don't enter one. If Markdig'sUseAutoLinksis enabled, Markdig will turn that URL above into a link like<a href="https://example.com|anothercell">. I'd expect the|anothercellbit to be excluded from the URL in that hyperlink.If I read RFC 3986 correctly (apologies for pulling out the big guns, I always find RFCs rather unhandy - maybe this answer on Stack Overflow is more approachable), a literal
|character is not a valid character in a URI (unless percent-encoded of course).I think this unit test might reproduce the issue at hand:
Should Markdig's
LinkHelper.TryParseUrl()be tweaked to exclude|characters from URLs?@xoofx commented on GitHub (Dec 1, 2020):
Pipe in table has been a trouble design for Markdig since the beginning
So for example, on GitHub, this:
Renders to this:
For which Markdig seems to follow the same rule. But if you look at how other parsers are doing on this case, there is not a clear winner...
Markdig is not fully compatible with GitHub, but overall it tries to be more compatible with it.
@hamvocke commented on GitHub (Dec 1, 2020):
Your example seems to render as I'd expect on GitHub if I include the proper amount of table headers/separators:
@xoofx commented on GitHub (Dec 1, 2020):
Right, and this is were we are departing with GitHub... GitHub before using CommonMark, didn't have clear rules about it (it was an implementation detail). Markdig started to implement some "rules" before GitHub started, and had to make some choices.
GitHub did something differently (which I think is slightly explained in the thread I posted above).
Fixing Markdig is probably a good goal here, because GitHub is likely the "de-facto reference" (because used a lot).
Though I don't have personally any sparetime interest solving this issue, so a PR would be welcome.
Note that the code in Markdig for handling pipe tables is awful, I'm really not proud of it. So if someone is enough brave to challenge it, I would not mind. 😅