Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upDetect md image link #66958
Conversation
flurmbo
added some commits
Jan 22, 2019
sbatten
assigned
mjbvz
Jan 23, 2019
mjbvz
added this to the December/January 2019 milestone
Jan 23, 2019
mjbvz
requested changes
Jan 23, 2019
Thanks for taking a look! Changes look good, just a few tweaks. Let me know if you have any questions about my comments or the code |
@@ -51,7 +51,7 @@ function matchAll( | |||
} | |||
|
|||
export default class LinkProvider implements vscode.DocumentLinkProvider { | |||
private readonly linkPattern = /(\[[^\]]*\]\(\s*)((([^\s\(\)]|\(\S*?\))+))\s*(".*?")?\)/g; | |||
private readonly linkPattern = /(\[((!\[(.+)\]\()(.+)\)\]|[^\]]*\])\(\s*)((([^\s\(\)]|\(\S*?\))+))\s*(".*?")?\)/g; |
This comment has been minimized.
This comment has been minimized.
mjbvz
Jan 23, 2019
Contributor
Regex looks good but I think it does need to be tweaked to be less greedy:
- Instead of using
.
for matching the contents between the brackets, match on what that content cannot contain, such as[^\]]
so that we match any character that is not a square bracket. - Use a non-greedy quanitfier:
+?
instead of just+
so we consume the minimum number of characters that still meet the regexp
The reason is that for markdown files like:
[](https://example.com) other text [](https://example.com)
if the matching is greedy, the detected link could end up spanning both links.
This comment has been minimized.
This comment has been minimized.
flurmbo
added some commits
Jan 24, 2019
mjbvz
merged commit 4fe1cdc
into
Microsoft:master
Jan 26, 2019
This comment has been minimized.
This comment has been minimized.
Thanks! This change will be in the next VS Code insiders build and is scheduled to be included in VS Code 1.31 |
This comment has been minimized.
This comment has been minimized.
Awesome, thanks for the fast response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
flurmbo commentedJan 23, 2019
Fixes #49238. I added an option to the regex to have an image instead of text for the link description. Then when iterating over regex matches
providerInlineLinks
will now check to see if an image resource was also matched, and if so add it to results. All the tests pass, as well as a new one I've added.Feedback on the regex would be appreciated, also I think perhaps the code I copied starting here could be refactored into a separate function.