[gfm] Prevent markdown mode from parsing formatting within vanilla links (closes #4079) #4106
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The bug that #4079 was coming across was the fact that markdown mode parses separately from gfm mode, and isn't aware of the parsing happening in gfm mode. Additionally, either an asterisk anywhere or an underscore after a non word character had to appear in the url. That leaves a few different routes for fixing that I can think of.
First, we could make markdown mode aware of autolinking, but this is pushing more of the gfm mode logic into markdown mode that should really be avoided. Additionally, putting small hacks to prevent formatting within links would be more fragile than just building in the autolinking entirely in markdown mode (and verbose, as we'd have to put it in all of the formatting logic).
Secondly, we could give gfm mode access to markdown mode's state and have gfm mode try to manage it, but that would make refactoring states within a mode more prone to breaking overlays. So, also not ideal.
Thirdly, we could simply give the gfm mode's tokens priority, which would fix the link, but everything after it would still be in a different state than it should be (italicized when it shouldn't be).
Lastly, we can force markdown to freeze state until after the link, which is ideal and the route I ended up taking. That is, the state before the link in markdown should be exactly the same as after the link. The simplest way I could think of to achieve this was to add a
freezeBaseState
flag to gfm mode that the overlay.js code would look for and skip base mode parsing when it was encountered. It would then set the base position to the overlay position so they both start parsing again from the same spot (after the link).