Support definition links with spaces

For #136073
This commit is contained in:
Matt Bierner
2021-11-01 09:22:48 -07:00
parent f145c79a93
commit a9bc0553f7
3 changed files with 37 additions and 17 deletions

View File

@@ -139,11 +139,22 @@ suite('markdown.DocumentLinkProvider', () => {
}
});
// #107471
test('Should not consider link references starting with ^ character valid', () => {
test('Should not consider link references starting with ^ character valid (#107471)', () => {
const links = getLinksForFile('[^reference]: https://example.com');
assert.strictEqual(links.length, 0);
});
test('Should find definitions links with spaces in angle brackets (#136073)', () => {
const links = getLinksForFile([
'[a]: <b c>',
'[b]: <cd>',
].join('\n'));
assert.strictEqual(links.length, 2);
const [link1, link2] = links;
assertRangeEqual(link1.range, new vscode.Range(0, 6, 0, 9));
assertRangeEqual(link2.range, new vscode.Range(1, 6, 1, 8));
});
});

View File

@@ -16,7 +16,6 @@ export class InMemoryDocument implements vscode.TextDocument {
this._lines = this._contents.split(/\r\n|\n/g);
}
isUntitled: boolean = false;
languageId: string = '';
isDirty: boolean = false;
@@ -49,7 +48,7 @@ export class InMemoryDocument implements vscode.TextDocument {
const before = this._contents.slice(0, offset);
const newLines = before.match(/\r\n|\n/g);
const line = newLines ? newLines.length : 0;
const preCharacters = before.match(/(\r\n|\n|^).*$/g);
const preCharacters = before.match(/(?<=\r\n|\n|^).*$/g);
return new vscode.Position(line, preCharacters ? preCharacters[0].length : 0);
}
getText(_range?: vscode.Range | undefined): string {