From 0cabe664c61aa4386bfcf22f1adbdf459e02bdae Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Tue, 18 Mar 2025 08:49:34 +0530 Subject: [PATCH] fix: normalize url fragments in internal links to correctly resolve to anchors --- src/node/markdown/plugins/link.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/node/markdown/plugins/link.ts b/src/node/markdown/plugins/link.ts index 3e48843c..c636db9f 100644 --- a/src/node/markdown/plugins/link.ts +++ b/src/node/markdown/plugins/link.ts @@ -55,6 +55,8 @@ export const linkPlugin = ( normalizeHref(hrefAttr, env) } else if (url.startsWith('#')) { hrefAttr[1] = decodeURI(hrefAttr[1]) + .normalize('NFKD') + .replace(/[\u0300-\u036F]/g, '') } // append base to internal (non-relative) urls @@ -72,7 +74,7 @@ export const linkPlugin = ( const indexMatch = url.match(indexRE) if (indexMatch) { const [, path, hash] = indexMatch - url = path + hash + url = path + hash.normalize('NFKD').replace(/[\u0300-\u036F]/g, '') } else { let cleanUrl = url.replace(/[?#].*$/, '') // transform foo.md -> foo[.html] @@ -88,7 +90,10 @@ export const linkPlugin = ( cleanUrl += '.html' } const parsed = new URL(url, 'http://a.com') - url = cleanUrl + parsed.search + parsed.hash + url = + cleanUrl + + parsed.search + + parsed.hash.normalize('NFKD').replace(/[\u0300-\u036F]/g, '') } // ensure leading . for relative paths