Skip to content

feat(reader): group chapters under collapsible parts in the HTML book's TOC - #20

Merged
apiad merged 2 commits into
mainfrom
feat/toc-parts
Oct 22, 2026
Merged

apiad merged 2 commits into
mainfrom
feat/toc-parts

Conversation

@apiad

@apiad apiad commented Oct 22, 2026

Copy link
Copy Markdown
Owner

Closes #19.

The reader's table of contents was a flat list, so a part divider (# Title {.part}) looked like one more chapter and a book with many parts had an index that was hard to scan.

Changes

  • book.py: a TOC entry from a part heading carries "part": true; order is unchanged. toc_part_css() copies the content of the theme's last h1.part::before rule (after user CSS) into a TOC label rule counted with its own part counter, so the label reads «Part I», «Parte I» or whatever the theme says. A theme that does not number parts gets no label.
  • reader.js: each part becomes a <li class="toc-part"><details><summary> with the chapters up to the next part nested in an <ol>. Chapters before the first part stay at the top level. All parts start collapsed; when the current chapter moves into another part, that part opens and the others close. Parts the reader opens by hand stay open until then. .here on chapter links is unchanged. <summary> gives keyboard access (Tab, Enter/Space).
  • reader.css: part rows in the accent colour, a small uppercase label, a small-caps bold title, more space above, a chevron that turns when open, and nested chapters indented.
  • Know-how note in know-how/the-html-book.md.

A book without parts renders the same markup as before. Its book.css gains the label rule when its theme numbers parts, which matches nothing.

The summary of a part toggles its group and does not jump to the part's divider page. That page is still one page before the part's first chapter.

Tests

  • New unit tests: part flags and order in the TOC data, no flags in the example book (which has no parts), label rule extraction (last rule wins, no rule without a part counter).
  • uv run pytest: 352 passed, browser tests included. In one earlier full run, test_a_hash_opens_at_its_target timed out once. It passed alone, in its file (20/20) and in the next full run.
  • Manual check in headless Chromium at 390×844 on a 10-part, 106-chapter book: ten collapsed PARTE I … PARTE X rows, Enter on a summary opens it, following a chapter in part III leaves only part III open with that chapter highlighted. The example book's TOC is still the flat three-chapter list.

🤖 Generated with Claude Code

apiad and others added 2 commits October 22, 2026 18:44
Refs #19

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Closes #19

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@apiad
apiad merged commit 6095b65 into main Oct 22, 2026
2 checks passed
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.

HTML book: the reader's table of contents does not group chapters under parts

1 participant