Skip to content

Commit

Permalink
EPUB: Handle Ibid footnotes
Browse files Browse the repository at this point in the history
  • Loading branch information
AbeJellinek committed Mar 5, 2025
1 parent b1a2e97 commit 5f906ab
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/dom/epub/epub-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,9 @@ class EPUBView extends DOMView<EPUBViewState, EPUBViewData> {

let container = doc.createElement('div');

let handledIbid = false;
let ibidRe = /\bIbid\b/;

let current = element;
let currentClone = current.cloneNode(true) as HTMLElement;
while (!current.classList.contains('section-container')) {
Expand All @@ -934,6 +937,23 @@ class EPUBView extends DOMView<EPUBViewState, EPUBViewData> {
}
let parentClone = parent.cloneNode(false) as HTMLElement;
parentClone.appendChild(currentClone);

// If the current footnote contains "Ibid", keep prepending previous siblings
// until we find one that doesn't
if (!handledIbid
&& current.previousElementSibling
&& current.textContent
&& ibidRe.test(current.textContent)) {
do {
current = current.previousElementSibling;
let currentClone = current.cloneNode(true) as HTMLElement;
parentClone.prepend(currentClone);
}
while (current.previousElementSibling?.textContent
&& ibidRe.test(current.previousElementSibling.textContent));
handledIbid = true;
}

currentClone = parentClone;
current = parent;
}
Expand Down

0 comments on commit 5f906ab

Please sign in to comment.