Skip to content

fix(convert): preserve chapter numbers after headings - #23

Draft
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-investigation-7c34
Draft

cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-investigation-7c34

Conversation

@cursor

@cursor cursor Bot commented Jun 14, 2026

Copy link
Copy Markdown

Bug and impact

Calibre cleanup treated any long monotonic sequence of standalone digit lines as page numbers. Books that render chapter/section numbers as a standalone line immediately after each Markdown heading (for example ## Chapter One followed by 1) lost those numbers during conversion, causing silent source-content loss before translation.

Root cause

_detect_page_number_lines collected every standalone digit before running the LNDS page-number heuristic, without excluding digit lines that are structurally attached to a heading.

Fix

Exclude standalone digit lines whose previous nonblank line is a Markdown heading from the page-number candidate sequence, while preserving the existing explicit --strip-page-numbers behavior and Calibre-noise adjacency cleanup.

Validation

  • Reproduced the pre-fix behavior: four chapter headings followed by 1-4 cleaned down to no standalone numbers.
  • Verified post-fix repro preserves 1-4.
  • python3 -m unittest tests.test_convert.CleanCalibreMarkersTests -v (11 tests)
  • python3 -m unittest discover -s tests -p 'test_*.py' -v (206 tests, 3 skipped)
  • python3 -m compileall scripts tests
  • Baseline mock full pipeline using standard-alice.epub: converted 38 chunks and generated HTML/DOCX/PDF; EPUB failed only with the documented Ubuntu Calibre 7.6.0 packaging bug.
Open in Web View Automation 

Co-authored-by: Rainman <deusyu@users.noreply.github.com>
@deusyu
deusyu force-pushed the cursor/critical-bug-investigation-7c34 branch from d09e637 to ee64e89 Compare June 26, 2026 02:15
@cursor
cursor Bot deleted the cursor/critical-bug-investigation-7c34 branch July 2, 2026 08:22
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