diff --git a/make-pdf/src/render.ts b/make-pdf/src/render.ts index 514fbbc89..fa03c9eb3 100644 --- a/make-pdf/src/render.ts +++ b/make-pdf/src/render.ts @@ -66,8 +66,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; // 1.5. Image directive suffixes: `![a](x.png){width=50%}` → data-gstack-* // attributes. Before the sanitizer (which keeps data- attrs) so the brace @@ -357,17 +359,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(/