[markdown] Ignore brackets inside link text (#151610)

* 🔨 Allow texts in bracket pairs inside link titles; [text](link)

Signed-off-by: GitHub <noreply@github.com>

* 🔨 Allow texts in bracket pairs inside link titles; [text](<link>)

Signed-off-by: GitHub <noreply@github.com>

* ⚗️ Add tests to verify  link titles can include bracket pairs

Signed-off-by: GitHub <noreply@github.com>
This commit is contained in:
Babak K. Shandiz 2022-06-09 18:48:50 +00:00 committed by GitHub
parent a38448d073
commit a8de8e2112
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View file

@ -185,12 +185,12 @@ function stripAngleBrackets(link: string) {
/**
* Matches `[text](link)`
*/
const linkPattern = /(\[((!\[[^\]]*?\]\(\s*)([^\s\(\)]+?)\s*\)\]|(?:\\\]|[^\]])*\])\(\s*)(([^\s\(\)]|\([^\s\(\)]*?\))+)\s*("[^"]*"|'[^']*'|\([^\(\)]*\))?\s*\)/g;
const linkPattern = /(\[((!\[[^\]]*?\]\(\s*)([^\s\(\)]+?)\s*\)\]|(?:\\\]|[^\]]|\][^(])*\])\(\s*)(([^\s\(\)]|\([^\s\(\)]*?\))+)\s*("[^"]*"|'[^']*'|\([^\(\)]*\))?\s*\)/g;
/**
* Matches `[text](<link>)`
*/
const linkPatternAngle = /(\[((!\[[^\]]*?\]\(\s*)([^\s\(\)]+?)\s*\)\]|(?:\\\]|[^\]])*\])\(\s*<)(([^<>]|\([^\s\(\)]*?\))+)>\s*("[^"]*"|'[^']*'|\([^\(\)]*\))?\s*\)/g;
const linkPatternAngle = /(\[((!\[[^\]]*?\]\(\s*)([^\s\(\)]+?)\s*\)\]|(?:\\\]|[^\]]|\][^(])*\])\(\s*<)(([^<>]|\([^\s\(\)]*?\))+)>\s*("[^"]*"|'[^']*'|\([^\(\)]*\))?\s*\)/g;
/**

View file

@ -101,6 +101,21 @@ suite('markdown.DocumentLinkProvider', () => {
}
});
test('Should ignore texts in brackets inside link title (#150921)', async () => {
{
const links = await getLinksForFile('[some [inner bracket pairs] in title](<link>)');
assertLinksEqual(links, [
new vscode.Range(0, 39, 0, 43),
]);
}
{
const links = await getLinksForFile('[some [inner bracket pairs] in title](link)');
assertLinksEqual(links, [
new vscode.Range(0, 38, 0, 42)
]);
}
});
test('Should handle two links without space', async () => {
const links = await getLinksForFile('a ([test](test)[test2](test2)) c');
assertLinksEqual(links, [