Skip to content

Conversation

alythobani
Copy link
Contributor

Fixes: #242

This PR adjusts the existing link patterns to be more precise and accurate (e.g. take backslashes into account when interpreting brackets as part of link syntax) - and in the context of #242, we now disallow unescaped square brackets inside the [display text] part of a [display text](url) markdown link.

This fixes the issue of a checkbox's square brackets (e.g. - [ ] / - [x]) being considered as the start of a markdown link when a markdown link is part of the checkbox item (e.g. - [ ] This is a [markdown link](https://some-url.com)).

Detailed docstrings have been added to the regexes now that they're even more complex than they were before and some intentional tradeoffs were taken (particularly for MARKDOWN_LINK_REGEX).

This PR also along the way:

  • adds the vitest test framework and adds unit tests for the link regexes (jumpToLink.test.ts)
  • removes package-lock.json from .gitignore and adds it to the repo's git tracking (generally considered good practice to commit package-lock.json)

@@ -0,0 +1,19 @@
{
"cSpell.words": [
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just getting rid of a bunch of spellcheck warnings in main.ts

"scripthost",
"ES2020"
]
"lib": ["dom", "scripthost", "ES2020"]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just prettier doing some auto formatting

Comment on lines -4 to -6
const WIKILINK_REGEX_STRING = "\\[\\[.*?\\]\\]";
const MARKDOWN_LINK_REGEX_STRING = "\\[.*?\\]\\(.*?\\)";
const URL_REGEX_STRING = "\\w+://\\S+";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new regexes are now built as actual regexes from the start (instead of just strings) so that they only need half as many backslashes

Copy link
Owner

@esm7 esm7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, this is a great contribution!

@alythobani
Copy link
Contributor Author

For sure, I was meaning to get around to this fix at some point :)

Thanks to you for making the plugin in the first place! It's been great

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.

gl refuses to jump to the next link if it's in a checklist
2 participants