docs(docs-infra): quote title attributes in links (#63578)

Prevent broken HTML when link titles contain spaces by properly quoting the title attribute

PR Close #63578
This commit is contained in:
Shuaib Hasan Akib 2025-09-04 01:51:29 +06:00 committed by Andrew Scott
parent f18980c18d
commit f2ec6fbfa7
3 changed files with 9 additions and 2 deletions

View file

@ -1,3 +1,4 @@
[Angular Site](https://angular.dev)
[same page](#test)
[same site](../other/page)
[same site](../other/page)
[npm packages](https://docs.npmjs.com/getting-started/what-is-npm "What is npm?")

View file

@ -31,4 +31,10 @@ describe('markdown to html', () => {
it('should render internal links that are relative paths', () => {
expect(parsedMarkdown).toContain('<a href="../other/page">same site</a>');
});
it('should render links with title attributes properly quoted', () => {
expect(parsedMarkdown).toContain(
'<a href="https://docs.npmjs.com/getting-started/what-is-npm" title="What is npm?" target="_blank">npm packages</a>',
);
});
});

View file

@ -24,6 +24,6 @@ export function linkRender(this: Renderer, {href, title, tokens}: Tokens.Link) {
return this.parser.parseInline(tokens);
}
const titleAttribute = title ? ` title=${title}` : '';
const titleAttribute = title ? ` title="${title}"` : '';
return `<a href="${href}"${titleAttribute}${anchorTarget(href)}>${this.parser.parseInline(tokens)}</a>`;
}