Add render --page-break-before to start chapters on new pages#35
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds an optional
--page-break-before <h1–h6>option toswifttext render. When set, it forces a page break before every heading of that level in PDF/HTML output — e.g.--page-break-before h2starts 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 h2end to end.Why
The
rendercommand's print CSS had no forced page breaks for headings, and the render path escapes raw HTML in the Markdown (passThroughRawHTMLis 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
markdownToHTMLgains a defaultedpageBreakBefore: HeadingBreakLevel?parameter and injectsbreak-before: page/page-break-before: alwaysfor 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.HeadingBreakLevelenum (h1–h6,ExpressibleByArgument) and--page-break-beforeoption onRender, threaded through the.htmland.pdfcases.markdownToHTMLcallers are untouched (they rely on the defaulted parameter), so existing output is unchanged.Notes for reviewers
##heading lands at the top of its own page, with no page carrying two headings.swifttextproduct builds and runs.🤖 Generated with Claude Code