From 9f7ec6fc78b201a3669a40ba5a308968bbce42ac Mon Sep 17 00:00:00 2001 From: Kam Date: Wed, 30 Sep 2026 23:21:04 +0300 Subject: [PATCH] fix(docs): only rewrite .md links on anchor tags The docs link plugin rewrote any href= in the rendered HTML, including escaped markup inside code samples, so an example like in a code block was changed to a site route. It now only rewrites the href of real tags. --- apps/docs/md-links.plugin.spec.ts | 10 ++++++++++ apps/docs/md-links.plugin.ts | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/apps/docs/md-links.plugin.spec.ts b/apps/docs/md-links.plugin.spec.ts index 4af049b..c0becaf 100644 --- a/apps/docs/md-links.plugin.spec.ts +++ b/apps/docs/md-links.plugin.spec.ts @@ -41,6 +41,16 @@ describe('resolveDocLinks', () => { 'c d', ); }); + + it('leaves escaped markup in code and non-anchor attributes alone', () => { + const html = + '
<a href="./configuration.md">
' + + 'a '; + expect(resolveDocLinks(html, '/src/content/getting-started/installation')).toBe( + '
<a href="./configuration.md">
' + + 'a ', + ); + }); }); describe('mdLinksPlugin', () => { diff --git a/apps/docs/md-links.plugin.ts b/apps/docs/md-links.plugin.ts index 346f57d..371882c 100644 --- a/apps/docs/md-links.plugin.ts +++ b/apps/docs/md-links.plugin.ts @@ -43,7 +43,7 @@ export function resolveMdHref(href: string, pageFile: string): string | null { export function resolveDocLinks(html: string, pageFile: string): string { return html.replace( - /(\shref=)(["'])([^"']*)\2/g, + /(]*?\s)?href=)(["'])([^"']*)\2/gi, (match, attr: string, quote: string, href: string) => { const route = resolveMdHref(href, pageFile); return route === null ? match : `${attr}${quote}${route}${quote}`;