MCPcopy Index your code
hub / github.com/karpathy/reader3 / get_fallback_toc

Function get_fallback_toc

reader3.py:135–146  ·  view source on GitHub ↗

If TOC is missing, build a flat one from the Spine.

(book_obj)

Source from the content-addressed store, hash-verified

133
134
135def get_fallback_toc(book_obj) -> List[TOCEntry]:
136 """
137 If TOC is missing, build a flat one from the Spine.
138 """
139 toc = []
140 for item in book_obj.get_items():
141 if item.get_type() == ebooklib.ITEM_DOCUMENT:
142 name = item.get_name()
143 # Try to guess a title from the content or ID
144 title = item.get_name().replace('.html', '').replace('.xhtml', '').replace('_', ' ').title()
145 toc.append(TOCEntry(title=title, href=name, file_href=name, anchor=""))
146 return toc
147
148
149def extract_metadata_robust(book_obj) -> BookMetadata:

Callers 1

process_epubFunction · 0.85

Calls 1

TOCEntryClass · 0.85

Tested by

no test coverage detected