From f916d38ce5d901e498a367892d29750a9e076dc8 Mon Sep 17 00:00:00 2001 From: Ross Williams Date: Thu, 20 Feb 2025 23:46:20 -0500 Subject: [PATCH] Ensure at least one location per section Previously, if a book had no text content in a section, then no location would be generated. In the pathological case of a book with no text content at all (pictures only), no locations are generated for the entire book. An example of this is the Open Circuits EPUB from No Starch Press (2023). By moving the "empty node" detection after the creation of the initial opening range, the parsing code ensures that a minimum of one location is generated per section. Signed-off-by: Ross Williams --- src/locations.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/locations.js b/src/locations.js index 27498908f..475fb758f 100644 --- a/src/locations.js +++ b/src/locations.js @@ -104,17 +104,18 @@ class Locations { var dist; var pos = 0; - if (node.textContent.trim().length === 0) { - return false; // continue - } - // Start range - if (counter == 0) { + if (counter === 0 && range === undefined) { range = this.createRange(); range.startContainer = node; range.startOffset = 0; } + if (node.textContent.trim().length === 0) { + prev = node; + return false; // continue + } + dist = _break - counter; // Node is smaller than a break,