mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 12:19:20 +00:00
@@ -104,8 +104,7 @@ export function stripAngleBrackets(link: string) {
|
||||
}
|
||||
|
||||
const linkPattern = /(\[((!\[[^\]]*?\]\(\s*)([^\s\(\)]+?)\s*\)\]|(?:\\\]|[^\]])*\])\(\s*)(([^\s\(\)]|\([^\s\(\)]*?\))+)\s*(".*?")?\)/g;
|
||||
// eslint-disable-next-line code-no-look-behind-regex
|
||||
const referenceLinkPattern = /((?<=^|[^\]])\[((?:\\\]|[^\]])+)\])(?!:)(?:[^\[]|$|\[\s*?([^\s\]]*?)\])/g;
|
||||
const referenceLinkPattern = /(?:(\[((?:\\\]|[^\]])+)\]\[\s*?)([^\s\]]*?)\]|\[\s*?([^\s\]]*?)\])(?!\:)/g;
|
||||
const definitionPattern = /^([\t ]*\[(?!\^)((?:\\\]|[^\]])+)\]:\s*)([^<]\S*|<[^>]+>)/gm;
|
||||
const inlineCodePattern = /(?:^|[^`])(`+)(?:.+?|.*?(?:(?:\r?\n).+?)*?)(?:\r?\n)?\1(?:$|[^`])/gm;
|
||||
|
||||
@@ -187,14 +186,14 @@ export default class LinkProvider implements vscode.DocumentLinkProvider {
|
||||
let reference = match[3];
|
||||
if (reference) { // [text][ref]
|
||||
const pre = match[1];
|
||||
const offset = (match.index || 0) + pre.length + 1;
|
||||
const offset = (match.index || 0) + pre.length;
|
||||
linkStart = document.positionAt(offset);
|
||||
linkEnd = document.positionAt(offset + reference.length);
|
||||
} else if (match[2]) { // [ref][], [ref]
|
||||
reference = match[2];
|
||||
} else if (match[4]) { // [ref][], [ref]
|
||||
reference = match[4];
|
||||
const offset = (match.index || 0) + 1;
|
||||
linkStart = document.positionAt(offset);
|
||||
linkEnd = document.positionAt(offset + match[2].length);
|
||||
linkEnd = document.positionAt(offset + reference.length);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -159,16 +159,16 @@ suite('markdown.DocumentLinkProvider', () => {
|
||||
assert.strictEqual(links.length, 1);
|
||||
});
|
||||
|
||||
test('Should find links for referenes with only one [] (#141285)', async () => {
|
||||
test('Should find links for referees with only one [] (#141285)', async () => {
|
||||
let links = await getLinksForFile([
|
||||
'[Works]',
|
||||
'[Works]: https://microsoft.com',
|
||||
'[ref]',
|
||||
'[ref]: https://microsoft.com',
|
||||
].join('\n'));
|
||||
assert.strictEqual(links.length, 2);
|
||||
|
||||
links = await getLinksForFile([
|
||||
'[Does Not Work]',
|
||||
'[Works]: https://microsoft.com',
|
||||
'[def]: https://microsoft.com',
|
||||
].join('\n'));
|
||||
assert.strictEqual(links.length, 1);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user