From 4410a692079920376fb7215c7cd4c7debd8c7a15 Mon Sep 17 00:00:00 2001 From: "Simen A. W. Olsen" Date: Fri, 29 May 2026 00:16:48 +0200 Subject: feat: flatten TOC and add kindlegen validation --- epubs/zig-0.11.0.epub | Bin 1086285 -> 1081154 bytes epubs/zig-0.12.0.epub | Bin 928020 -> 922787 bytes epubs/zig-0.12.1.epub | Bin 938646 -> 933413 bytes epubs/zig-0.13.0.epub | Bin 938695 -> 933462 bytes epubs/zig-0.14.0.epub | Bin 969788 -> 964256 bytes epubs/zig-0.14.1.epub | Bin 973091 -> 967559 bytes epubs/zig-0.15.1.epub | Bin 976374 -> 970838 bytes epubs/zig-0.15.2.epub | Bin 975597 -> 970073 bytes epubs/zig-0.16.0.epub | Bin 989455 -> 983760 bytes epubs/zig-0.9.0.epub | Bin 1118090 -> 1113072 bytes epubs/zig-0.9.1.epub | Bin 1118252 -> 1113222 bytes epubs/zig-master.epub | Bin 972486 -> 966895 bytes src/html.zig | 71 +++++++++++++++++++++++++++----------------------- validate.sh | 44 ++++++++++++++++++++++++------- 14 files changed, 73 insertions(+), 42 deletions(-) diff --git a/epubs/zig-0.11.0.epub b/epubs/zig-0.11.0.epub index 8751a77..ee5b585 100644 Binary files a/epubs/zig-0.11.0.epub and b/epubs/zig-0.11.0.epub differ diff --git a/epubs/zig-0.12.0.epub b/epubs/zig-0.12.0.epub index 9dca6f3..fab617f 100644 Binary files a/epubs/zig-0.12.0.epub and b/epubs/zig-0.12.0.epub differ diff --git a/epubs/zig-0.12.1.epub b/epubs/zig-0.12.1.epub index 64b2179..d2d0be1 100644 Binary files a/epubs/zig-0.12.1.epub and b/epubs/zig-0.12.1.epub differ diff --git a/epubs/zig-0.13.0.epub b/epubs/zig-0.13.0.epub index f242a27..57cf9ca 100644 Binary files a/epubs/zig-0.13.0.epub and b/epubs/zig-0.13.0.epub differ diff --git a/epubs/zig-0.14.0.epub b/epubs/zig-0.14.0.epub index 1af8ecd..60ce73d 100644 Binary files a/epubs/zig-0.14.0.epub and b/epubs/zig-0.14.0.epub differ diff --git a/epubs/zig-0.14.1.epub b/epubs/zig-0.14.1.epub index 378dbb1..7279242 100644 Binary files a/epubs/zig-0.14.1.epub and b/epubs/zig-0.14.1.epub differ diff --git a/epubs/zig-0.15.1.epub b/epubs/zig-0.15.1.epub index 564ab1e..d92935f 100644 Binary files a/epubs/zig-0.15.1.epub and b/epubs/zig-0.15.1.epub differ diff --git a/epubs/zig-0.15.2.epub b/epubs/zig-0.15.2.epub index 152f4e4..1d98fee 100644 Binary files a/epubs/zig-0.15.2.epub and b/epubs/zig-0.15.2.epub differ diff --git a/epubs/zig-0.16.0.epub b/epubs/zig-0.16.0.epub index 114bee7..80fd87b 100644 Binary files a/epubs/zig-0.16.0.epub and b/epubs/zig-0.16.0.epub differ diff --git a/epubs/zig-0.9.0.epub b/epubs/zig-0.9.0.epub index b6f6dd4..f2203e7 100644 Binary files a/epubs/zig-0.9.0.epub and b/epubs/zig-0.9.0.epub differ diff --git a/epubs/zig-0.9.1.epub b/epubs/zig-0.9.1.epub index fbc087d..14fc4b1 100644 Binary files a/epubs/zig-0.9.1.epub and b/epubs/zig-0.9.1.epub differ diff --git a/epubs/zig-master.epub b/epubs/zig-master.epub index 2dd2111..2dad509 100644 Binary files a/epubs/zig-master.epub and b/epubs/zig-master.epub differ diff --git a/src/html.zig b/src/html.zig index fe7f287..8ec8564 100644 --- a/src/html.zig +++ b/src/html.zig @@ -8,7 +8,8 @@ //! 4. normalizes HTML named entities (e.g. `—`) to numeric references, //! since XML predefines only `& < > " '`, //! 5. removes invalid control characters, -//! 6. extracts the in-page table of contents for use as the EPUB navigation, +//! 6. extracts the in-page table of contents (flattened to one level, since +//! Amazon's kindlegen rejects nested nav TOCs) for the EPUB navigation, //! 7. removes the `#navigation` sidebar (it is `position: fixed`, so it bleeds //! onto every page, and the version-switcher dropdown is dead in an EPUB), //! 8. self-closes void elements (`` -> ``, etc.). @@ -94,48 +95,52 @@ fn extractToc(allocator: std.mem.Allocator, html: []const u8) !?[]u8 { const m = std.mem.indexOf(u8, html, marker) orelse return null; const ul_open = findTagOpen(html, m, "ul") orelse return null; const ul_end = matchingClose(html, ul_open, "ul") orelse return null; - return try rewriteToc(allocator, html[ul_open..ul_end]); + return try flattenToc(allocator, html[ul_open..ul_end]); } -/// Rewrite an extracted TOC list: `