mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
fix(docs-infra): fail the guide build when a markdown file starts with a BOM
A leading UTF-8 byte order mark (U+FEFF) before the first `#` stops the Markdown parser from recognizing the heading, so the guide renders its title as a paragraph and drops the standard docs header. The character is invisible, so it cannot be caught in review. Add a check in the guides generation pipeline that throws when a source file starts with a BOM, failing the build with the offending file name. This sits alongside the existing unknown-anchor check and prevents the regression fixed in #69889 from recurring.
This commit is contained in:
@@ -55,6 +55,16 @@ async function main() {
|
||||
}
|
||||
|
||||
const markdownContent = await readFile(filePath, {encoding: 'utf8'});
|
||||
|
||||
// A leading byte order mark (U+FEFF) stops the first Markdown heading from being
|
||||
// recognized, so the page title renders as a paragraph and loses its header. Fail
|
||||
// the build so the BOM has to be removed from the source file instead.
|
||||
if (markdownContent.charCodeAt(0) === 0xfeff) {
|
||||
throw new Error(
|
||||
`The file "${filePath}" starts with a byte order mark (BOM). Remove it so the leading heading is parsed correctly.`,
|
||||
);
|
||||
}
|
||||
|
||||
const htmlOutputContent = await parseMarkdownAsync(markdownContent, {
|
||||
markdownFilePath: filePath,
|
||||
apiEntries: mapManifestToEntries(apiManifest),
|
||||
|
||||
Reference in New Issue
Block a user