Repository navigation
feat(book): full title→heading chain in injectBookSectionDefaults - #33
Merged
Merged
Conversation
Wires `title.enabled`, `heading_2.enabled`, and `heading_3.enabled` per `section:` tag in `injectBookSectionDefaults` so the chapter-prefix machinery in enumerate.ts composes without authors needing project-level workarounds. Background: `enumerate.ts`'s book-mode auto-prefix only fires when the page-title heading is itself numbered (it provides `this.enumerator` for figures/theorems/sub-headings to prepend). The page-title heading in turn requires `numbering.title.enabled: true`. PR #22 wired `heading_1.enabled` per section but missed `title`, so chapter pages rendered `Figure 1` / `Section 1` instead of `Figure 1.1` / `Section 1.1` on a default `numbering.book: true` config. Authors hit this on pandoc- generated chapter files (LaTeX `\chapter{}` → MD `# Title`) where they cannot add per-page frontmatter. This patch: - chapters / appendices: seeds `title.enabled ??= true`, `heading_2.enabled ??= true`, `heading_3.enabled ??= true` alongside the existing `heading_1` defaults. - frontmatter / backmatter: seeds those same keys to `??= false` so a project-level `heading_2.enabled: true` (often used so chapters number correctly) doesn't leak through and number the preface's `##` headings. - Changes the legacy hard `h1.enabled = false` on frontmatter/backmatter to `??= false` for symmetry — a page that explicitly wants its title numbered (e.g. "Chapter 0: Preface") can now override the section default. The hard assignment had made this impossible. All assignments use `??=` so the layered precedence (page > project > section default > hardcoded) is preserved. Adds 10 new tests covering the new wiring and the per-page override paths. Closes #25. Co-Authored-By: Claude Opus 4.7 <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR updates injectBookSectionDefaults in myst-cli to seed book-mode numbering defaults per TOC section: tag so that chapter-prefix enumeration composes correctly when a page’s first H1 is absorbed as the page title (e.g., pandoc chapter conversions).
Changes:
- Extend section-default injection to cover
numbering.title,numbering.heading_2, andnumbering.heading_3(in addition to existingheading_1) forchapters/appendices, and seed disabled defaults forfrontmatter/backmatter. - Add unit tests covering the new defaults and override behavior.
- Add a changeset documenting the patch release.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| packages/myst-cli/src/process/mdast.ts | Extends injectBookSectionDefaults to seed title + heading_2/3 defaults by book section. |
| packages/myst-cli/src/process/bookSection.spec.ts | Adds tests validating the new seeding/override behavior. |
| .changeset/book-section-defaults.md | Declares a myst-cli patch release and describes the behavior change. |
Comments suppressed due to low confidence (1)
packages/myst-cli/src/process/bookSection.spec.ts:200
- This test (and its comment) uses
heading_1.start: 0to illustrate a “Chapter 0: Preface”, but the frontmatter validator enforcesstart >= 1for numbering items (myst-frontmattervalidateNumberingItem,min: 1). In the real pipeline a page-levelstart: 0will be rejected/ignored, so this example doesn’t reflect a supported override unless validation rules are changed.
test('page override wins on a frontmatter page: enabling title is preserved', () => {
// The other direction: an author has a `Preface` they want numbered
// as part of the chapter sequence ("Chapter 0: Preface"). They write
// `numbering.heading_1: { enabled: true, start: 0, label: "Chapter %s" }`.
// The section default uses ??=, so the page wins and the preface
// gets numbered despite being tagged `section: frontmatter`.
//
// This is the symmetry fix: the legacy `h1.enabled = false` (hard
// assignment) made this impossible.
const fm: PageFrontmatter = {
numbering: {
book: { enabled: true },
heading_1: { enabled: true, start: 0, label: 'Chapter %s' },
title: { enabled: true },
},
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment-and-changeset cleanup of injectBookSectionDefaults after a deep review confirmed the documented precedence chain (page > project > section > built-in) matches the code. The previous claim that frontmatter/backmatter section defaults block project-level numbering leakage contradicted that chain — `injectBookSectionDefaults` runs after `processPageFrontmatter` merges project numbering into the page, so `??=` no-ops for any key the project explicitly set. Reframe the comments and changeset around the real story: the new chapter-side wiring (title/heading_2/heading_3 seeded true on chapter pages) means authors no longer need a project-level `heading_2.enabled: true` workaround, so the leak scenario stops happening in the common case. A project that explicitly enables those depths still wins — by design, per §3.5(g). Also replace the `start: 0` page-override test (rejected by the `min: 1` validator at validators.ts:148) with a valid override using `title.enabled: true`. No code logic changes, no signature changes. All 19 bookSection tests pass; full myst-cli suite 293/293 green. Co-Authored-By: Claude Opus 4.7 <[email protected]>
Extend `injectBookSectionDefaults` to wire heading_4/5/6 alongside the existing title/heading_1/heading_2/heading_3 chain. With the depth-1–3 fix in place, authors who removed the project-level workaround discovered that `####`+ headings on chapter pages rendered unnumbered (verified against book-dp1 — ch_intro had H4s rendering with enum=None instead of `1.1.1.1`). mystmd's numbering schema caps at heading_6 (matches HTML h1–h6, see myst-frontmatter numbering/types.ts), so wiring 1–6 is exhaustive rather than arbitrary — there is no heading_7 to forget. All assignments stay `??=` per §3.5(g) precedence (page > project > section > built-in), so a project or page that explicitly disables a deeper level still wins. Tests updated to assert the full 1–6 chain on chapters/appendices and the matching full disable on frontmatter/backmatter. All 19 bookSection tests pass; full myst-cli suite 293/293 green. Closes #36. Co-Authored-By: Claude Opus 4.7 <[email protected]>
Move all numbering mutations inside the `switch` cases so any `BookSection` value not explicitly handled (currently only `parts`, which is divider-only) is a clean no-op past the gate checks. Previously the function pre-initialized `heading_1` and (after the heading_6 extension in 33ae25c) `title`/`heading_2…heading_6` to empty `{}` objects before the switch, which leaked into the resolved frontmatter for any page tagged `section: parts`. The `firstInSection` branch could also have set `h1.start = 1` on such pages. Both are now contained to the chapters/appendices and frontmatter/backmatter cases that actually need them. Caught by Copilot review on PR #33. Add a regression test pinning the no-op behavior for `section: parts` with `firstInSection: true` — the path that previously leaked the most. 20 bookSection tests pass; full myst-cli suite 294/294 green. Co-Authored-By: Claude Opus 4.7 <[email protected]>
This was referenced May 18, 2026
mmcky
added a commit
that referenced
this pull request
May 20, 2026
PR #33 was merged onto main after qe-v4 but missed the VERSION.yml append step. Recording it as id 5 with tag qe-v5, and adding its squash SHA to the book-mode-with-section-scope upstream candidate (it patches #22's injectBookSectionDefaults). Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
This was referenced May 21, 2026
9 tasks done
mmcky
added a commit
that referenced
this pull request
May 22, 2026
Records PR #40 (#34 — LaTeX `\newtheorem{name}[other]` counter sharing) as id 6 with squash SHA a63d53f and tag qe-v6, and adds it to the book-mode-with-section-scope upstream candidate alongside #22, #28, and #33 — they share the same auto-prefix machinery and form one coherent upstream story. Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
This was referenced Jun 3, 2026
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.
Summary
Closes #25 and #36. Wires the full
title → heading_1 → … → heading_6chain persection:tag ininjectBookSectionDefaultsso the chapter-prefix machinery inenumerate.tscomposes without authors needing project-level or per-page frontmatter workarounds.The problem (from #25)
In a project using just
numbering.book: trueandsection:tags:…the
enumerate.tsauto-prefix machinery never fires on chapter pages. The page-title H1 (which pandoc-generated chapter files produce as# Introduction) doesn't increment a counter unlessnumbering.title.enabled: true, sothis.enumerator(the chapter prefix) is undefined and figures / sections / theorems render flat:Figure 1instead ofFigure 1.1,Section 1instead of1.1, etc.The existing workaround required setting
title.enabledandheading_2/3/4.enabledat project level — but that then leaked into frontmatter/backmatter pages, numbering## Acknowledgementson the preface as "1". Per-page frontmatter to disable it was the only way out, and isn't viable for book-dp1 where chapter files are pandoc-generated and forbidden to hand-edit.The fix
In
injectBookSectionDefaults(a ~40-line function), wire the matching chain per section:section:tagchapters/appendicestitle.enabled ??= true,heading_2/3/4/5/6.enabled ??= true(alongside existingheading_1wiring)frontmatter/backmattertitle.enabled ??= false,heading_2/3/4/5/6.enabled ??= false(matching existingheading_1disable)The chain covers all six HTML heading depths because mystmd's numbering schema caps at
heading_6(myst-frontmatternumbering/types.ts) — wiring 1–6 is exhaustive rather than arbitrary.Also changes the legacy hard
h1.enabled = falseon frontmatter/backmatter to??= falseto align with the documented precedence model — the hard assignment had violated layer 1 (page) by making a page-explicit override impossible.Precedence (§3.5(g))
This change only adds defaults, never overrides. The mystmd precedence model — verified against the code in
fillNumbering/fillMissingKeys— is fully honored:numbering:(highest)numbering:All assignments use
??=so any higher layer's setting flows through untouched. A project that explicitly enables, say,heading_2.enabled: truewill still cause numbering on asection: frontmatterpage — by design, per the documented precedence. Authors who want different behavior on a specific preface page set it explicitly in page frontmatter.Tests added
10 new tests in
bookSection.spec.ts:title.enabled: true)All 19
bookSection.spec.tstests pass; full myst-cli suite 293/293 green.End-to-end verification against book-dp1
Branch built locally and npm-linked into book-dp1 (qe-v4 + #25 stripped of the project-level workaround —
numbering:reduced to justbook: trueplus per-kindproof.scope). Verified on rendered output (commit0b32ad13, pre-#36 extension; depth-4 verified after33ae25cf):1, H21.1, H31.1.1, Figure1.1, Theorem1.2.1, Algorithm1.12,2.1,2.1.1,2.1A, H2A.1/A.2/A.3, TheoremA.2.11.1.1.1(#36)33ae25cf)Notes on review feedback
The first revision overclaimed in the comments and changeset — it said the frontmatter/backmatter section defaults block project-level leakage, which contradicts §3.5(g) (section defaults are layer 3, below project). Copilot flagged the call-ordering issue, and a deep review confirmed the documented precedence is correct and matches the code. The follow-up commit (
0b32ad13) reframes the claims around what the change actually does (chapter-side wiring removes the need for the workaround that caused leaks) without changing any code logic. End-to-end testing against book-dp1 then surfaced that the 1–3 chain wasn't enough —####headings rendered flat — which was folded into this PR as33ae25cf(closing #36).Test plan
bookSection.spec.ts(19 tests) passmyst-clifull suite (293 tests) passnumbering: { book: true }only — chapter, second-chapter, preface, appendix all render as expected; depth-4 numbering confirmed after Extend injectBookSectionDefaults to heading_4–heading_6 #36 extension🤖 Generated with Claude Code