Skip to content

Commit

Permalink
tweaked linkPattern regex to pass new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
flurmbo committed Jan 26, 2019
1 parent a7c88d7 commit ef66e5f
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function extractDocumentLink(
}

export default class LinkProvider implements vscode.DocumentLinkProvider {
private readonly linkPattern = /(\[((!\[(.+)\]\()(.+)\)\]|[^\]]*\])\(\s*)((([^\s\(\)]|\(\S*?\))+))\s*(".*?")?\)/g;
private readonly linkPattern = /(\[((!\[[^\]]*\]\(\s*)([^\s\(\)]+)\s*\)\]|[^\]]*\])\(\s*)(([^\s\(\)]|\(\S*?\))+)\s*(".*?")?\)/g;
private readonly referenceLinkPattern = /(\[([^\]]+)\]\[\s*?)([^\s\]]*?)\]/g;
private readonly definitionPattern = /^([\t ]*\[([^\]]+)\]:\s*)(\S+)/gm;

Expand All @@ -92,11 +92,11 @@ export default class LinkProvider implements vscode.DocumentLinkProvider {
): vscode.DocumentLink[] {
const results: vscode.DocumentLink[] = [];
for (const match of matchAll(this.linkPattern, text)) {
const matchImage = match[5] && extractDocumentLink(document, base, match[3].length + 1, match[5], match.index);
const matchImage = match[4] && extractDocumentLink(document, base, match[3].length + 1, match[4], match.index);
if (matchImage) {
results.push(matchImage);
}
const matchLink = extractDocumentLink(document, base, match[1].length, match[6], match.index);
const matchLink = extractDocumentLink(document, base, match[1].length, match[5], match.index);
if (matchLink) {
results.push(matchLink);
}
Expand Down

0 comments on commit ef66e5f

Please sign in to comment.