Skip to content

Commit f916d38

Browse files
committed
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 <ross@ross-williams.net>
1 parent f09089c commit f916d38

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

src/locations.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,18 @@ class Locations {
104104
var dist;
105105
var pos = 0;
106106

107-
if (node.textContent.trim().length === 0) {
108-
return false; // continue
109-
}
110-
111107
// Start range
112-
if (counter == 0) {
108+
if (counter === 0 && range === undefined) {
113109
range = this.createRange();
114110
range.startContainer = node;
115111
range.startOffset = 0;
116112
}
117113

114+
if (node.textContent.trim().length === 0) {
115+
prev = node;
116+
return false; // continue
117+
}
118+
118119
dist = _break - counter;
119120

120121
// Node is smaller than a break,

0 commit comments

Comments
 (0)