diff --git a/make-pdf/src/render.ts b/make-pdf/src/render.ts index ae5228f42..9946eb6fe 100644 --- a/make-pdf/src/render.ts +++ b/make-pdf/src/render.ts @@ -57,8 +57,10 @@ export interface RenderResult { * Pure renderer. No side effects. */ export function render(opts: RenderOptions): RenderResult { - // 1. Markdown → HTML - const rawHtml = marked.parse(opts.markdown, { async: false }) as string; + // 1. Markdown → HTML (strip a leading YAML frontmatter block first; marked + // has no frontmatter awareness and would otherwise render it as a literal + // paragraph of body text on its own first page). + const rawHtml = marked.parse(stripFrontmatter(opts.markdown), { async: false }) as string; // 2. Sanitize const cleanHtml = sanitizeUntrustedHtml(rawHtml); @@ -311,17 +313,51 @@ function wrapChaptersByH1(html: string): string { } const chunks: string[] = []; const preamble = html.slice(0, matches[0]); + // A preamble that renders nothing visible (a leading \n\n# Hello\n\nBody.\n` }); + const chapters = result.html.match(/class="chapter"/g) ?? []; + // One chapter, not two — the invisible "); + expect(result.html).toMatch(/