Repository navigation
Build PDF chapters from the document outline - #45
Merged
Merged
Conversation
PDFs were ingested as a single "Document" chapter, so a 539-page book arrived as one unbroken chapter whose reading sections could only be labelled by their opening words. pdfjs already exposes the embedded outline, so read it and give each entry its own chapter. Entries at any nesting depth become chapters running to the next entry's page. Entries that cannot describe a contiguous range are dropped: backwards or out-of-range destinations, blank titles, and entries sharing a start page with the previous one. An outline with fewer than two usable entries keeps the existing single-chapter fallback, as does a PDF with no outline at all.
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.
Problem
PDFs are ingested as a single chapter titled
Document, no matter how the book is organised. A 539-page book therefore arrives as one unbroken chapter, and since reading sections come from fixed ~2500-word chunks, the sidebar can only label them by their opening words — "In effect, Kant had provided,…" — which says nothing about where you are or where you're going.Meanwhile pdfjs already exposes the book's embedded outline, and nothing in the ingest path ever asked for it. The Cambridge/Pinkard Phenomenology of Spirit carries a complete one, nested four deep with page destinations.
Change
Scoped entirely to the PDF reader — no changes to the ingest pipeline, the sidebar, the schema, or the reader plugin contract.
pdfjsAdapterreadsgetOutline()and resolves each entry's destination to a page number. Depth- and entry-capped; any failure yields no outline.planPdfChaptersturns each entry into a chapter running to the next entry's page, andprepareInitial/loadChaptersbuild from that plan. Chapters are markedsource: 'toc'withboundaryEvidence: ['publisher-toc'], so the structure is reported as authored rather than generated.Entries at any nesting depth become chapters. Entries that can't describe a contiguous range are dropped — backwards or out-of-range destinations, blank titles, and entries sharing a start page with the previous one. Fewer than two usable entries, or no outline, keeps today's single-chapter fallback untouched.
Result
The Hegel PDF imports as 61 titled chapters instead of one:
Front matter (
Cover,Copyright,Contents,Index) now arrives titled, so the existingclassifyChapterstep can recognise and skip it.Trade-offs
I. Sensuous-Certaintycollapses intoA. ConsciousnessandV. The Certainty and Truth of ReasonintoC. (AA) Reason. The text is all present, under the parent's title.Testing
npm run lint,npm test(843 passing), andnpm run buildall pass via the pre-commit hook. New reader tests cover outline-derived chapters, the dropped-entry cases, and the single-chapter fallback. The chapter plan above was verified against the real 539-page PDF.🤖 Generated with Claude Code