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}`;