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
Fix link regex to not match multiple links per-line #460
base: master
Are you sure you want to change the base?
Conversation
Currently, the inline link regex is too inclusive. For instance, this means that if you have two links on a line, and try to go to the second link (with eg. <localleader>gl), it'll instead take you to the first.
autoload/pandoc/hypertext.vim
Outdated
@@ -35,7 +35,7 @@ function! pandoc#hypertext#Init() abort | |||
if exists('g:pandoc#hypertext#inline_link_regex') | |||
let s:inline_link_regex = g:pandoc#hypertext#inline_link_regex | |||
else | |||
let s:inline_link_regex = '\v!?\[[^]]+\]\(([^) \t]+).*\)' | |||
let s:inline_link_regex = '\v!?\[[^]]+\]\(([^) \t]+)\)' |
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.
Any idea what the reason was this was coded the way it was? Is there a link syntax that includes keywords or other information inside the parenthesis after the URL? This seems like a very deliberate nested construction not an oversight. Perhaps it needs to be[^)]*
instead of .*
but I'm hesitant to just ditch this without knowing what it was trying to fix in the first place.
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.
looks like it was probably there to support titles, which are a double-quoted string after the url (separated by whitespace). the current regex stops scanning the url at any whitespace, which breaks if you have spaces in your url (pandoc itself has no issue with spaces from my quick tests).
have changed the regex again to try to properly parse the url separately from the title (if one exists); i've tested this with multiple links, both with urls containing spaces and double quotes, on the same line and it seems to work (as well as simpler cases). i think the only thing that would break this is escaped double quotes inside the title.
referenced-links also seem to lack space support; perhaps they could have a similar fix.
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.
also seems to be an issue with opening links to alternate-based files with quotes in their names, eg. [my link](my\"file\".html)
which isn't an issue if the file is markdown, but it at least isn't an issue with the url-parsing.
Currently, the inline link regex is too inclusive. For instance, this means that if you have two links on a line, and try to go to the second link (with eg.
<localleader>gl
), it'll instead take you to the first.Fixes #283