Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions apps/docs/md-links.plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ describe('resolveDocLinks', () => {
'<a href="/agents/tools">c</a> <a href="https://github.com/x/README.md">d</a>',
);
});

it('leaves escaped markup in code and non-anchor attributes alone', () => {
const html =
'<pre><code>&lt;a href="./configuration.md"&gt;</code></pre> ' +
'<a data-href="./security.md" href="./security.md">a</a> <link href="./x.md">';
expect(resolveDocLinks(html, '/src/content/getting-started/installation')).toBe(
'<pre><code>&lt;a href="./configuration.md"&gt;</code></pre> ' +
'<a data-href="./security.md" href="/getting-started/security">a</a> <link href="./x.md">',
);
});
});

describe('mdLinksPlugin', () => {
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/md-links.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
/(<a\s(?:[^>]*?\s)?href=)(["'])([^"']*)\2/gi,
Comment thread
erkamyaman marked this conversation as resolved.
(match, attr: string, quote: string, href: string) => {
const route = resolveMdHref(href, pageFile);
return route === null ? match : `${attr}${quote}${route}${quote}`;
Expand Down
Loading