From 95c91644855d6bb3899a191cfc517882a6e3e929 Mon Sep 17 00:00:00 2001 From: WilliamK112 <164879897+WilliamK112@users.noreply.github.com> Date: Thu, 25 Jun 2026 06:51:56 -0400 Subject: [PATCH] Ignore markdown links in HTML comments Signed-off-by: WilliamK112 <164879897+WilliamK112@users.noreply.github.com> --- src/test/documentLinks.test.ts | 4 ++-- src/util/noLinkRanges.ts | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/test/documentLinks.test.ts b/src/test/documentLinks.test.ts index 8f12934..0a18c61 100644 --- a/src/test/documentLinks.test.ts +++ b/src/test/documentLinks.test.ts @@ -459,8 +459,8 @@ suite('Link computer', () => { assertLinksEqual(links, []); }); - test.skip('Should not detect links inside inline html comments', async () => { - // See #149678 + test('Should not detect links inside inline html comments', async () => { + // See microsoft/vscode-markdown-languageservice#52 const links = await getLinksForText(joinLines( `text text`, `text text`, diff --git a/src/util/noLinkRanges.ts b/src/util/noLinkRanges.ts index fbe880f..6ec3dbd 100644 --- a/src/util/noLinkRanges.ts +++ b/src/util/noLinkRanges.ts @@ -9,6 +9,7 @@ import { rangeContains } from '../types/range.js'; import { ITextDocument } from '../types/textDocument.js'; const inlineCodePattern = /(?/g; class InlineRanges { @@ -60,6 +61,11 @@ export class NoLinkRanges { const startPosition = document.positionAt(startOffset); inlineRanges.add(lsp.Range.create(startPosition, document.positionAt(startOffset + match[0].length))); } + for (const match of text.matchAll(htmlCommentPattern)) { + const startOffset = match.index ?? 0; + const startPosition = document.positionAt(startOffset); + inlineRanges.add(lsp.Range.create(startPosition, document.positionAt(startOffset + match[0].length))); + } return new NoLinkRanges(multiline, inlineRanges); }