Skip to content

fix: preserve embedded numbered chapter titles after introductions - #525

Closed
mvanhorn wants to merge 1 commit into
kikootwo:mainfrom
mvanhorn:fix/509-preserve-embedded-chapter-titles
Closed

mvanhorn wants to merge 1 commit into
kikootwo:mainfrom
mvanhorn:fix/509-preserve-embedded-chapter-titles

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Linked issue

Fixes #509

What changed

Accept embedded numbered chapter titles while preserving their original case and zero padding. Filename-derived names retain priority, titles identified as the book title remain excluded, and other generic titles still use fallback numbering. Regression coverage checks ordering, title preservation after an introduction, and the chapter metadata passed into merging; the documentation describes the behavior.

Why

Merging an audiobook with an introduction shifts subsequent embedded chapter numbers: “Chapter 1” becomes “Chapter 2” even though the audio remains in the correct order. getChapterTitle() treated embedded “Chapter N” titles as generic and replaced them with numbering based on file position. An introduction occupies the first position, so the fallback numbers no longer match the embedded chapter labels.

How it was tested

npx --no-install vitest run tests/utils/chapter-merger.test.ts passed all 25 tests.
Ran npm test in a Linux container (localhost/osc-linux-node:22) for the ReadMeABook getChapterTitle change; 6482 tests passed.
The tests in tests/utils/chapter-merger.test.ts fail without the fix in the ReadMeABook getChapterTitle change (checked by reverting the source changes).

Checklist

  • Tests added or updated, and npm test passes
  • Docs in documentation/ updated in the compact format (bullets, tables, short code blocks), plus documentation/TABLEOFCONTENTS.md if a doc was added
  • No secrets, API keys, passwords or personal data in the code, logs or screenshots

AI was used for assistance.

Accept embedded numbered chapter titles while preserving their original
case and zero padding. Filename-derived names retain priority, titles
identified as the book title remain excluded, and other generic titles
still use fallback numbering. Regression coverage checks ordering, title
preservation after an introduction, and the chapter metadata passed into
merging; the documentation describes the behavior.

Fixes kikootwo#509
@kikootwo

kikootwo commented Nov 2, 2026

Copy link
Copy Markdown
Owner

@mvanhorn thanks for this, the diagnosis is right. I'm bringing it in on a branch of mine with you as co-author, with one change: the embedded "Chapter N" titles are kept only when they stay distinct across the whole book, so multi-disc sets that restart at "Chapter 1" on each disc keep today's numbering instead of getting duplicate names. I'll close this one when it lands.

kikootwo added a commit that referenced this pull request Nov 2, 2026
…a merged book (#531)

A merged book whose files are tagged "Intro", "Chapter 1", "Chapter 2" and whose file names hold no titles keeps those chapter names; before, every "Chapter N" tag was replaced by the file's position, so the intro shifted each chapter by one. The numbered tags are kept only when every title in the set is distinct (case and spacing folded, "Chapter 01" = "Chapter 1"), fallback names of untagged files included. Per-disc tags that restart at "Chapter 1", or an untagged intro beside "Chapter 1..N", keep position numbering as before. One log line says which way the set went.

Closes #509

Based on #525 by @mvanhorn, with a check across the whole book so per-disc sets keep their numbering.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: mvanhorn <455140+mvanhorn@users.noreply.github.com>
@kikootwo

kikootwo commented Nov 2, 2026

Copy link
Copy Markdown
Owner

@mvanhorn thanks again. It's in now as #531 with you as co-author, with the whole-book check described above. It will be in the next release. Closing this one in favour of #531.

@kikootwo kikootwo closed this Nov 2, 2026
@kikootwo

kikootwo commented Nov 3, 2026

Copy link
Copy Markdown
Owner

@mvanhorn this is out in v1.2.13, landed in #531: https://github.com/kikootwo/ReadMeABook/releases/tag/v1.2.13

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.

Bug: Chapter merging renumbers valid embedded chapter titles after an introduction

2 participants