Skip to content

Use Garry Tan's exact Claude Code setup: 23 opinionated tools that serve as CEO, Designer, Eng Manager, Release Manager, Doc Engineer, and QA

TypeScript

make-pdf: bold Swiss-style layout by default, --style plain keeps the old look (GST-3770) (#4820)

Garry Tan80fd754fd18c
diff --git a/.gitattributes b/.gitattributes
index 397af035f..16baea2c0 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -61,3 +61,7 @@ Dockerfile* text eol=lf
# the content-addressed staged filename.
lib/diagram-render/dist/*.html text eol=lf
lib/diagram-render/dist/*.json text eol=lf
+
+# Byte-for-byte golden CSS for make-pdf --style plain; CRLF on a Windows
+# checkout would break the exact comparison.
+make-pdf/test/fixtures/print-css-plain/*.css text eol=lf
diff --git a/changelog.d/make-pdf-swiss-style.md b/changelog.d/make-pdf-swiss-style.md
new file mode 100644
index 000000000..affc9ae8f
--- /dev/null
+++ b/changelog.d/make-pdf-swiss-style.md
@@ -0,0 +1,4 @@
+---
+bump: minor
+---
+**make-pdf has a bold new default look, and `--style plain` keeps the old one.** PDFs now come out in a Swiss-poster layout: section headings in white on black bars, a red document title, small red sub-headings in a narrow left field beside the text, tables, code and diagrams across the full width, and a black cover block with a red bar. The text column holds about 70 characters a line (down from about 83), with 0.75in side margins and 11pt type on a 15pt line. `--style plain` produces exactly the previous look, and `--margins` still overrides either style. The same look applies to `--to html` and `preview`; Word output always uses the plain look.
diff --git a/docs/skills.md b/docs/skills.md
index 232f3720b..940ddd410 100644
--- a/docs/skills.md
+++ b/docs/skills.md
@@ -1300,7 +1300,7 @@ macOS may prompt for Keychain approval; Linux uses its supported keyring/fallbac
## `/make-pdf`
-Turn any markdown file into a publication-quality PDF: proper margins, page numbers, cover page, clickable TOC, mermaid and excalidraw fences rendered as vector diagrams, `--to html|docx` when you need another format. The compiled `pdf` binary does the typesetting; the printing happens in a browser — your Aside browser first. make-pdf serves the finished HTML from your machine on loopback, opens it in a tab Aside closes when it is done, prints through the browser's own PDF engine (tagged PDF, document outline, header and footer templates all intact), and copies the file out. Nothing leaves the box. When Aside is absent (Linux, Windows, or the app closed) the same pipeline prints through gstack's bundled browser instead, so a PDF comes out on every platform. Full guide to fences and formats: [howto-diagrams-and-formats.md](howto-diagrams-and-formats.md).
+Turn any markdown file into a publication-quality PDF: proper margins, page numbers, cover page, clickable TOC, mermaid and excalidraw fences rendered as vector diagrams, `--to html|docx` when you need another format. The default look is a bold Swiss layout (white-on-black section bars, red accents, sub-headings in a narrow left field); `--style plain` keeps the earlier quiet look, and Word output always uses plain. The compiled `pdf` binary does the typesetting; the printing happens in a browser — your Aside browser first. make-pdf serves the finished HTML from your machine on loopback, opens it in a tab Aside closes when it is done, prints through the browser's own PDF engine (tagged PDF, document outline, header and footer templates all intact), and copies the file out. Nothing leaves the box. When Aside is absent (Linux, Windows, or the app closed) the same pipeline prints through gstack's bundled browser instead, so a PDF comes out on every platform. Full guide to fences and formats: [howto-diagrams-and-formats.md](howto-diagrams-and-formats.md).
---
diff --git a/make-pdf/SKILL.md b/make-pdf/SKILL.md
index f34e512d0..6bf483ed3 100644
--- a/make-pdf/SKILL.md
+++ b/make-pdf/SKILL.md
@@ -196,9 +196,13 @@ Skills that run plan reviews (`/plan-*-review`, `/codex review`) include the EXI
# make-pdf: publication-quality PDFs from markdown
-Turn `.md` files into PDFs that look like Faber & Faber essays: 1in margins,
-left-aligned body, Helvetica throughout, curly quotes and em dashes, optional
-cover page and clickable TOC, diagonal DRAFT watermark when you need it.
+Turn `.md` files into finished PDFs. The default look, `swiss`, is a bold Swiss
+layout: section headings in white on black bars, a red title, small red
+sub-headings in a narrow left field beside the text, a black cover block, and a
+text column of about 70 characters a line. `--style plain` gives the quiet look
+(1in margins, 12pt body, Faber & Faber essay style). Both are left-aligned,
+Helvetica throughout, with curly quotes and em dashes, an optional cover page
+and clickable TOC, and a diagonal DRAFT watermark when you need it.
Copy-paste from the PDF produces clean words, never "S a i l i n g".
On Linux, install `fonts-liberation` for correct rendering — Helvetica and Arial
@@ -343,8 +347,13 @@ promoted page is vertically centered. When the heuristic guesses wrong,
## Common flags
```
+Look:
+ --style swiss|plain swiss (default): black heading bars, red accents,
+ a left field for sub-headings. plain: the quiet look.
+
Page layout:
- --margins <dim> 1in (default) | 72pt | 2.54cm | 25mm
+ --margins <dim> swiss default 0.7in 0.75in 0.85in 0.75in; plain
+ default 1in | 72pt | 2.54cm | 25mm (sets all four)
--page-size letter|a4|legal
Structure:
@@ -403,6 +412,8 @@ before running.
(understand you're giving the markdown file permission to fetch from its
image URLs).
- Generated PDF too tall/wide → `--page-size a4` or `--margins 0.75in`.
+- Someone wants the old, quiet look (or a document full of wide tables reads
+ better without the left field) → `--style plain`.
## Output contract
diff --git a/make-pdf/SKILL.md.tmpl b/make-pdf/SKILL.md.tmpl
index 27bed9e7a..f19d0853c 100644
--- a/make-pdf/SKILL.md.tmpl
+++ b/make-pdf/SKILL.md.tmpl
@@ -3,8 +3,8 @@ name: make-pdf
preamble-tier: 1
version: 1.0.0
description: |
- Turn any markdown file into a publication-quality PDF. Proper 1in margins,
- intelligent page breaks, page numbers, cover pages, running headers, curly
+ Turn any markdown file into a publication-quality PDF. A bold Swiss layout
+ by default (--style plain for a quiet one), intelligent page breaks, page numbers, cover pages, running headers, curly
quotes and em dashes, clickable TOC, diagonal DRAFT watermark. Not a draft
artifact — a finished artifact. Use when asked to "make a PDF", "export to
PDF", "turn this markdown into a PDF", or "generate a document". (gstack)
@@ -32,9 +32,13 @@ allowed-tools:
# make-pdf: publication-quality PDFs from markdown
-Turn `.md` files into PDFs that look like Faber & Faber essays: 1in margins,
-left-aligned body, Helvetica throughout, curly quotes and em dashes, optional
-cover page and clickable TOC, diagonal DRAFT watermark when you need it.
+Turn `.md` files into finished PDFs. The default look, `swiss`, is a bold Swiss
+layout: section headings in white on black bars, a red title, small red
+sub-headings in a narrow left field beside the text, a black cover block, and a
+text column of about 70 characters a line. `--style plain` gives the quiet look
+(1in margins, 12pt body, Faber & Faber essay style). Both are left-aligned,
+Helvetica throughout, with curly quotes and em dashes, an optional cover page
+and clickable TOC, and a diagonal DRAFT watermark when you need it.
Copy-paste from the PDF produces clean words, never "S a i l i n g".
On Linux, install `fonts-liberation` for correct rendering — Helvetica and Arial
@@ -179,8 +183,13 @@ promoted page is vertically centered. When the heuristic guesses wrong,
## Common flags
```
+Look:
+ --style swiss|plain swiss (default): black heading bars, red accents,
+ a left field for sub-headings. plain: the quiet look.
+
Page layout:
- --margins <dim> 1in (default) | 72pt | 2.54cm | 25mm
+ --margins <dim> swiss default 0.7in 0.75in 0.85in 0.75in; plain
+ default 1in | 72pt | 2.54cm | 25mm (sets all four)
--page-size letter|a4|legal
Structure:
@@ -239,6 +248,8 @@ before running.
(understand you're giving the markdown file permission to fetch from its
image URLs).
- Generated PDF too tall/wide → `--page-size a4` or `--margins 0.75in`.
+- Someone wants the old, quiet look (or a document full of wide tables reads
+ better without the left field) → `--style plain`.
## Output contract
diff --git a/make-pdf/src/cli.ts b/make-pdf/src/cli.ts
index 956b6600f..9a092ae66 100644
--- a/make-pdf/src/cli.ts
+++ b/make-pdf/src/cli.ts
@@ -13,7 +13,8 @@
import { COMMANDS } from "./commands";
import { ExitCode, BrowserUnavailableError } from "./types";
-import type { GenerateOptions, PreviewOptions } from "./types";
+import type { GenerateOptions, PreviewOptions, Style } from "./types";
+import { STYLES } from "./style-swiss";
interface ParsedArgs {
command: string;
@@ -85,8 +86,14 @@ function printUsage(): void {
lines.push(" html = single self-contained file, no network refs.");
lines.push(" docx = content fidelity, diagrams as PNG.");
lines.push("");
+ lines.push("Look:");
+ lines.push(" --style swiss|plain swiss (default): bold Swiss layout, black heading bars,");
+ lines.push(" red accents, a left field for sub-headings.");
+ lines.push(" plain: the look before swiss, unchanged.");
+ lines.push("");
lines.push("Page layout:");
- lines.push(" --margins <dim> All four margins (default: 1in). in, pt, cm, mm.");
+ lines.push(" --margins <dim> All four margins (default: 0.7in 0.75in 0.85in 0.75in");
+ lines.push(" under swiss, 1in under plain). in, pt, cm, mm.");
lines.push(" --page-size letter|a4|legal (aliases: --format — page SIZE, not output format)");
lines.push("");
lines.push("Document structure:");
@@ -126,6 +133,15 @@ function printUsage(): void {
console.error(lines.join("\n"));
}
+function styleFromFlags(f: Record<string, string | boolean>, command: string): Style | undefined {
+ if (f.style === undefined) return undefined;
+ const value = typeof f.style === "string" ? f.style.toLowerCase() : "";
+ if ((STYLES as readonly string[]).includes(value)) return value as Style;
+ const got = typeof f.style === "string" ? `'${f.style}'` : "no value";
+ console.error(`$P ${command}: invalid --style (got ${got}). Expected ${STYLES.join(" or ")}, for example --style plain.`);
+ process.exit(ExitCode.BadArgs);
+}
+
function generateOptionsFromFlags(parsed: ParsedArgs): GenerateOptions {
const p = parsed.positional;
if (p.length === 0) {
@@ -149,6 +165,7 @@ function generateOptionsFromFlags(parsed: ParsedArgs): GenerateOptions {
input: p[0],
output: p[1],
to: to as GenerateOptions["to"],
+ style: styleFromFlags(f, "generate"),
margins: f.margins as string | undefined,
marginTop: f["margin-top"] as string | undefined,
marginRight: f["margin-right"] as string | undefined,
@@ -192,6 +209,7 @@ function previewOptionsFromFlags(parsed: ParsedArgs): PreviewOptions {
};
return {
input: p[0],
+ style: styleFromFlags(f, "preview"),
cover: f.cover === true,
toc: f.toc === true,
watermark: typeof f.watermark === "string" ? f.watermark : undefined,
diff --git a/make-pdf/src/commands.ts b/make-pdf/src/commands.ts
index 5ccb3aeda..4aeb813f7 100644
--- a/make-pdf/src/commands.ts
+++ b/make-pdf/src/commands.ts
@@ -20,6 +20,8 @@ export const COMMANDS = new Map<string, {
usage: "generate <input.md> [output.pdf] [options]",
category: "Primary",
flags: [
+ // Look
+ "--style",
// Page layout
"--margins", "--margin-top", "--margin-right", "--margin-bottom", "--margin-left",
"--page-size", "--format",
@@ -41,6 +43,7 @@ export const COMMANDS = new Map<string, {
usage: "preview <input.md> [options]",
category: "Primary",
flags: [
+ "--style",
"--cover", "--toc", "--no-chapter-breaks", "--watermark",
"--no-confidential", "--allow-network",
"--title", "--author", "--date",
diff --git a/make-pdf/src/diagram-prepass.ts b/make-pdf/src/diagram-prepass.ts
index b3e2c8e95..3f5d2f9aa 100644
--- a/make-pdf/src/diagram-prepass.ts
+++ b/make-pdf/src/diagram-prepass.ts
@@ -833,6 +833,18 @@ const PAGE_HEIGHTS_IN: Record<string, number> = {
tabloid: 17,
};
+export function contentHeightInches(opts: {
+ pageSize?: string;
+ margins?: string;
+ marginTop?: string;
+ marginBottom?: string;
+}): number {
+ const pageH = PAGE_HEIGHTS_IN[opts.pageSize ?? "letter"] ?? 11;
+ const top = dimToInches(opts.marginTop ?? opts.margins, 1);
+ const bottom = dimToInches(opts.marginBottom ?? opts.margins, 1);
+ return Math.max(1, pageH - top - bottom);
+}
+
/**
* Content box of the rotated (landscape) named page: portrait page HEIGHT
* becomes the landscape width; portrait WIDTH becomes the landscape height.
diff --git a/make-pdf/src/orchestrator.ts b/make-pdf/src/orchestrator.ts
index 4fe440546..474659548 100644
--- a/make-pdf/src/orchestrator.ts
+++ b/make-pdf/src/orchestrator.ts
@@ -23,7 +23,7 @@ import * as path from "node:path";
import { spawn } from "node:child_process";
import { render } from "./render";
-import { screenCss } from "./print-css";
+import { DEFAULT_STYLE, resolveMargins, screenCss } from "./print-css";
import type { GenerateOptions, PreviewOptions } from "./types";
import { ExitCode } from "./types";
import { pickEngine } from "../../lib/aside-render";
@@ -84,7 +84,9 @@ class ProgressReporter {
/**
* generate — full pipeline. Returns the output PDF path on success.
*/
-export async function generate(opts: GenerateOptions): Promise<string> {
+export async function generate(requested: GenerateOptions): Promise<string> {
+ const style = requested.to === "docx" ? "plain" : requested.style ?? DEFAULT_STYLE;
+ const opts = resolveMargins(requested, style);
const progress = new ProgressReporter(opts);
const input = path.resolve(opts.input);
@@ -118,6 +120,7 @@ export async function generate(opts: GenerateOptions): Promise<string> {
watermark: opts.watermark,
noChapterBreaks: opts.noChapterBreaks,
confidential: opts.confidential,
+ style,
pageSize: opts.pageSize,
margins: opts.margins,
marginTop: opts.marginTop,
@@ -182,7 +185,7 @@ export async function generate(opts: GenerateOptions): Promise<string> {
if (to === "html") {
const withScreenLayer = finalHtml.replace(
"</style>",
- `</style>\n<style>\n${screenCss()}\n</style>`,
+ `</style>\n<style>\n${screenCss(style)}\n</style>`,
);
fs.writeFileSync(outputPath, withScreenLayer, "utf8");
const kb = Math.round(fs.statSync(outputPath).size / 1024);
@@ -201,7 +204,8 @@ export async function generate(opts: GenerateOptions): Promise<string> {
if (opts.headerTemplate) printOnly.push("--header-template");
if (opts.footerTemplate) printOnly.push("--footer-template");
if (opts.pageSize) printOnly.push("--page-size");
- if (opts.margins || opts.marginTop || opts.marginRight || opts.marginBottom || opts.marginLeft) printOnly.push("--margins");
+ if (requested.margins || requested.marginTop || requested.marginRight || requested.marginBottom || requested.marginLeft) printOnly.push("--margins");
+ if (requested.style) printOnly.push("--style");
if (printOnly.length > 0) {
warn(`docx is content-fidelity: ${printOnly.join(", ")} do not apply to Word output`);
}
@@ -240,7 +244,8 @@ export async function generate(opts: GenerateOptions): Promise<string> {
pageNumbers: false,
tagged: opts.tagged !== false,
outline: opts.outline !== false,
- printBackground: !!opts.watermark,
+ // swiss paints black heading bars and a black cover block: backgrounds must print.
+ printBackground: !!opts.watermark || style === "swiss",
// Named landscape pages only take effect when Chromium honors CSS page
// sizes. Flip it ONLY when a promotion exists — minimal behavior change
// for every other document.
@@ -301,6 +306,7 @@ export async function preview(opts: PreviewOptions): Promise<string> {
noChapterBreaks: opts.noChapterBreaks,
confidential: opts.confidential,
pageNumbers: opts.pageNumbers,
+ style: opts.style,
});
progress.end("Rendering HTML", `${rendered.meta.wordCount} words`);
diff --git a/make-pdf/src/print-css.ts b/make-pdf/src/print-css.ts
index 02137a11e..19763085a 100644
--- a/make-pdf/src/print-css.ts
+++ b/make-pdf/src/print-css.ts
@@ -34,6 +34,15 @@
* single source of truth (DRY) and every stack stays in sync.
*/
+import {
+ DEFAULT_STYLE,
+ SWISS_MARGIN_SHORTHAND,
+ SWISS_MARGINS,
+ swissRules,
+ swissScreenCss,
+ type Style,
+} from "./style-swiss";
+
// Metric-compatible sans stack: Helvetica (macOS), Liberation Sans (Linux,
// ships via fonts-liberation), Arial (Windows). Shared by every text surface.
const SANS_STACK = `Helvetica, "Liberation Sans", Arial`;
@@ -42,7 +51,12 @@ const CJK_STACK = `"PingFang SC", "Heiti SC", "Noto Sans CJK SC", "Source Han Sa
// Color-emoji families: Apple (macOS), Segoe (Windows), Noto (Linux).
const EMOJI_FAMILIES = `"Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji"`;
+export { DEFAULT_STYLE, STYLES, type Style } from "./style-swiss";
+
export interface PrintCssOptions {
+ // Look: "swiss" (default) or "plain" (the look before GSTA-849, byte for byte).
+ style?: Style;
+
// Document structure
cover?: boolean;
toc?: boolean;
@@ -58,7 +72,7 @@ export interface PrintCssOptions {
// Page size (in CSS `@page size:` terms)
pageSize?: "letter" | "a4" | "legal" | "tabloid";
- // Margins (default 1in)
+ // Margins (default: 1in plain, 0.7in 0.75in 0.85in 0.75in swiss)
margins?: string;
// Whether to render "N of M" page numbers in the @page @bottom-center rule.
@@ -71,8 +85,9 @@ export interface PrintCssOptions {
* Produce a CSS block (no <style> wrapper) for inline injection.
*/
export function printCss(opts: PrintCssOptions = {}): string {
+ const style = opts.style ?? DEFAULT_STYLE;
const size = opts.pageSize ?? "letter";
- const margin = opts.margins ?? "1in";
+ const margin = opts.margins ?? (style === "swiss" ? SWISS_MARGIN_SHORTHAND : "1in");
const hasWatermark = typeof opts.watermark === "string" && opts.watermark.length > 0;
return [
@@ -91,9 +106,32 @@ export function printCss(opts: PrintCssOptions = {}): string {
footnoteRules(),
hasWatermark ? watermarkRules() : "",
breakAvoidRules(),
+ style === "swiss" ? swissRules({ cover: opts.cover, toc: opts.toc }) : "",
].filter(Boolean).join("\n\n");
}
+type MarginOptions = {
+ margins?: string; marginTop?: string; marginRight?: string;
+ marginBottom?: string; marginLeft?: string;
+};
+
+/**
+ * Fill in the style's default margins. Explicit --margins sets all four
+ * sides and --margin-<side> overrides one, under either style. plain returns
+ * the options untouched, so every plain code path still sees exactly what
+ * the user passed (and falls back to 1in where it always did).
+ */
+export function resolveMargins<T extends MarginOptions>(opts: T, style: Style): T {
+ if (style !== "swiss") return opts;
+ return {
+ ...opts,
+ marginTop: opts.marginTop ?? opts.margins ?? SWISS_MARGINS.top,
+ marginRight: opts.marginRight ?? opts.margins ?? SWISS_MARGINS.right,
+ marginBottom: opts.marginBottom ?? opts.margins ?? SWISS_MARGINS.bottom,
+ marginLeft: opts.marginLeft ?? opts.margins ?? SWISS_MARGINS.left,
+ };
+}
+
function pageRules(size: string, margin: string, opts: PrintCssOptions): string {
const runningHeader = escapeCssString(opts.runningHeader ?? "");
const showConfidential = opts.confidential !== false;
@@ -156,8 +194,8 @@ function pageRules(size: string, margin: string, opts: PrintCssOptions): string
* (centered measure, padding, no print-only chapter breaks forcing scroll
* gaps). Print output is unaffected — media-scoped.
*/
-export function screenCss(): string {
- return [
+export function screenCss(style: Style = DEFAULT_STYLE): string {
+ const plain = [
`@media screen {`,
// ~42em at 12pt ≈ 70-75 characters per line — the readable ceiling.
` body { max-width: 42em; margin: 0 auto; padding: 2.5em 1.5em; }`,
@@ -168,6 +206,7 @@ export function screenCss(): string {
` .toc li .toc-page, .toc li .toc-dots { display: none; }`,
`}`,
].join("\n");
+ return style === "swiss" ? `${plain}\n${swissScreenCss()}` : plain;
}
function rootTypography(): string {
diff --git a/make-pdf/src/render.ts b/make-pdf/src/render.ts
index e696cfa1b..023401145 100644
--- a/make-pdf/src/render.ts
+++ b/make-pdf/src/render.ts
@@ -13,8 +13,10 @@
import { marked } from "marked";
import { smartypants } from "./smartypants";
-import { printCss, type PrintCssOptions } from "./print-css";
+import { DEFAULT_STYLE, printCss, resolveMargins, type PrintCssOptions, type Style } from "./print-css";
+import { swissCoverTitle, swissFieldHeadingLines } from "./style-swiss";
import { applyImageDirectives } from "./image-policy";
+import { contentHeightInches, contentWidthInches } from "./diagram-prepass";
export interface RenderOptions {
markdown: string;
@@ -32,6 +34,9 @@ export interface RenderOptions {
noChapterBreaks?: boolean;
confidential?: boolean; // default: true
+ // Look: "swiss" (default) or "plain".
+ style?: Style;
+
// Page layout
pageSize?: "letter" | "a4" | "legal" | "tabloid";
margins?: string;
@@ -95,7 +100,10 @@ export function render(opts: RenderOptions): RenderResult {
// numbering is always off in orchestrator). If the caller supplied a custom
// footerTemplate, suppress CSS page numbers too so their footer wins.
const showPageNumbers = opts.pageNumbers !== false && !opts.footerTemplate;
+ const style = opts.style ?? DEFAULT_STYLE;
+ const pageBox = resolveMargins(opts, style);
const cssOptions: PrintCssOptions = {
+ style,
cover: opts.cover,
toc: opts.toc,
noChapterBreaks: opts.noChapterBreaks,
@@ -105,7 +113,7 @@ export function render(opts: RenderOptions): RenderResult {
pageSize: opts.pageSize,
// Compose per-side margins into the CSS shorthand so @page stays the
// single source of truth even under preferCSSPageSize.
- margins: composeMargins(opts),
+ margins: composeMargins(pageBox),
pageNumbers: showPageNumbers,
};
const css = printCss(cssOptions);
@@ -117,6 +125,8 @@ export function render(opts: RenderOptions): RenderResult {
subtitle: opts.subtitle,
author: derivedAuthor,
date: derivedDate,
+ style,
+ box: { contentWIn: contentWidthInches(pageBox), contentHIn: contentHeightInches(pageBox) },
})
: "";
@@ -128,10 +138,12 @@ export function render(opts: RenderOptions): RenderResult {
const tocBlock = opts.toc ? buildTocBlock(anchored.entries) : "";
+ const laidOutHtml = style === "swiss" ? keepFieldHeadingsWithText(anchoredHtml) : anchoredHtml;
+
// Wrap body in .chapter sections at H1 boundaries if chapter breaks are on.
const chapterHtml = opts.noChapterBreaks
- ? `<section class="chapter">${anchoredHtml}</section>`
- : wrapChaptersByH1(anchoredHtml);
+ ? `<section class="chapter">${laidOutHtml}</section>`
+ : wrapChaptersByH1(laidOutHtml);
const watermarkBlock = opts.watermark
? `<div class="watermark">${escapeHtml(opts.watermark)}</div>`
@@ -401,19 +413,87 @@ function sanitizePass(html: string): string {
// ─── Cover / TOC / Chapter helpers ────────────────────────────────────
+/**
+ * swiss sets an h3 in the left field beside the text that follows it. A float
+ * does not move with that text: when orphans push a paragraph to the next
+ * page, a floated sub-heading stays behind at the page foot. So the h3 and the
+ * paragraph, list or quote right after it go in <div class="swiss-keep">,
+ * where the CSS pins the h3 to the wrapper's top and the wrapper starts where
+ * the text does. min-height keeps a sub-heading longer than its text clear of
+ * the next block. (Code, tables, figures and image-only paragraphs need no
+ * wrapper: the CSS keeps the h3 in normal flow above them.) Only top-level
+ * blocks are paired: an h3 inside raw HTML, a quote or a list item is not in
+ * the field, and the CSS that positions the wrapper applies only at the top.
+ */
+export function keepFieldHeadingsWithText(html: string): string {
+ const blocks = topLevelBlocks(html);
+ const out: string[] = [];
+ let last = 0;
+ for (let i = 0; i + 1 < blocks.length; i++) {
+ const [h3, next] = [blocks[i], blocks[i + 1]];
+ if (h3.tag !== "h3" || !/^(p|ul|ol|blockquote)$/.test(next.tag)) continue;
+ if (html.slice(h3.end, next.start).trim() !== "") continue;
+ const text = html.slice(next.start, next.end);
+ if (next.tag === "p" && /^<p\b[^>]*>[^<]*<img\b[^>]*>[^<]*<\/p>$/i.test(text)) continue;
+ const heading = html.slice(h3.start, h3.end);
+ const minPt = swissFieldHeadingLines(stripTags(heading)) * 13 + 2;
+ out.push(html.slice(last, h3.start), `<div class="swiss-keep" style="min-height: ${minPt}pt;">${html.slice(h3.start, next.end)}</div>`);
+ last = next.end;
+ i++;
+ }
+ out.push(html.slice(last));
+ return out.join("");
+}
+
+const VOID_TAGS = new Set(["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "source", "track", "wbr"]);
+
+/**
+ * Spans of the top-level elements in a fragment. Comments are skipped, void
+ * tags open nothing, a close tag with no matching open tag is ignored, and a
+ * close tag closes whatever it left open, so unbalanced raw HTML cannot leave
+ * the rest of the document nested.
+ */
+function topLevelBlocks(html: string): Array<{ tag: string; start: number; end: number }> {
+ const blocks: Array<{ tag: string; start: number; end: number }> = [];
+ const stack: string[] = [];
+ let start = 0;
+ const token = /<!--[\s\S]*?(?:-->|$)|<(\/?)([a-zA-Z][\w-]*)\b[^>]*>/g;
+ let m: RegExpExecArray | null;
+ while ((m = token.exec(html)) !== null) {
+ if (!m[2]) continue;
+ const tag = m[2].toLowerCase();
+ if (m[1]) {
+ const at = stack.lastIndexOf(tag);
+ if (at < 0) continue;
+ stack.length = at;
+ if (at === 0) blocks.push({ tag, start, end: token.lastIndex });
+ continue;
+ }
+ if (VOID_TAGS.has(tag) || m[0].endsWith("/>")) continue;
+ if ((tag === "li" || tag === "p") && stack[stack.length - 1] === tag) stack.pop();
+ if (stack.length === 0) start = m.index;
+ stack.push(tag);
+ }
+ return blocks;
+}
+
function buildCoverBlock(opts: {
title: string;
subtitle?: string;
author?: string;
date: string;
+ style: Style;
+ box: { contentWIn: number; contentHIn: number };
}): string {
const title = escapeHtml(opts.title);
+ const size = opts.style === "swiss" ? swissCoverTitle(opts.title, opts.box) : undefined;
+ const titleStyle = size ? ` style="font-size: ${size.fontPt}pt; padding-top: ${size.padTopIn}in;"` : "";
const subtitle = opts.subtitle ? escapeHtml(opts.subtitle) : "";
const author = opts.author ? escapeHtml(opts.author) : "";
const date = escapeHtml(opts.date);
return [
`<section class="cover">`,
- ` <h1 class="cover-title">${title}</h1>`,
+ ` <h1 class="cover-title"${titleStyle}>${title}</h1>`,
subtitle ? ` <p class="cover-subtitle">${subtitle}</p>` : ``,
` <hr class="rule">`,
` <div class="cover-meta">`,
diff --git a/make-pdf/src/style-swiss.ts b/make-pdf/src/style-swiss.ts
new file mode 100644
index 000000000..6b5e536eb
--- /dev/null
+++ b/make-pdf/src/style-swiss.ts
@@ -0,0 +1,187 @@
+/**
+ * The "swiss" print style: make-pdf's default look since GSTA-849.
+ *
+ * A Swiss-poster layout in the Müller-Brockmann tradition, picked by the
+ * owner in blind A/B pairs over today's plain look ("plain" lives in
+ * print-css.ts and is untouched by this file). The page is split into two
+ * fields: a narrow left field that holds small red sub-headings, and a text
+ * column to its right. Section headings run the full width as white type on a
+ * black bar whose text starts at the column edge, so every heading, paragraph
+ * and list shares one left edge. Tables, code, figures and images use the full
+ * width. Readable line length comes from the field, never from wide margins.
+ *
+ * These rules are appended after the plain rules, so every structural rule
+ * (page boxes, chapter breaks, TOC leaders, footnotes, watermark, break-avoid)
+ * keeps a single source in print-css.ts.
+ */
+
+export type Style = "swiss" | "plain";
+
+export const DEFAULT_STYLE: Style = "swiss";
+
+export const STYLES: readonly Style[] = ["swiss", "plain"];
+
+/** Width of the left field. The text column starts this far into the type area. */
+export const SWISS_FIELD_IN = 1.9;
+
+/** Widest text column, so long lines stay readable on legal and tabloid paper. */
+const SWISS_COLUMN_MAX_IN = 5.1;
+
+export const SWISS_MARGINS = { top: "0.7in", right: "0.75in", bottom: "0.85in", left: "0.75in" } as const;
+
+export const SWISS_MARGIN_SHORTHAND = `${SWISS_MARGINS.top} ${SWISS_MARGINS.right} ${SWISS_MARGINS.bottom} ${SWISS_MARGINS.left}`;
+
+const RED = "#e30613";
+const INK = "#111";
+const EXACT = "-webkit-print-color-adjust: exact; print-color-adjust: exact;";
+
+export function swissRules(opts: { cover?: boolean; toc?: boolean } = {}): string {
+ return [
+ `:root { --swiss-field: ${SWISS_FIELD_IN}in; }`,
+ `body { font-size: 11pt; line-height: 15pt; }`,
+ `.chapter { display: flow-root; }`,
+ `.chapter > * { margin-left: var(--swiss-field); max-width: ${SWISS_COLUMN_MAX_IN}in; }`,
+ `.chapter > h1, .chapter > h2, .chapter > table, .chapter > pre, .chapter > figure, .chapter > .page-wide, .chapter > p:has(> img:only-child) { margin-left: 0; max-width: none; clear: left; }`,
+ // An h3 with text after it sits absolutely at the top of a wrapper that holds
+ // that text, so it always starts on the page where the text starts; the
+ // wrapper's min-height (set by render.ts from the heading's length) keeps a
+ // long sub-heading clear of the next block.
+ `.chapter > .swiss-keep { position: relative; clear: left; margin-left: 0; max-width: none; }`,
+ `.chapter > .swiss-keep > h3 { position: absolute; top: 0; left: 0; }`,
+ `.chapter > .swiss-keep > :not(h3) { margin-left: var(--swiss-field); max-width: ${SWISS_COLUMN_MAX_IN}in; }`,
+ `.chapter > hr { clear: left; height: 0; border: 0; border-top: 0.5pt solid ${INK}; margin: 12pt 0 12pt var(--swiss-field); }`,
+ `.chapter > h1 { font-size: 46pt; line-height: 46pt; letter-spacing: -0.035em; font-weight: 700; margin: 0 0 20pt; color: ${RED}; overflow-wrap: anywhere; }`,
+ `.chapter > h1 + p { font-size: 15pt; line-height: 20pt; margin-bottom: 18pt; }`,
+ `.chapter > h2 { ${EXACT} background: ${INK}; color: #fff; font-size: 17pt; line-height: 20pt; font-weight: 700; letter-spacing: -0.01em; margin: 24pt 0 12pt; padding: 7pt 10pt 8pt var(--swiss-field); overflow-wrap: anywhere; }`,
+ // A bar never ends a page: the block after it brings at least three of its lines along.
+ `.chapter > h2 + p, .chapter > h2 + blockquote, .chapter > h2 + ul > li:first-child, .chapter > h2 + ol > li:first-child { orphans: 3; }`,
+ `.chapter > h3, .chapter > .swiss-keep > h3 { float: left; clear: left; width: calc(var(--swiss-field) - 0.2in); margin: 1pt 0 0 0; break-inside: avoid; font-size: 10pt; line-height: 13pt; font-weight: 700; color: ${RED}; text-transform: none; letter-spacing: 0; overflow-wrap: anywhere; }`,
+ // Above a block that cannot split (code, a table, a figure, an image) the
+ // sub-heading stays in normal flow, so break-after: avoid still keeps it
+ // with that block instead of stranding it at a page foot.
+ `.chapter > h3:has(+ pre), .chapter > h3:has(+ table), .chapter > h3:has(+ figure), .chapter > h3:has(+ p > img:only-child) { float: none; margin: 6pt 0 4pt 0; }`,
+ `.chapter > .swiss-keep > h3 { float: none; }`,
+ `p { margin: 0 0 7.5pt; }`,
+ `ul, ol { padding-left: 14pt; margin: 0 0 7.5pt; }`,
+ `li { margin: 0; line-height: 15pt; }`,
+ `table { font-size: 9.5pt; line-height: 13pt; border-top: 2pt solid ${INK}; border-bottom: 2pt solid ${INK}; margin: 6pt 0 15pt; }`,
+ `th, td { padding: 4pt 10pt 4pt 0; border-bottom: 0.5pt solid #bbb; }`,
+ `th { color: ${RED}; border-bottom: 1pt solid ${INK}; }`,
+ `pre { background: none; border: 0; border-left: 3pt solid ${RED}; border-radius: 0; padding: 2pt 0 2pt 10pt; font-size: 9pt; line-height: 12pt; }`,
+ `blockquote { border-left: 3pt solid ${RED}; }`,
+ `figure.diagram, figure.diagram .diagram-caption { text-align: left; }`,
+ `figcaption, .diagram-caption { font-style: normal; font-weight: 700; color: ${RED}; font-size: 9pt; }`,
+ opts.cover ? coverRules() : "",
+ opts.toc ? `.toc h2 { ${EXACT} background: ${INK}; color: #fff; font-size: 17pt; line-height: 20pt; letter-spacing: -0.01em; text-transform: none; margin: 0 0 18pt; padding: 7pt 10pt 8pt var(--swiss-field); }` : "",
+ ].filter(Boolean).join("\n");
+}
+
+function coverRules(): string {
+ return [
+ `.cover { ${EXACT} padding-top: 0; }`,
+ `.cover h1.cover-title { ${EXACT} background: ${INK}; color: #fff; font-size: 96pt; line-height: 0.92; letter-spacing: -0.045em; max-width: none; margin: 0 0 18pt; padding: 3.2in 18pt 22pt 18pt; overflow-wrap: anywhere; }`,
+ `.cover .cover-subtitle, .cover .cover-meta { margin-left: var(--swiss-field); }`,
+ `.cover hr.rule { ${EXACT} width: calc(var(--swiss-field) - 0.2in); border-top: 10pt solid ${RED}; margin: 0 0 14pt var(--swiss-field); }`,
+ `.cover .cover-meta { font-size: 13pt; line-height: 18pt; color: ${INK}; }`,
+ ].join("\n");
+}
+
+/** Screen layer for `--to html`: room for the field on wide screens, one column on phones. */
+export function swissScreenCss(): string {
+ return [
+ `@media screen {`,
+ ` body { max-width: 7.5in; }`,
+ `}`,
+ `@media screen and (max-width: 48em) {`,
+ ` .chapter > *, .chapter > hr, .cover .cover-subtitle, .cover .cover-meta, .cover hr.rule { margin-left: 0; max-width: none; }`,
+ ` .chapter > h3, .chapter > .swiss-keep > h3 { float: none; position: static; width: auto; margin: 14pt 0 4pt; }`,
+ ` .chapter > .swiss-keep { min-height: 0 !important; }`,
+ ` .chapter > .swiss-keep > :not(h3) { margin-left: 0; max-width: none; }`,
+ ` .chapter > h2, .toc h2 { padding-left: 10pt; }`,
+ ` .cover h1.cover-title { font-size: 44pt !important; padding-top: 1in !important; }`,
+ `}`,
+ ].join("\n");
+}
+
+/** Estimated lines an h3 takes in the left field (10pt bold, field width less 0.2in). */
+export function swissFieldHeadingLines(text: string): number {
+ const widthPt = (SWISS_FIELD_IN - 0.2) * 72;
+ let lines = 1;
+ let x = 0;
+ for (const word of text.trim().split(/\s+/)) {
+ const w = Array.from(word).reduce((s, g) => s + glyphEm(g) * 1.06, 0) * 10;
+ const space = glyphEm(" ") * 10;
+ if (x > 0 && x + w > widthPt) { lines++; x = 0; }
+ if (w > widthPt) {
+ lines += Math.ceil(w / widthPt) - 1;
+ x = w % widthPt;
+ } else {
+ x += w;
+ }
+ x += space;
+ }
+ return lines;
+}
+
+const WIDE_CHAR = /[\u1100-\u115F\u2E80-\uA4CF\uAC00-\uD7A3\uF900-\uFAFF\uFE30-\uFE4F\uFF00-\uFF60\uFFE0-\uFFE6]|[\u{1F000}-\u{1FAFF}]/u;
+const COVER_SIZES_PT = [96, 84, 72, 60, 48];
+const COVER_BLOCK_IN = 5.97;
+const COVER_BELOW_BLOCK_IN = 3.48;
+const COVER_BLOCK_MIN_IN = 1.5;
+const SWISS_LETTER_BOX = { contentWIn: 7, contentHIn: 9.45 };
+
+/** Estimated width of one glyph in ems of bold Helvetica with the cover's tight tracking. */
+function glyphEm(ch: string): number {
+ if (WIDE_CHAR.test(ch)) return 1;
+ if (ch === " ") return 0.28;
+ if (/[A-Z0-9]/.test(ch)) return 0.66;
+ if (/[iljtf.,:;'!|]/.test(ch)) return 0.3;
+ if (/[mwMW]/.test(ch)) return 0.85;
+ return 0.55;
+}
+
+/** Lines a title takes at a size, or Infinity when one unbreakable word is wider than the block. */
+function coverLines(title: string, sizePt: number, widthPt: number): number {
+ let lines = 1;
+ let x = 0;
+ for (const word of title.trim().split(/\s+/)) {
+ const glyphs = Array.from(word);
+ const wide = glyphs.some((g) => WIDE_CHAR.test(g));
+ if (wide) {
+ for (const g of glyphs) {
+ const w = glyphEm(g) * sizePt;
+ if (x + w > widthPt) { lines++; x = 0; }
+ x += w;
+ }
+ x += glyphEm(" ") * sizePt;
+ continue;
+ }
+ const w = glyphs.reduce((s, g) => s + glyphEm(g), 0) * sizePt;
+ if (w > widthPt) return Infinity;
+ if (x > 0 && x + w > widthPt) { lines++; x = 0; }
+ x += w + glyphEm(" ") * sizePt;
+ }
+ return lines;
+}
+
+/**
+ * Size the swiss cover title so the black block, the red bar and the meta
+ * always fit on page 1 of the actual page box (paper size less margins): the
+ * largest size whose estimated lines fit the block, and a top padding that
+ * shrinks as the title grows. The 48pt floor still wraps anything longer
+ * (overflow-wrap: anywhere), it never clips. The default box is swiss Letter.
+ */
+export function swissCoverTitle(
+ title: string,
+ box: { contentWIn: number; contentHIn: number } = SWISS_LETTER_BOX,
+): { fontPt: number; padTopIn: number } {
+ const widthPt = box.contentWIn * 72 - 58;
+ const blockIn = Math.max(COVER_BLOCK_MIN_IN, Math.min(COVER_BLOCK_IN, box.contentHIn - COVER_BELOW_BLOCK_IN));
+ const maxTextPt = blockIn * 72 - 56;
+ const fontPt = COVER_SIZES_PT.find((s) => coverLines(title, s, widthPt) * s * 0.92 <= maxTextPt)
+ ?? COVER_SIZES_PT[COVER_SIZES_PT.length - 1];
+ const lines = Math.min(coverLines(title, fontPt, widthPt), Math.max(1, Math.floor(maxTextPt / (fontPt * 0.92))));
+ const textIn = (lines * fontPt * 0.92) / 72;
+ const padTopIn = Math.round(Math.min(3.2, Math.max(0.4, blockIn - textIn - 0.31)) * 100) / 100;
+ return { fontPt, padTopIn };
+}
diff --git a/make-pdf/src/types.ts b/make-pdf/src/types.ts
index 84d82a434..c40a21c2a 100644
--- a/make-pdf/src/types.ts
+++ b/make-pdf/src/types.ts
@@ -5,6 +5,8 @@
*/
export type PageSize = "letter" | "a4" | "legal" | "tabloid";
+export type { Style } from "./style-swiss";
+import type { Style } from "./style-swiss";
export type FontMode = "sans"; // v1: Helvetica only. Future: "serif" | "custom".
/**
@@ -23,6 +25,9 @@ export interface GenerateOptions {
// docx — content-fidelity Word document (diagrams embedded as PNG)
to?: OutputFormat;
+ // Look: "swiss" (default, bold Swiss-poster layout) | "plain" (the look before it)
+ style?: Style;
+
// Page layout
margins?: string; // "1in" | "72pt" | "25mm" | "2.54cm"
marginTop?: string;
@@ -70,6 +75,7 @@ export interface PreviewOptions {
quiet?: boolean;
verbose?: boolean;
// Same render flags as generate so preview matches output
+ style?: Style;
cover?: boolean;
toc?: boolean;
watermark?: string;
diff --git a/make-pdf/test/cli-exit-codes.test.ts b/make-pdf/test/cli-exit-codes.test.ts
index b9160c79f..2b76c7ca4 100644
--- a/make-pdf/test/cli-exit-codes.test.ts
+++ b/make-pdf/test/cli-exit-codes.test.ts
@@ -282,6 +282,19 @@ describe("cli.ts exit codes end to end (no stubs, no browser touched)", () => {
expect(badTo.stdout).toBe("");
});
+ test("--style: an unknown or missing value exits 1; the value is case-insensitive", () => {
+ const bad = runCli(["generate", inputMd, "--style", "bogus"]);
+ expect(bad.code).toBe(ExitCode.BadArgs);
+ expect(bad.stderr).toContain("$P generate: invalid --style (got 'bogus'). Expected swiss or plain, for example --style plain.");
+ const bare = runCli(["generate", inputMd, "--style"]);
+ expect(bare.code).toBe(ExitCode.BadArgs);
+ expect(bare.stderr).toContain("invalid --style (got no value)");
+ const out = path.join(tmp, "style-upper.html");
+ const upper = runCli(["generate", inputMd, out, "--to", "html", "--style", "PLAIN", "--quiet"]);
+ expect(upper.code).toBe(ExitCode.Success);
+ expect(fs.readFileSync(out, "utf8")).not.toContain("--swiss-field");
+ });
+
test("exit 0 paths: no arguments prints usage (stderr); version prints VERSION on stdout only", () => {
const usage = runCli([]);
expect(usage.code).toBe(ExitCode.Success);
diff --git a/make-pdf/test/e2e/combined-gate.test.ts b/make-pdf/test/e2e/combined-gate.test.ts
index 43634b3f0..4cca3930c 100644
--- a/make-pdf/test/e2e/combined-gate.test.ts
+++ b/make-pdf/test/e2e/combined-gate.test.ts
@@ -42,11 +42,14 @@ function prerequisitesAvailable(): { ok: true } | { ok: false; reason: string }
describe("combined-features copy-paste gate", () => {
const avail = prerequisitesAvailable();
- test.skipIf(!avail.ok)("fixture PDF extracts cleanly through pdftotext", () => {
+ // Both looks extract the same text in the same order: swiss moves sub-headings
+ // into a left field and paints bars, and copy-paste must not notice.
+ for (const style of ["swiss", "plain"]) {
+ test.skipIf(!avail.ok)(`${style}: fixture PDF extracts cleanly through pdftotext`, () => {
if (!avail.ok) return; // satisfies the type checker
- const outputPdf = path.join(os.tmpdir(), `make-pdf-combined-gate-${process.pid}.pdf`);
+ const outputPdf = path.join(os.tmpdir(), `make-pdf-combined-gate-${style}-${process.pid}.pdf`);
try {
- execFileSync(PDF_BIN, ["generate", FIXTURE, outputPdf, "--quiet"], {
+ execFileSync(PDF_BIN, ["generate", FIXTURE, outputPdf, "--quiet", "--style", style], {
encoding: "utf8",
timeout: 60_000,
stdio: ["ignore", "pipe", "pipe"],
@@ -65,6 +68,7 @@ describe("combined-features copy-paste gate", () => {
try { fs.unlinkSync(outputPdf); } catch { /* ignore */ }
}
}, 60000);
+ }
if (!avail.ok) {
test("prerequisites check", () => {
diff --git a/make-pdf/test/e2e/diagram-gate.test.ts b/make-pdf/test/e2e/diagram-gate.test.ts
index 84bd7440e..08cbb40c3 100644
--- a/make-pdf/test/e2e/diagram-gate.test.ts
+++ b/make-pdf/test/e2e/diagram-gate.test.ts
@@ -92,10 +92,10 @@ describe("diagram render gate", () => {
}
expect(fs.existsSync(outputPdf)).toBe(true);
- // 0. Print-resolution downscale fired on the 4200px noise photo — this
+ // 0. Print-resolution downscale fired on the 4800px noise photo (above 2 × the 7in swiss content width × 300dpi) — this
// is the only live coverage of __downscaleRaster AND the served-dir
// payload transport (the data URI is far too big for argv).
- expect(stderr).toMatch(/downscaled huge-noise\.png 4200px → \d+px/);
+ expect(stderr).toMatch(/downscaled huge-noise\.png 4800px → \d+px/);
const pdftotext = resolvePopplerTool("pdftotext")!;
const text = execFileSync(pdftotext, [outputPdf, "-"], { encoding: "utf8", timeout: CHILD_TIMEOUT_MS });
diff --git a/make-pdf/test/e2e/landscape-gate.test.ts b/make-pdf/test/e2e/landscape-gate.test.ts
index d5224a6d3..57417673f 100644
--- a/make-pdf/test/e2e/landscape-gate.test.ts
+++ b/make-pdf/test/e2e/landscape-gate.test.ts
@@ -75,12 +75,13 @@ function generate(args: string[], outputPdf: string): void {
describe("landscape promotion gate", () => {
const avail = prerequisitesAvailable();
- test.skipIf(!avail.ok)("exactly the promoted blocks get landscape pages", () => {
+ for (const style of ["swiss", "plain"]) {
+ test.skipIf(!avail.ok)(`${style}: exactly the promoted blocks get landscape pages`, () => {
if (!avail.ok) return;
const workDir = fs.mkdtempSync("/tmp/make-pdf-landscape-gate-");
const outputPdf = path.join(workDir, "out.pdf");
try {
- generate([], outputPdf);
+ generate(["--style", style], outputPdf);
const boxes = pageBoxes(outputPdf);
const landscape = boxes.filter(isLandscape);
const portrait = boxes.filter((b) => !isLandscape(b));
@@ -113,6 +114,7 @@ describe("landscape promotion gate", () => {
try { fs.rmSync(workDir, { recursive: true, force: true }); } catch { /* ignore */ }
}
}, 120000);
+ }
test.skipIf(!avail.ok)("--toc combo: TOC renders and landscape promotion survives", () => {
if (!avail.ok) return;
diff --git a/make-pdf/test/e2e/swiss-gate.test.ts b/make-pdf/test/e2e/swiss-gate.test.ts
new file mode 100644
index 000000000..978a9f478
--- /dev/null
+++ b/make-pdf/test/e2e/swiss-gate.test.ts
@@ -0,0 +1,198 @@
+/**
+ * swiss layout gate: the default look's layout promises, checked on real
+ * PDFs through pdftotext -bbox-layout and one pixel sample.
+ *
+ * - the text column holds a readable line (median 55-75 characters on
+ * Letter and A4, at most 75 on tabloid, where the column is capped);
+ * - a black bar is never the last text on its page: the paragraph after it
+ * starts on the same page with at least three of its lines there;
+ * - full-width blocks (tables, code) start at the content's left edge, and
+ * left-field sub-headings stay inside the field and above the next bar;
+ * - copy-paste text keeps each sub-heading before its paragraph;
+ * - the bars really print dark;
+ * - a 90-character title keeps the whole cover on page 1.
+ */
+
+import { describe, expect, test } from "bun:test";
+import { execFileSync } from "node:child_process";
+import * as fs from "node:fs";
+import * as os from "node:os";
+import * as path from "node:path";
+
+import { resolvePopplerTool, resolvePdftotext } from "../../src/pdftotext";
+import { SWISS_FIELD_IN, SWISS_MARGINS } from "../../src/style-swiss";
+import { browserAvailable, NO_BROWSER_REASON } from "../../../test/helpers/browser-available";
+
+const FIXTURE = path.resolve(__dirname, "../fixtures/swiss-gate.md");
+const ROOT = path.resolve(__dirname, "../../..");
+const PDF_BIN = path.join(ROOT, "make-pdf/dist/pdf");
+const CHILD_TIMEOUT_MS = 60_000;
+const BARS = ["Alpha", "Beta", "Gamma", "Delta", "Epsilon", "Zeta", "Eta", "Theta"].map((w) => `${w} bar heading`);
+
+const LEFT_PT = parseFloat(SWISS_MARGINS.left) * 72;
+const COLUMN_PT = LEFT_PT + SWISS_FIELD_IN * 72;
+
+function prerequisitesAvailable(): { ok: true } | { ok: false; reason: string } {
+ if (!fs.existsSync(PDF_BIN)) return { ok: false, reason: `make-pdf binary missing (${PDF_BIN}). Run bun run build.` };
+ if (!browserAvailable()) return { ok: false, reason: NO_BROWSER_REASON };
+ try { resolvePdftotext(); } catch (err: any) { return { ok: false, reason: err.message }; }
+ if (!resolvePopplerTool("pdftoppm")) return { ok: false, reason: "pdftoppm not found." };
+ return { ok: true };
+}
+
+interface Line { page: number; pageH: number; x0: number; x1: number; y0: number; y1: number; text: string }
+
+function lines(pdf: string): Line[] {
+ const xml = execFileSync(resolvePopplerTool("pdftotext")!, ["-bbox-layout", pdf, "-"], { encoding: "utf8", timeout: CHILD_TIMEOUT_MS });
+ const out: Line[] = [];
+ let page = 0;
+ let pageH = 0;
+ for (const chunk of xml.split(/(?=<page )/)) {
+ const ph = chunk.match(/^<page width="[\d.]+" height="([\d.]+)"/);
+ if (!ph) continue;
+ page++;
+ pageH = parseFloat(ph[1]);
+ for (const m of chunk.matchAll(/<line xMin="([\d.]+)" yMin="([\d.]+)" xMax="([\d.]+)" yMax="([\d.]+)">([\s\S]*?)<\/line>/g)) {
+ const words = [...m[5].matchAll(/<word[^>]*>([^<]*)<\/word>/g)].map((w) => w[1]);
+ out.push({ page, pageH, x0: +m[1], y0: +m[2], x1: +m[3], y1: +m[4], text: words.join(" ") });
+ }
+ }
+ return out;
+}
+
+/** Body lines: inside the page's type area (no running header or footer). */
+const body = (ls: Line[]) => ls.filter((l) => l.y0 > 0.7 * 72 - 1 && l.y1 < l.pageH - 0.85 * 72 + 1);
+
+function render(dir: string, name: string, args: string[]): string {
+ const out = path.join(dir, `${name}.pdf`);
+ execFileSync(PDF_BIN, ["generate", FIXTURE, out, "--quiet", ...args], { encoding: "utf8", timeout: CHILD_TIMEOUT_MS, stdio: ["ignore", "pipe", "pipe"] });
+ return out;
+}
+
+function columnMedian(ls: Line[]): { median: number; n: number } {
+ const col = body(ls).filter((l) => Math.abs(l.x0 - COLUMN_PT) < 3 && l.text.split(" ").length >= 4).map((l) => l.text.length).sort((a, b) => a - b);
+ return { median: col[Math.floor(col.length / 2)] ?? 0, n: col.length };
+}
+
+describe("swiss layout gate", () => {
+ const avail = prerequisitesAvailable();
+ let dir = "";
+
+ test.skipIf(!avail.ok)("Letter: measure, bars, full-width blocks, field headings, copy order, dark bars", () => {
+ if (!avail.ok) return;
+ dir = fs.mkdtempSync(path.join(os.tmpdir(), "make-pdf-swiss-gate-"));
+ const pdf = render(dir, "letter", []);
+ const ls = lines(pdf);
+ const all = body(ls);
+
+ const { median, n } = columnMedian(ls);
+ expect(n).toBeGreaterThan(20);
+ expect(median).toBeGreaterThanOrEqual(55);
+ expect(median).toBeLessThanOrEqual(75);
+
+ for (const bar of BARS) {
+ const b = all.find((l) => l.text === bar);
+ expect({ bar, found: !!b }).toEqual({ bar, found: true });
+ const after = all.filter((l) => l.page === b!.page && l.y0 > b!.y1);
+ expect({ bar, linesAfterOnPage: Math.min(after.length, 3) }).toEqual({ bar, linesAfterOnPage: 3 });
+ expect(b!.x0).toBeGreaterThan(COLUMN_PT - 3);
+ }
+
+ const cell = all.find((l) => l.text.includes("tablecellalpha"))!;
+ const code = all.find((l) => l.text.includes("codelinealpha"))!;
+ expect(cell.x0).toBeLessThan(LEFT_PT + 20);
+ expect(code.x0).toBeLessThan(LEFT_PT + 20);
+
+ for (const h of ["Table follows", "Code follows", "First of two", "Second of two"]) {
+ const l = all.find((x) => x.text === h)!;
+ expect({ h, inField: l.x0 < LEFT_PT + 3 && l.x1 < COLUMN_PT }).toEqual({ h, inField: true });
+ }
+ const longH = all.filter((l) => l.x0 < LEFT_PT + 3 && l.x1 < COLUMN_PT && /narrow field|several lines|long left-field|wraps over/.test(l.text));
+ expect(longH.length).toBeGreaterThanOrEqual(2);
+ const beta = all.find((l) => l.text === "Beta bar heading")!;
+ const lastH = longH[longH.length - 1];
+ expect(lastH.page < beta.page || lastH.y1 < beta.y0).toBe(true);
+ const first = all.find((x) => x.text === "First of two")!;
+ const second = all.find((x) => x.text === "Second of two")!;
+ expect(second.y0).toBeGreaterThanOrEqual(first.y1);
+
+ const text = execFileSync(resolvePopplerTool("pdftotext")!, [pdf, "-"], { encoding: "utf8", timeout: CHILD_TIMEOUT_MS });
+ expect(text.indexOf("Table follows")).toBeLessThan(text.indexOf("tablecellalpha"));
+ expect(text.indexOf("Code follows")).toBeLessThan(text.indexOf("codelinealpha"));
+ expect(text.indexOf("Second of two")).toBeLessThan(text.indexOf("Sentence 1", text.indexOf("Second of two")));
+
+ const alpha = all.find((l) => l.text === "Alpha bar heading")!;
+ const prefix = path.join(dir, "bar");
+ execFileSync(resolvePopplerTool("pdftoppm")!, ["-r", "36", "-gray", "-f", String(alpha.page), "-l", String(alpha.page), "-singlefile", pdf, prefix], { timeout: CHILD_TIMEOUT_MS });
+ const pgm = fs.readFileSync(`${prefix}.pgm`);
+ const header = pgm.toString("latin1", 0, 64).match(/^P5\s+(\d+)\s+(\d+)\s+255\s/)!;
+ const w = +header[1];
+ const start = header[0].length;
+ const s = 36 / 72;
+ const y = Math.round(((alpha.y0 + alpha.y1) / 2) * s);
+ let dark = 0;
+ let total = 0;
+ for (let x = Math.round((LEFT_PT + 6) * s); x < Math.round((COLUMN_PT - 10) * s); x++) {
+ total++;
+ if (pgm[start + y * w + x] < 60) dark++;
+ }
+ expect(dark / total).toBeGreaterThan(0.9);
+ }, 120000);
+
+ for (const [size, args, lo, hi] of [["a4", ["--page-size", "a4"], 55, 75], ["tabloid", ["--page-size", "tabloid"], 0, 75]] as const) {
+ test.skipIf(!avail.ok)(`${size}: the text column holds a readable line`, () => {
+ if (!avail.ok) return;
+ const d = fs.mkdtempSync(path.join(os.tmpdir(), "make-pdf-swiss-gate-"));
+ try {
+ const { median, n } = columnMedian(lines(render(d, size, [...args])));
+ expect(n).toBeGreaterThan(20);
+ expect(median).toBeGreaterThanOrEqual(lo);
+ expect(median).toBeLessThanOrEqual(hi);
+ } finally {
+ fs.rmSync(d, { recursive: true, force: true });
+ }
+ }, 120000);
+ }
+
+ test.skipIf(!avail.ok)("a 90-character title keeps the whole cover on page 1", () => {
+ if (!avail.ok) return;
+ const d = fs.mkdtempSync(path.join(os.tmpdir(), "make-pdf-swiss-gate-"));
+ try {
+ const title = "The gstack factory: how crews plan, build, review and ship software with agents, end to end";
+ const pdf = render(d, "cover", ["--cover", "--title", title, "--author", "Gate Author", "--date", "2026-11-25"]);
+ const page = (p: number) => execFileSync(resolvePopplerTool("pdftotext")!, ["-f", String(p), "-l", String(p), pdf, "-"], { encoding: "utf8", timeout: CHILD_TIMEOUT_MS });
+ const one = page(1).replace(/\s+/g, " ");
+ expect(one).toContain("end to end");
+ expect(one).toContain("Gate Author");
+ expect(one).toContain("2026-11-25");
+ expect(page(2)).not.toContain("Gate Author");
+ } finally {
+ fs.rmSync(d, { recursive: true, force: true });
+ }
+ }, 120000);
+
+ test.skipIf(!avail.ok)("the cover fits page 1 of a smaller page box (--margins 2in)", () => {
+ if (!avail.ok) return;
+ const d = fs.mkdtempSync(path.join(os.tmpdir(), "make-pdf-swiss-gate-"));
+ try {
+ const pdf = render(d, "cover-2in", ["--cover", "--title", "Infrastructure Status for North America", "--author", "Gate Author", "--date", "2026-11-25", "--margins", "2in"]);
+ const page = (p: number) => execFileSync(resolvePopplerTool("pdftotext")!, ["-f", String(p), "-l", String(p), pdf, "-"], { encoding: "utf8", timeout: CHILD_TIMEOUT_MS });
+ const one = page(1).replace(/\s+/g, " ");
+ expect(one).toContain("Gate Author");
+ expect(one).toContain("2026-11-25");
+ expect(page(2)).not.toContain("Gate Author");
+ } finally {
+ fs.rmSync(d, { recursive: true, force: true });
+ }
+ }, 120000);
+
+ test("cleanup", () => {
+ if (dir) fs.rmSync(dir, { recursive: true, force: true });
+ });
+
+ if (!avail.ok) {
+ test("prerequisites check", () => {
+ console.warn(`[skip] ${avail.reason}`);
+ });
+ }
+});
diff --git a/make-pdf/test/e2e/toc-gate.test.ts b/make-pdf/test/e2e/toc-gate.test.ts
index 74f4127ee..6956cb14b 100644
--- a/make-pdf/test/e2e/toc-gate.test.ts
+++ b/make-pdf/test/e2e/toc-gate.test.ts
@@ -113,7 +113,11 @@ function checkToc(pdf: string): void {
describe("TOC page-number gate (#2903)", () => {
const avail = prerequisitesAvailable();
- for (const variant of [{ name: "cover + toc", args: ["--cover", "--toc"] }, { name: "toc only", args: ["--toc"] }]) {
+ for (const variant of [
+ { name: "cover + toc", args: ["--cover", "--toc"] },
+ { name: "toc only", args: ["--toc"] },
+ { name: "plain cover + toc", args: ["--cover", "--toc", "--style", "plain"] },
+ ]) {
test.skipIf(!avail.ok)(`${variant.name}: every TOC cell holds its heading's printed page and every link lands there`, () => {
if (!avail.ok) return;
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "make-pdf-toc-gate-"));
diff --git a/make-pdf/test/fixtures/diagram-assets/huge-noise.png b/make-pdf/test/fixtures/diagram-assets/huge-noise.png
index 73ebd53ac..cd43cd7a0 100644
Binary files a/make-pdf/test/fixtures/diagram-assets/huge-noise.png and b/make-pdf/test/fixtures/diagram-assets/huge-noise.png differ
diff --git a/make-pdf/test/fixtures/print-css-plain/default.css b/make-pdf/test/fixtures/print-css-plain/default.css
new file mode 100644
index 000000000..400c00b1e
--- /dev/null
+++ b/make-pdf/test/fixtures/print-css-plain/default.css
@@ -0,0 +1,134 @@
+@page {
+ size: letter;
+ margin: 1in;
+ @bottom-center { content: counter(page) " of " counter(pages); font-family: Helvetica, "Liberation Sans", Arial, sans-serif; font-size: 9pt; color: #666; }
+ @bottom-right { content: "CONFIDENTIAL"; font-family: Helvetica, "Liberation Sans", Arial, sans-serif; font-size: 8pt; color: #aaa; letter-spacing: 0.05em; }
+}
+@page :first {
+ @top-center { content: none; }
+ @bottom-center { content: none; }
+ @bottom-right { content: none; }
+}
+@page wide {
+ size: letter landscape;
+ margin: 1in;
+}
+.page-wide {
+ page: wide;
+ text-align: center;
+}
+.page-wide img, .page-wide svg { width: 100%; height: auto; max-width: none; }
+.page-wide figure.diagram > svg { max-width: none; }
+
+html { lang: en; }
+img { max-width: 100%; height: auto; }
+body {
+ font-family: Helvetica, "Liberation Sans", Arial, "PingFang SC", "Heiti SC", "Noto Sans CJK SC", "Source Han Sans SC", "Microsoft YaHei", "Hiragino Kaku Gothic ProN", "Noto Sans CJK JP", "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
+ font-size: 12pt;
+ line-height: 1.5;
+ color: #111;
+ background: white;
+ hyphens: manual;
+ font-variant-ligatures: common-ligatures;
+ font-kerning: normal;
+ text-rendering: geometricPrecision;
+ margin: 0;
+ padding: 0;
+}
+
+.chapter { break-before: page; page-break-before: always; }
+.chapter:first-of-type { break-before: auto; page-break-before: auto; }
+h1 {
+ font-size: 26pt;
+ line-height: 1.2;
+ font-weight: 700;
+ letter-spacing: -0.01em;
+ margin: 0 0 0.25in;
+ break-after: avoid;
+ page-break-after: avoid;
+}
+h2 { font-size: 18pt; line-height: 1.3; font-weight: 700; margin: 26pt 0 8pt; break-after: avoid; page-break-after: avoid; }
+h3 { font-size: 13.5pt; line-height: 1.4; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: #333; margin: 20pt 0 5pt; break-after: avoid; page-break-after: avoid; }
+h4 { font-size: 12pt; font-weight: 700; margin: 14pt 0 5pt; break-after: avoid; page-break-after: avoid; }
+
+p {
+ margin: 0 0 12pt;
+ text-align: left;
+ widows: 3;
+ orphans: 3;
+}
+p:first-child { margin-top: 0; }
+p.lead { font-size: 14pt; line-height: 1.45; color: #222; margin: 0 0 18pt; }
+
+a {
+ color: #0055cc;
+ text-decoration: underline;
+ text-decoration-thickness: 0.5pt;
+ text-underline-offset: 1.5pt;
+}
+strong { font-weight: 700; }
+em { font-style: italic; }
+
+code {
+ font-family: "SF Mono", Menlo, Consolas, monospace;
+ font-size: 10.5pt;
+ background: #f4f4f4;
+ padding: 1pt 3pt;
+ border-radius: 2pt;
+ border: 0.5pt solid #e4e4e4;
+}
+pre {
+ font-family: "SF Mono", Menlo, Consolas, monospace;
+ font-size: 10pt;
+ line-height: 1.4;
+ background: #f7f7f5;
+ padding: 10pt 12pt;
+ border: 0.5pt solid #e0e0e0;
+ border-radius: 3pt;
+ margin: 12pt 0;
+ overflow: hidden;
+ white-space: pre-wrap;
+}
+pre code { background: none; border: 0; padding: 0; font-size: inherit; }
+.hljs-keyword { color: #8b0000; font-weight: 500; }
+.hljs-string { color: #0d6608; }
+.hljs-comment { color: #888; font-style: italic; }
+.hljs-function, .hljs-title { color: #0044aa; }
+.hljs-number { color: #a64d00; }
+
+blockquote {
+ margin: 12pt 0;
+ padding: 0 0 0 18pt;
+ border-left: 2pt solid #111;
+ color: #333;
+ font-size: 12pt;
+ line-height: 1.5;
+}
+blockquote p { margin-bottom: 6pt; text-align: left; }
+blockquote cite { display: block; margin-top: 6pt; font-style: normal; font-size: 10pt; color: #666; letter-spacing: 0.02em; }
+blockquote cite::before { content: "— "; }
+
+figure { margin: 12pt 0; }
+figure img { display: block; max-width: 100%; height: auto; }
+figcaption { font-size: 10pt; color: #666; margin-top: 6pt; font-style: italic; }
+figure.diagram { break-inside: avoid; text-align: center; }
+figure.diagram > svg { max-width: 100%; height: auto; }
+figure.diagram .diagram-caption { text-align: center; }
+figure.diagram-error { border: 1.5pt solid #b00020; padding: 8pt 10pt; text-align: left; }
+figure.diagram-error .diagram-error-title { font-weight: 700; color: #b00020; font-style: normal; margin: 0 0 6pt; }
+figure.diagram-error .diagram-error-detail { font-size: 8.5pt; white-space: pre-wrap; margin: 0; }
+.image-missing { display: inline-block; border: 1pt dashed #b00020; color: #b00020; padding: 4pt 8pt; font-size: 9pt; }
+
+table { width: 100%; border-collapse: collapse; margin: 12pt 0; font-size: 11pt; }
+th, td { border-bottom: 0.5pt solid #ccc; padding: 5pt 8pt; text-align: left; vertical-align: top; }
+th { font-weight: 700; border-bottom: 1pt solid #111; background: transparent; }
+
+ul, ol { margin: 0 0 12pt 0; padding-left: 20pt; }
+li { margin-bottom: 3pt; line-height: 1.45; }
+li > ul, li > ol { margin-top: 3pt; margin-bottom: 0; }
+
+.footnote-ref { font-size: 0.75em; vertical-align: super; line-height: 0; text-decoration: none; color: #0055cc; }
+.footnotes { margin-top: 24pt; padding-top: 12pt; border-top: 0.5pt solid #ccc; font-size: 10pt; line-height: 1.4; }
+.footnotes ol { padding-left: 18pt; }
+
+blockquote, pre, code, table, figure, li, .keep-together { break-inside: avoid; page-break-inside: avoid; }
\ No newline at end of file
diff --git a/make-pdf/test/fixtures/print-css-plain/flags.css b/make-pdf/test/fixtures/print-css-plain/flags.css
new file mode 100644
index 000000000..ddf0e952a
--- /dev/null
+++ b/make-pdf/test/fixtures/print-css-plain/flags.css
@@ -0,0 +1,217 @@
+@page {
+ size: a4;
+ margin: 72pt;
+ @top-center { content: "Title \"q\""; font-family: Helvetica, "Liberation Sans", Arial, "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif; font-size: 9pt; color: #666; }
+}
+@page :first {
+ @top-center { content: none; }
+ @bottom-center { content: none; }
+ @bottom-right { content: none; }
+}
+@page wide {
+ size: a4 landscape;
+ margin: 72pt;
+}
+.page-wide {
+ page: wide;
+ text-align: center;
+}
+.page-wide img, .page-wide svg { width: 100%; height: auto; max-width: none; }
+.page-wide figure.diagram > svg { max-width: none; }
+
+html { lang: en; }
+img { max-width: 100%; height: auto; }
+body {
+ font-family: Helvetica, "Liberation Sans", Arial, "PingFang SC", "Heiti SC", "Noto Sans CJK SC", "Source Han Sans SC", "Microsoft YaHei", "Hiragino Kaku Gothic ProN", "Noto Sans CJK JP", "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
+ font-size: 12pt;
+ line-height: 1.5;
+ color: #111;
+ background: white;
+ hyphens: manual;
+ font-variant-ligatures: common-ligatures;
+ font-kerning: normal;
+ text-rendering: geometricPrecision;
+ margin: 0;
+ padding: 0;
+}
+
+.cover {
+ page: first;
+ page-break-after: always;
+ break-after: page;
+ text-align: left;
+ padding-top: 1.4in;
+}
+.cover .eyebrow {
+ font-size: 11pt;
+ letter-spacing: 0.2em;
+ text-transform: uppercase;
+ color: #666;
+ margin: 0 0 36pt;
+}
+.cover h1.cover-title {
+ font-size: 56pt;
+ line-height: 1.08;
+ font-weight: 700;
+ letter-spacing: -0.02em;
+ margin: 0 0 24pt;
+ max-width: 6in;
+ text-align: left;
+}
+.cover .cover-subtitle {
+ font-size: 18pt;
+ line-height: 1.35;
+ font-weight: 400;
+ color: #333;
+ margin: 0 0 36pt;
+ max-width: 5.5in;
+ text-align: left;
+}
+.cover hr.rule {
+ width: 2.5in;
+ height: 0;
+ border: 0;
+ border-top: 1.5px solid #111;
+ margin: 0 0 24pt 0;
+}
+.cover .cover-meta { font-size: 13pt; line-height: 1.6; color: #333; text-align: left; }
+.cover .cover-meta strong { font-weight: 700; }
+
+.toc { page-break-after: always; break-after: page; }
+.toc h2 {
+ font-size: 16pt;
+ text-transform: uppercase;
+ letter-spacing: 0.15em;
+ color: #444;
+ font-weight: 700;
+ margin: 0 0 0.4in;
+}
+.toc ol {
+ list-style: none;
+ padding: 0;
+ margin: 0;
+}
+.toc li {
+ display: flex;
+ align-items: baseline;
+ gap: 0.25in;
+ font-size: 12pt;
+ line-height: 1.7;
+ padding: 3pt 0;
+}
+.toc li .toc-title { flex: 0 0 auto; }
+.toc li .toc-dots { flex: 1 1 auto; border-bottom: 1px dotted #aaa; margin: 0 6pt; transform: translateY(-4pt); }
+.toc li .toc-page { flex: 0 0 auto; color: #666; font-variant-numeric: tabular-nums; }
+.toc li.level-2 { padding-left: 0.35in; font-size: 11pt; }
+.toc li a { color: inherit; text-decoration: none; }
+
+/* chapter breaks disabled */
+h1 {
+ font-size: 26pt;
+ line-height: 1.2;
+ font-weight: 700;
+ letter-spacing: -0.01em;
+ margin: 0 0 0.25in;
+ break-after: avoid;
+ page-break-after: avoid;
+}
+h2 { font-size: 18pt; line-height: 1.3; font-weight: 700; margin: 26pt 0 8pt; break-after: avoid; page-break-after: avoid; }
+h3 { font-size: 13.5pt; line-height: 1.4; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: #333; margin: 20pt 0 5pt; break-after: avoid; page-break-after: avoid; }
+h4 { font-size: 12pt; font-weight: 700; margin: 14pt 0 5pt; break-after: avoid; page-break-after: avoid; }
+
+p {
+ margin: 0 0 12pt;
+ text-align: left;
+ widows: 3;
+ orphans: 3;
+}
+p:first-child { margin-top: 0; }
+p.lead { font-size: 14pt; line-height: 1.45; color: #222; margin: 0 0 18pt; }
+
+a {
+ color: #0055cc;
+ text-decoration: underline;
+ text-decoration-thickness: 0.5pt;
+ text-underline-offset: 1.5pt;
+}
+strong { font-weight: 700; }
+em { font-style: italic; }
+
+code {
+ font-family: "SF Mono", Menlo, Consolas, monospace;
+ font-size: 10.5pt;
+ background: #f4f4f4;
+ padding: 1pt 3pt;
+ border-radius: 2pt;
+ border: 0.5pt solid #e4e4e4;
+}
+pre {
+ font-family: "SF Mono", Menlo, Consolas, monospace;
+ font-size: 10pt;
+ line-height: 1.4;
+ background: #f7f7f5;
+ padding: 10pt 12pt;
+ border: 0.5pt solid #e0e0e0;
+ border-radius: 3pt;
+ margin: 12pt 0;
+ overflow: hidden;
+ white-space: pre-wrap;
+}
+pre code { background: none; border: 0; padding: 0; font-size: inherit; }
+.hljs-keyword { color: #8b0000; font-weight: 500; }
+.hljs-string { color: #0d6608; }
+.hljs-comment { color: #888; font-style: italic; }
+.hljs-function, .hljs-title { color: #0044aa; }
+.hljs-number { color: #a64d00; }
+
+blockquote {
+ margin: 12pt 0;
+ padding: 0 0 0 18pt;
+ border-left: 2pt solid #111;
+ color: #333;
+ font-size: 12pt;
+ line-height: 1.5;
+}
+blockquote p { margin-bottom: 6pt; text-align: left; }
+blockquote cite { display: block; margin-top: 6pt; font-style: normal; font-size: 10pt; color: #666; letter-spacing: 0.02em; }
+blockquote cite::before { content: "— "; }
+
+figure { margin: 12pt 0; }
+figure img { display: block; max-width: 100%; height: auto; }
+figcaption { font-size: 10pt; color: #666; margin-top: 6pt; font-style: italic; }
+figure.diagram { break-inside: avoid; text-align: center; }
+figure.diagram > svg { max-width: 100%; height: auto; }
+figure.diagram .diagram-caption { text-align: center; }
+figure.diagram-error { border: 1.5pt solid #b00020; padding: 8pt 10pt; text-align: left; }
+figure.diagram-error .diagram-error-title { font-weight: 700; color: #b00020; font-style: normal; margin: 0 0 6pt; }
+figure.diagram-error .diagram-error-detail { font-size: 8.5pt; white-space: pre-wrap; margin: 0; }
+.image-missing { display: inline-block; border: 1pt dashed #b00020; color: #b00020; padding: 4pt 8pt; font-size: 9pt; }
+
+table { width: 100%; border-collapse: collapse; margin: 12pt 0; font-size: 11pt; }
+th, td { border-bottom: 0.5pt solid #ccc; padding: 5pt 8pt; text-align: left; vertical-align: top; }
+th { font-weight: 700; border-bottom: 1pt solid #111; background: transparent; }
+
+ul, ol { margin: 0 0 12pt 0; padding-left: 20pt; }
+li { margin-bottom: 3pt; line-height: 1.45; }
+li > ul, li > ol { margin-top: 3pt; margin-bottom: 0; }
+
+.footnote-ref { font-size: 0.75em; vertical-align: super; line-height: 0; text-decoration: none; color: #0055cc; }
+.footnotes { margin-top: 24pt; padding-top: 12pt; border-top: 0.5pt solid #ccc; font-size: 10pt; line-height: 1.4; }
+.footnotes ol { padding-left: 18pt; }
+
+.watermark {
+ position: fixed;
+ top: 50%;
+ left: 50%;
+ transform: translate(-50%, -50%) rotate(-30deg);
+ font-size: 140pt;
+ font-weight: 700;
+ color: rgba(200, 0, 0, 0.06);
+ letter-spacing: 0.08em;
+ pointer-events: none;
+ z-index: 9999;
+ user-select: none;
+ white-space: nowrap;
+}
+
+blockquote, pre, code, table, figure, li, .keep-together { break-inside: avoid; page-break-inside: avoid; }
\ No newline at end of file
diff --git a/make-pdf/test/fixtures/print-css-plain/screen.css b/make-pdf/test/fixtures/print-css-plain/screen.css
new file mode 100644
index 000000000..83cc0ef3c
--- /dev/null
+++ b/make-pdf/test/fixtures/print-css-plain/screen.css
@@ -0,0 +1,7 @@
+@media screen {
+ body { max-width: 42em; margin: 0 auto; padding: 2.5em 1.5em; }
+ .chapter { break-before: auto; }
+ .watermark { display: none; }
+ figure.diagram { overflow-x: auto; }
+ .toc li .toc-page, .toc li .toc-dots { display: none; }
+}
\ No newline at end of file
diff --git a/make-pdf/test/fixtures/swiss-gate.md b/make-pdf/test/fixtures/swiss-gate.md
new file mode 100644
index 000000000..90c8c0c34
--- /dev/null
+++ b/make-pdf/test/fixtures/swiss-gate.md
@@ -0,0 +1,58 @@
+# Swiss gate
+
+Sentence 1 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs. Sentence 2 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs. Sentence 3 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs.
+
+## Alpha bar heading
+
+Sentence 1 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs. Sentence 2 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs. Sentence 3 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs. Sentence 4 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs. Sentence 5 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs.
+
+### Table follows
+
+| Column one | Column two | Column three |
+|---|---|---|
+| tablecellalpha | b | c |
+| d | e | f |
+
+### Code follows
+
+```
+codelinealpha = 1
+```
+
+### A long left-field sub-heading that wraps over several lines in the narrow field
+
+Short.
+
+## Beta bar heading
+
+Sentence 1 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs. Sentence 2 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs. Sentence 3 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs. Sentence 4 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs. Sentence 5 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs.
+
+### First of two
+
+### Second of two
+
+Sentence 1 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs. Sentence 2 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs. Sentence 3 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs. Sentence 4 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs.
+
+## Gamma bar heading
+
+Sentence 1 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs. Sentence 2 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs. Sentence 3 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs. Sentence 4 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs. Sentence 5 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs. Sentence 6 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs.
+
+## Delta bar heading
+
+Sentence 1 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs. Sentence 2 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs. Sentence 3 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs. Sentence 4 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs. Sentence 5 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs. Sentence 6 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs.
+
+## Epsilon bar heading
+
+Sentence 1 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs. Sentence 2 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs. Sentence 3 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs. Sentence 4 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs. Sentence 5 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs. Sentence 6 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs.
+
+## Zeta bar heading
+
+Sentence 1 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs. Sentence 2 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs. Sentence 3 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs. Sentence 4 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs. Sentence 5 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs. Sentence 6 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs.
+
+## Eta bar heading
+
+Sentence 1 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs. Sentence 2 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs. Sentence 3 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs. Sentence 4 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs. Sentence 5 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs. Sentence 6 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs.
+
+## Theta bar heading
+
+Sentence 1 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs. Sentence 2 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs. Sentence 3 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs. Sentence 4 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs. Sentence 5 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs. Sentence 6 of this paragraph keeps the line long enough to wrap across the text column several times, which is what a reading measure needs.
diff --git a/make-pdf/test/render.test.ts b/make-pdf/test/render.test.ts
index 8c3436c35..c4795558e 100644
--- a/make-pdf/test/render.test.ts
+++ b/make-pdf/test/render.test.ts
@@ -576,7 +576,7 @@ describe("render() — removing script keeps the page's structure", () => {
describe("printCss", () => {
test("emits 1in margins by default", () => {
- const css = printCss();
+ const css = printCss({ style: "plain" });
expect(css).toContain("margin: 1in");
});
@@ -588,7 +588,7 @@ describe("printCss", () => {
test("per-side margins reach the CSS @page rule (preferCSSPageSize parity)", () => {
// Under a landscape promotion Chromium honors the CSS margins, not the
// CDP per-side options — render() must compose them into the shorthand.
- const r = render({ markdown: "# T", marginLeft: "0.5in", marginRight: "0.5in" });
+ const r = render({ markdown: "# T", marginLeft: "0.5in", marginRight: "0.5in", style: "plain" });
expect(r.printCss).toContain("margin: 1in 0.5in 1in 0.5in");
});
@@ -664,7 +664,7 @@ describe("printCss", () => {
});
test("typography floor: body 12pt, poster cover, readable TOC", () => {
- const css = printCss({ cover: true, toc: true });
+ const css = printCss({ cover: true, toc: true, style: "plain" });
expect(css).toContain("font-size: 12pt"); // body
expect(css).toMatch(/\.cover h1\.cover-title\s*\{[^}]*font-size:\s*56pt/);
expect(css).toMatch(/\.cover \.cover-meta\s*\{[^}]*font-size:\s*13pt/);
diff --git a/make-pdf/test/style-swiss.test.ts b/make-pdf/test/style-swiss.test.ts
new file mode 100644
index 000000000..93168c122
--- /dev/null
+++ b/make-pdf/test/style-swiss.test.ts
@@ -0,0 +1,223 @@
+/**
+ * The swiss style (make-pdf's default since GSTA-849) and the plain style
+ * that keeps the look from before it.
+ *
+ * plain is pinned byte for byte: the golden files under
+ * fixtures/print-css-plain/ were captured from printCss()/screenCss() on main
+ * before swiss existed, so any drift in the plain look fails here.
+ */
+
+import { describe, expect, test } from "bun:test";
+import { execFileSync } from "node:child_process";
+import * as fs from "node:fs";
+import * as os from "node:os";
+import * as path from "node:path";
+
+import { printCss, resolveMargins, screenCss } from "../src/print-css";
+import { keepFieldHeadingsWithText, render } from "../src/render";
+import { contentWidthInches, landscapeContentBox } from "../src/diagram-prepass";
+import { generate } from "../src/orchestrator";
+import { DEFAULT_STYLE, SWISS_FIELD_IN, SWISS_MARGIN_SHORTHAND, swissCoverTitle, swissFieldHeadingLines } from "../src/style-swiss";
+
+const GOLDEN = path.join(import.meta.dir, "fixtures", "print-css-plain");
+const golden = (name: string) => fs.readFileSync(path.join(GOLDEN, name), "utf8");
+
+describe("plain is today's look, byte for byte", () => {
+ test("default options", () => {
+ expect(printCss({ style: "plain" })).toBe(golden("default.css"));
+ });
+ test("every structural flag at once", () => {
+ expect(printCss({
+ style: "plain", cover: true, toc: true, noChapterBreaks: true, watermark: "DRAFT",
+ confidential: false, runningHeader: 'Title "q"', pageSize: "a4", margins: "72pt", pageNumbers: false,
+ })).toBe(golden("flags.css"));
+ });
+ test("screen layer for --to html", () => {
+ expect(screenCss("plain")).toBe(golden("screen.css"));
+ });
+ test("plain cover title carries no inline sizing", () => {
+ const r = render({ markdown: "# T", cover: true, title: "gstack ethos", style: "plain" });
+ expect(r.html).toContain('<h1 class="cover-title">gstack ethos</h1>');
+ });
+ test("resolveMargins leaves plain options untouched", () => {
+ const o = { marginLeft: "0.5in" };
+ expect(resolveMargins(o, "plain")).toBe(o);
+ });
+});
+
+describe("swiss is the default", () => {
+ test("DEFAULT_STYLE is swiss and printCss() uses it", () => {
+ expect(DEFAULT_STYLE).toBe("swiss");
+ const css = printCss();
+ expect(css).toContain(`margin: ${SWISS_MARGIN_SHORTHAND};`);
+ expect(css).toContain(`--swiss-field: ${SWISS_FIELD_IN}in`);
+ expect(css).toContain("body { font-size: 11pt; line-height: 15pt; }");
+ });
+ test("swiss appends to the plain rules, so structural rules keep one source", () => {
+ const css = printCss({ style: "swiss" });
+ const plain = printCss({ style: "plain", margins: SWISS_MARGIN_SHORTHAND });
+ expect(css.startsWith(plain)).toBe(true);
+ });
+ test("explicit --margins overrides every swiss side", () => {
+ expect(printCss({ margins: "72pt" })).toContain("margin: 72pt;");
+ expect(resolveMargins({ margins: "1in" }, "swiss")).toMatchObject({
+ marginTop: "1in", marginRight: "1in", marginBottom: "1in", marginLeft: "1in",
+ });
+ });
+ test("one per-side flag keeps the other swiss defaults", () => {
+ const r = render({ markdown: "# T", marginLeft: "0.5in", marginRight: "0.5in" });
+ expect(r.printCss).toContain("margin: 0.7in 0.5in 0.85in 0.5in");
+ });
+ test("content width follows the swiss margins (7in letter, about 6.77in A4)", () => {
+ expect(contentWidthInches(resolveMargins({}, "swiss"))).toBeCloseTo(7);
+ expect(contentWidthInches(resolveMargins({ pageSize: "a4", margins: undefined }, "swiss"))).toBeCloseTo(6.77, 2);
+ expect(landscapeContentBox(resolveMargins({}, "swiss"))).toEqual({ contentWIn: 9.5, contentHIn: 6.95 });
+ });
+ test("full-width blocks clear the left field; the chapter contains its floats", () => {
+ const css = printCss();
+ expect(css).toContain(".chapter { display: flow-root; }");
+ expect(css).toMatch(/\.chapter > h1, \.chapter > h2, \.chapter > table, \.chapter > pre, \.chapter > figure, \.chapter > \.page-wide, \.chapter > p:has\(> img:only-child\) \{[^}]*clear: left;/);
+ expect(css).toMatch(/\.chapter > hr \{[^}]*clear: left;/);
+ expect(css).not.toMatch(/hr[^{]*\{[^}]*display: none/);
+ });
+ test("black bars and the cover block ask the browser to print their backgrounds", () => {
+ const css = printCss({ cover: true, toc: true });
+ for (const sel of [".chapter > h2", ".cover h1.cover-title", ".toc h2"]) {
+ const rule = css.split("\n").find((l) => l.startsWith(`${sel} {`) && l.includes("background"));
+ expect(rule).toContain("print-color-adjust: exact");
+ }
+ });
+ test("cover and TOC rules only when those parts exist", () => {
+ const css = printCss();
+ expect(css).not.toContain(".cover h1.cover-title");
+ expect(css).not.toContain(".toc h2");
+ });
+ test("screen layer collapses the field on narrow screens", () => {
+ const css = screenCss();
+ expect(css.startsWith(golden("screen.css"))).toBe(true);
+ expect(css).toContain("@media screen and (max-width: 48em)");
+ expect(css).toMatch(/\.chapter > h3, \.chapter > \.swiss-keep > h3 \{ float: none; position: static;/);
+ });
+});
+
+describe("swiss field headings stay with their text", () => {
+ test("an h3 and the paragraph, list or quote after it share one wrapper", () => {
+ const html = "<h3>Short</h3>\n<p>Text.</p><h3>List</h3><ul><li>a<ul><li>b</li></ul></li></ul><p>after</p>";
+ const out = keepFieldHeadingsWithText(html);
+ expect(out).toBe(
+ '<div class="swiss-keep" style="min-height: 15pt;"><h3>Short</h3>\n<p>Text.</p></div>' +
+ '<div class="swiss-keep" style="min-height: 15pt;"><h3>List</h3><ul><li>a<ul><li>b</li></ul></li></ul></div><p>after</p>',
+ );
+ });
+ test("code, tables, figures and a following heading get no wrapper", () => {
+ const html = "<h3>A</h3><pre>x</pre><h3>B</h3><table><tr><td>1</td></tr></table><h3>C</h3><h3>D</h3><figure></figure>";
+ expect(keepFieldHeadingsWithText(html)).toBe(html);
+ });
+ test("an h3 before an image-only paragraph gets no wrapper, so the image keeps the full width", () => {
+ const html = '<h3>Shot</h3><p><img src="x.png" alt="x"></p><h3>Caption</h3><p>see <img src="y.png"> here</p>';
+ expect(keepFieldHeadingsWithText(html)).toBe(html);
+ });
+ test("an h3 inside a quote, list item, table or details block gets no wrapper", () => {
+ const html = "<blockquote><h3>Q</h3><p>quoted</p></blockquote><ul><li><h3>L</h3><p>item</p></li></ul>" +
+ "<table><tr><td><h3>T</h3><p>cell</p></td></tr></table><details><h3>D</h3><p>more</p></details>";
+ expect(keepFieldHeadingsWithText(html)).toBe(html);
+ expect(keepFieldHeadingsWithText(html + "<h3>Top</h3><p>body</p>")).toBe(
+ html + '<div class="swiss-keep" style="min-height: 15pt;"><h3>Top</h3><p>body</p></div>',
+ );
+ expect(render({ markdown: "# Doc\n\n> ### Quoted heading\n>\n> Quoted paragraph." }).html).not.toContain('<div class="swiss-keep"');
+ });
+ test("an h3 inside raw HTML gets no wrapper, and the wrapper CSS only positions top-level wrappers", () => {
+ const md = "# Doc\n\n<div align=\"center\">\n\n### Inside div\n\nPara in div.\n\n</div>\n\n<section>\n\n### Inside section\n\nMore.\n\n</section>\n\n### Top\n\nbody";
+ const html = render({ markdown: md }).html;
+ expect(html.match(/<div class="swiss-keep"/g)?.length).toBe(1);
+ expect(html).toContain('<div class="swiss-keep" style="min-height: 15pt;"><h3>Top</h3>');
+ const css = printCss();
+ expect(css).toContain(".chapter > .swiss-keep > h3 { position: absolute;");
+ expect(css).not.toMatch(/(^|\n|, )\.swiss-keep > /);
+ });
+ test("a </p> inside an HTML comment does not end the paragraph", () => {
+ const html = "<h3>A</h3><p>x <!-- </p> --> y</p><table><tr><td>1</td></tr></table>";
+ expect(keepFieldHeadingsWithText(html)).toBe(
+ '<div class="swiss-keep" style="min-height: 15pt;"><h3>A</h3><p>x <!-- </p> --> y</p></div><table><tr><td>1</td></tr></table>',
+ );
+ });
+ test("unbalanced raw HTML does not switch off later wrappers or wrap nested ones", () => {
+ const html = "<ul><li>a<li>b</ul></div><h3>X</h3><p>t</p><blockquote><h3>Q</h3><p>q</p></blockquote>";
+ expect(keepFieldHeadingsWithText(html)).toBe(
+ '<ul><li>a<li>b</ul></div><div class="swiss-keep" style="min-height: 15pt;"><h3>X</h3><p>t</p></div><blockquote><h3>Q</h3><p>q</p></blockquote>',
+ );
+ });
+ test("one unbroken word wider than the field counts every line it wraps to", () => {
+ expect(swissFieldHeadingLines("AVeryLongIdentifierNameThatIsOneWord")).toBeGreaterThanOrEqual(2);
+ expect(swissFieldHeadingLines("x".repeat(65))).toBeGreaterThanOrEqual(3);
+ expect(swissFieldHeadingLines("Example")).toBe(1);
+ });
+ test("a long sub-heading reserves more lines than a short one", () => {
+ expect(swissFieldHeadingLines("Example")).toBe(1);
+ expect(swissFieldHeadingLines("A long left-field sub-heading that wraps over several lines in the narrow field")).toBeGreaterThanOrEqual(4);
+ });
+ test("plain renders never get the wrapper", () => {
+ expect(render({ markdown: "### H\n\ntext", style: "plain" }).html).not.toContain("swiss-keep");
+ expect(render({ markdown: "### H\n\ntext" }).html).toContain('<div class="swiss-keep"');
+ });
+});
+
+describe("swiss cover title sizing", () => {
+ test("short titles get the full 96pt poster size and the deep top pad", () => {
+ expect(swissCoverTitle("gstack ethos")).toEqual({ fontPt: 96, padTopIn: 3.2 });
+ });
+ test("a 90-character title steps down and lifts the block", () => {
+ const t = "The gstack factory: how crews plan, build, review and ship software with agents, end to end";
+ expect(t.length).toBeGreaterThanOrEqual(90);
+ const s = swissCoverTitle(t);
+ expect(s.fontPt).toBeLessThan(96);
+ expect(s.padTopIn).toBeLessThan(3.2);
+ });
+ test("a long unbreakable token falls to the 48pt floor", () => {
+ expect(swissCoverTitle("x".repeat(60)).fontPt).toBe(48);
+ });
+ test("CJK titles are measured as wide glyphs", () => {
+ const cjk = "软件工厂如何规划构建审查和发布软件".repeat(2) + "以及更多内容";
+ expect(Array.from(cjk).length).toBe(40);
+ expect(swissCoverTitle(cjk).fontPt).toBeLessThan(swissCoverTitle("a".repeat(5) + " " + "b".repeat(5)).fontPt);
+ });
+ test("emoji count as wide glyphs too", () => {
+ expect(swissCoverTitle("🚀".repeat(30)).fontPt).toBeLessThan(96);
+ });
+ test("the cover is sized for the real page box, not swiss Letter", () => {
+ const title = "Infrastructure Status for North America";
+ const small = swissCoverTitle(title, { contentWIn: 4.5, contentHIn: 7 });
+ const letter = swissCoverTitle(title);
+ expect(small.fontPt).toBeLessThan(letter.fontPt);
+ expect(small.padTopIn).toBeLessThan(letter.padTopIn);
+ expect(swissCoverTitle(title, { contentWIn: 7, contentHIn: 9.45 })).toEqual(letter);
+ const r = render({ markdown: "# T", cover: true, title, margins: "2in" });
+ expect(r.html).toContain(`style="font-size: ${small.fontPt}pt; padding-top: ${small.padTopIn}in;"`);
+ });
+ test("swiss render emits the computed size inline on the cover title", () => {
+ const r = render({ markdown: "# T", cover: true, title: "gstack ethos" });
+ expect(r.html).toContain('<h1 class="cover-title" style="font-size: 96pt; padding-top: 3.2in;">gstack ethos</h1>');
+ });
+});
+
+describe("Word output keeps the plain look", () => {
+ const unzip = Bun.which("unzip");
+ test.skipIf(!unzip)("--to docx renders the same document.xml with or without --style swiss", async () => {
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), "make-pdf-swiss-docx-"));
+ try {
+ const input = path.join(dir, "doc.md");
+ fs.writeFileSync(input, "# Doc\n\n### Sub\n\nBody text.\n");
+ const xml = async (style: "swiss" | "plain" | undefined, name: string) => {
+ const out = path.join(dir, `${name}.docx`);
+ await generate({ input, output: out, to: "docx", cover: true, title: "Short", date: "2026-11-25", quiet: true, style });
+ return execFileSync(unzip!, ["-p", out, "word/document.xml"], { timeout: 30_000 }).toString("utf8");
+ };
+ const plain = await xml("plain", "plain");
+ expect(await xml(undefined, "default")).toBe(plain);
+ expect(await xml("swiss", "swiss")).toBe(plain);
+ expect(plain).not.toContain('w:val="192"');
+ } finally {
+ fs.rmSync(dir, { recursive: true, force: true });
+ }
+ }, 60_000);
+});