Skip to content

Add render --page-break-before to start chapters on new pages#35

Merged
odrobnik merged 1 commit into
mainfrom
claude/friendly-chatterjee-c8eb1b
Jun 18, 2026
Merged

Add render --page-break-before to start chapters on new pages#35
odrobnik merged 1 commit into
mainfrom
claude/friendly-chatterjee-c8eb1b

Conversation

@odrobnik

Copy link
Copy Markdown
Contributor

What

Adds an optional --page-break-before <h1–h6> option to swifttext render. When set, it forces a page break before every heading of that level in PDF/HTML output — e.g. --page-break-before h2 starts each chapter on its own page.

Also adds Scripts/manuscript-to-pdf.sh, which builds the CLI and renders a Markdown manuscript to PDF with --page-break-before h2 end to end.

Why

The render command's print CSS had no forced page breaks for headings, and the render path escapes raw HTML in the Markdown (passThroughRawHTML is off). So a caller had no way to make each chapter begin on a fresh page — neither via CSS nor by injecting markup. This closes that gap with a small, explicit option.

How

  • markdownToHTML gains a defaulted pageBreakBefore: HeadingBreakLevel? parameter and injects break-before: page / page-break-before: always for the chosen level, placed after the base heading rules so it wins on source order. The leading break is ignored by the print engine when the heading is the first box, so no blank first page is emitted.
  • New HeadingBreakLevel enum (h1h6, ExpressibleByArgument) and --page-break-before option on Render, threaded through the .html and .pdf cases.
  • The default is off, and the PDF subcommand's markdownToHTML callers are untouched (they rely on the defaulted parameter), so existing output is unchanged.

Notes for reviewers

  • Scope is PDF/HTML only; DOCX and Pages go through separate converters and are unaffected (reflected in the option's help text).
  • Verified against a 16-chapter manuscript: each ## heading lands at the top of its own page, with no page carrying two headings.
  • SwiftLint is clean on both changed files; the swifttext product builds and runs.

🤖 Generated with Claude Code

The render command's print CSS had no forced page breaks for headings,
and raw HTML in the Markdown is escaped (passThroughRawHTML is off), so a
caller could not start each chapter on its own page.

Add an optional `--page-break-before <h1–h6>` option to `render` that
injects `break-before: page` for that heading level into the PDF/HTML
stylesheet. Default off, so existing output is unchanged. markdownToHTML
gains a defaulted parameter, leaving the PDF subcommand's callers intact.

Scripts/manuscript-to-pdf.sh drives it end to end: builds swifttext and
renders a Markdown manuscript to PDF with `--page-break-before h2` so each
chapter (an h2 heading) begins on a fresh page.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@odrobnik odrobnik merged commit feb8848 into main Jun 18, 2026
6 checks passed
@odrobnik odrobnik deleted the claude/friendly-chatterjee-c8eb1b branch June 18, 2026 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant