From a6c980f158769305baa8d5b74d13fe940a4af890 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Saben=C3=A7a?= Date: Thu, 27 Aug 2026 21:07:34 +0100 Subject: [PATCH] fix: keep split chapter anchors on their first fragment textsplit.py duplicates a chapter's wrapping element (and its id) into every fragment produced when a large spine file is split, so the anchor map's last-write-wins assignment always ended up pointing the TOC/NCX anchor at the chapter's last fragment instead of its first. Readers whose spine->TOC lookup falls back to the previous entry for un-tocced spine items (CrossPoint and YACP both do) then show the previous chapter's title for nearly the entire chapter. Use setdefault so the first fragment containing the id wins instead. --- crosspoint_reader/textsplit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crosspoint_reader/textsplit.py b/crosspoint_reader/textsplit.py index 67b9e95..aa773fa 100644 --- a/crosspoint_reader/textsplit.py +++ b/crosspoint_reader/textsplit.py @@ -400,7 +400,7 @@ def _split_epub_text(path, log, result, profile=None, opts=None): if k > 0: order.insert(insert_at + k, new_zname) for frag in re.findall(r'id="([^"]+)"', content): - anchor_map[(posixpath.basename(href), frag)] = name + anchor_map.setdefault((posixpath.basename(href), frag), name) new_items = [] new_refs = []