Detect md image link#66958
Merged
mjbvz merged 7 commits intomicrosoft:masterfrom Jan 26, 2019
flurmbo:detect-md-image-link
Merged
Detect md image link#66958mjbvz merged 7 commits intomicrosoft:masterfrom flurmbo:detect-md-image-link
mjbvz merged 7 commits intomicrosoft:masterfrom
flurmbo:detect-md-image-link
Conversation
mjbvz
requested changes
Jan 23, 2019
Collaborator
mjbvz
left a comment
There was a problem hiding this comment.
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
|
|
||
| export default class LinkProvider implements vscode.DocumentLinkProvider { | ||
| private readonly linkPattern = /(\[[^\]]*\]\(\s*)((([^\s\(\)]|\(\S*?\))+))\s*(".*?")?\)/g; | ||
| private readonly linkPattern = /(\[((!\[(.+)\]\()(.+)\)\]|[^\]]*\])\(\s*)((([^\s\(\)]|\(\S*?\))+))\s*(".*?")?\)/g; |
Collaborator
There was a problem hiding this comment.
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.
Collaborator
There was a problem hiding this comment.
Probably worth adding a test for that example md as well
extensions/markdown-language-features/src/features/documentLinkProvider.ts
Outdated
Show resolved
Hide resolved
Collaborator
|
Thanks! This change will be in the next VS Code insiders build and is scheduled to be included in VS Code 1.31 |
Contributor
Author
|
Awesome, thanks for the fast response |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
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
providerInlineLinkswill 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.