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:
Kam
2026-09-06 02:07:14 +03:00
committed by Andrew Scott
parent f9654aa297
commit 4d6d886ff6
@@ -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, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
}
/** 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 '';