mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
fix(docs-infra): escape the code example header
`buildHeaderElement` interpolated the header into a string that is then parsed
as HTML, so markup in a header became an element instead of text. The ten
captions on https://angular.dev/guide/i18n/translation-files read
`messages.fr.xlf ()`, having turned `(<trans-unit>)` into an empty element.
These are the only two headers in the guides containing markup.
(cherry picked from commit 9073469416)
This commit is contained in:
@@ -96,6 +96,11 @@ export function processForApiLinks(fragment: Element, apiEntries: ApiEntries): v
|
||||
});
|
||||
}
|
||||
|
||||
/** Escapes text that is interpolated into an HTML string. */
|
||||
function escapeHtml(text: string): string {
|
||||
return text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
||||
}
|
||||
|
||||
/** Build the header element if a header is provided in the token. */
|
||||
function buildHeaderElement(token: CodeToken) {
|
||||
let header = '';
|
||||
@@ -104,7 +109,7 @@ function buildHeaderElement(token: CodeToken) {
|
||||
}
|
||||
|
||||
if (token.header) {
|
||||
header += `<h3>${token.header}</h3>`;
|
||||
header += `<h3>${escapeHtml(token.header)}</h3>`;
|
||||
}
|
||||
|
||||
if (!header) return '';
|
||||
|
||||
Reference in New Issue
Block a user