md extension should underline images used as link description

This commit is contained in:
Phil Marshall 2019-01-21 23:25:05 -06:00
parent 2d79ffe0cd
commit d372fa0697

View file

@ -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;
private readonly referenceLinkPattern = /(\[([^\]]+)\]\[\s*?)([^\s\]]*?)\]/g;
private readonly definitionPattern = /^([\t ]*\[([^\]]+)\]:\s*)(\S+)/gm;
@ -74,7 +74,7 @@ export default class LinkProvider implements vscode.DocumentLinkProvider {
const results: vscode.DocumentLink[] = [];
for (const match of matchAll(this.linkPattern, text)) {
const pre = match[1];
const link = match[2];
const link = match[6];
const offset = (match.index || 0) + pre.length;
const linkStart = document.positionAt(offset);
const linkEnd = document.positionAt(offset + link.length);
@ -85,6 +85,20 @@ export default class LinkProvider implements vscode.DocumentLinkProvider {
} catch (e) {
// noop
}
if (match[5]) {
const imagePre = match[3];
const imageLink = match[5];
const imageOffset = (match.index || 0) + imagePre.length + 1;
const imageLinkStart = document.positionAt(imageOffset);
const imageLinkEnd = document.positionAt(imageOffset + imageLink.length);
try {
results.push(new vscode.DocumentLink(
new vscode.Range(imageLinkStart, imageLinkEnd),
normalizeLink(document, imageLink, base)));
} catch (e) {
// noop
}
}
}
return results;