Skip to content

Bind the Title to numbering level 0 so every h1 restarts the count - #13

Merged
jph00 merged 1 commit into
mainfrom
title-numbering-boundary
Sep 3, 2026
Merged

Bind the Title to numbering level 0 so every h1 restarts the count#13
jph00 merged 1 commit into
mainfrom
title-numbering-boundary

Conversation

@PiotrCzapla

@PiotrCzapla PiotrCzapla commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

We need includes in our pipeline, and the only reliable place I found to do them is at the markdown level. An included document has to keep its own heading numbers, since it also works as a standalone document.

The idea: keep a counter for every level, the title (h1) too, but never show the h1 number. Then h2 restarts after each h1. Which gives us a way to Include markdown with reset counters for headers.

Fable ideas were:

  • using section reset - did not work too well
  • follows list approach and attach a new counter to all headers after each reset, and keeping a reset as an option on the header.

The code looks good after the second Fable attempt; most of the diff is tests.
Needs AnswerDotAI/mdhtml#59.


Claude's summary of the change:

mdhtml's schemes now carry the h1 title as level 0 with an empty lvlText, so the heading abstractNum reads the scheme straight through, one Word level per scheme level. Level 0 binds to the Title style with w:suff="nothing" (an empty number takes no tab), levels 1-5 to Heading1-5. Word's multilevel rule then restarts every level below each h1, with no second numbering instance and no per-paragraph numPr. A reference without a Title style gets a warning, since its h1s cannot restart anything.

Tests: 29 pass. test_h1_is_title checks the Title binding, empty text and no suffix; test_title_restarts_numbering covers two documents in one file. The numbering.xml was verified through LibreOffice: 1. / 1.1. / 1. / 1.1. for decimal, 1. / (a) / 1. / (a) for legal, with REF fields printing each target's own number.

@PiotrCzapla
PiotrCzapla force-pushed the title-numbering-boundary branch from d567328 to 2a5852e Compare September 3, 2026 20:51
@PiotrCzapla PiotrCzapla changed the title Bind the Title to an invisible numbering level: every h1 restarts the heading numbers Bind the Title to numbering level 0 so every h1 restarts the count Sep 3, 2026
mdhtml's schemes now carry the h1 title as level 0 with an empty lvlText,
so the heading abstractNum reads the scheme straight through: level 0 binds
to the Title style (with `w:suff nothing`, since an empty number takes no
tab either) and levels 1-5 to Heading1-5, and Word's multilevel rule makes
every h1 restart the levels below it. A reference without a Title style
gets a warning, because its h1s cannot restart anything.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@PiotrCzapla
PiotrCzapla force-pushed the title-numbering-boundary branch from 2a5852e to 16bab80 Compare September 3, 2026 21:01
@PiotrCzapla
PiotrCzapla marked this pull request as ready for review September 3, 2026 21:04
@PiotrCzapla
PiotrCzapla requested review from jph00 and ncoop57 September 3, 2026 21:04
@jph00
jph00 merged commit 04dc114 into main Sep 3, 2026
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.

2 participants