Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

charlie-wt
Copy link

@charlie-wt charlie-wt commented Dec 29, 2023

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

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.
@@ -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]+)\)'
Copy link
Member

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.

Copy link
Author

@charlie-wt charlie-wt Jan 5, 2024

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.

Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Always opens first link in line
2 participants