From 73ad4d519e67f49a892b645b5c15946c3637712d Mon Sep 17 00:00:00 2001 From: Carsten Scholling Date: Thu, 24 Oct 2024 10:12:41 +0200 Subject: [PATCH] #164 Allow common [!ANY] alerts --- src/languageFeatures/documentLinks.ts | 5 ++--- src/test/documentLinks.test.ts | 8 ++++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/languageFeatures/documentLinks.ts b/src/languageFeatures/documentLinks.ts index 44df1e4..1c1bc83 100644 --- a/src/languageFeatures/documentLinks.ts +++ b/src/languageFeatures/documentLinks.ts @@ -171,8 +171,8 @@ const referenceLinkPattern = new RegExp( /**/r`|` + - // [shorthand] - /****/r`\[\s*(?(?:\\.|[^\[\]\\])+?)\s*\]` + + // [shorthand] but not [!shorthand] + /****/r`\[(?!\!)\s*(?(?:\\.|[^\[\]\\])+?)\s*\]` + r`)` + r`(?![\(])`, // Must not be followed by a paren to avoid matching normal links 'gm'); @@ -811,4 +811,3 @@ export function createWorkspaceLinkCache( const linkComputer = new MdLinkComputer(parser, workspace); return new MdWorkspaceInfoCache(workspace, (doc, token) => linkComputer.getAllLinks(doc, token)); } - diff --git a/src/test/documentLinks.test.ts b/src/test/documentLinks.test.ts index c7704a4..4af8337 100644 --- a/src/test/documentLinks.test.ts +++ b/src/test/documentLinks.test.ts @@ -255,6 +255,14 @@ suite('Link computer', () => { ]); }); + test('Should not find reference link shorthand when prefixed with ! (#164)', async () => { + const links = await getLinksForText(joinLines( + '[!note]', + '[!anything]', + )); + assertLinksEqual(links, []); + }); + test('Should find reference link with space in reference name', async () => { const links = await getLinksForText(joinLines( '[text][my ref]',