From 8beb2f527974298f6fd3d39d871027b01f66fdfa Mon Sep 17 00:00:00 2001 From: David Bruant Date: Wed, 21 May 2025 12:45:47 +0200 Subject: [PATCH] look for left/right branch content only up to common ancestor --- .../odf/templating/fillOdtElementTemplate.js | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/scripts/odf/templating/fillOdtElementTemplate.js b/scripts/odf/templating/fillOdtElementTemplate.js index 6f53630..31d418a 100644 --- a/scripts/odf/templating/fillOdtElementTemplate.js +++ b/scripts/odf/templating/fillOdtElementTemplate.js @@ -131,17 +131,17 @@ function extractBlockContent(blockStartNode, blockEndNode) { const contentFragment = blockStartNode.ownerDocument.createDocumentFragment() /** @type {Element[]} */ - const repeatedPatternArray = [] + const blockContent = [] // get start branch "right" content - for(const startAncestor of startAncestry){ + for(const startAncestor of startAncestryToCommonAncestor){ if(startAncestor === startChild) break; let sibling = startAncestor.nextSibling while(sibling) { - repeatedPatternArray.push(sibling) + blockContent.push(sibling) sibling = sibling.nextSibling; } } @@ -150,38 +150,38 @@ function extractBlockContent(blockStartNode, blockEndNode) { let sibling = startChild.nextSibling while(sibling !== endChild) { - repeatedPatternArray.push(sibling) + blockContent.push(sibling) sibling = sibling.nextSibling; } // get end branch "left" content - for(const endAncestor of [...endAncestry].reverse()){ + for(const endAncestor of [...endAncestryToCommonAncestor].reverse()){ if(endAncestor === endChild) continue; // already taken care of let sibling = endAncestor.previousSibling - const reversedRepeatedPatternArrayContribution = [] + const reversedBlockContentContribution = [] while(sibling) { - reversedRepeatedPatternArrayContribution.push(sibling) + reversedBlockContentContribution.push(sibling) sibling = sibling.previousSibling; } - const repeatedPatternArrayContribution = reversedRepeatedPatternArrayContribution.reverse() + const blockContentContribution = reversedBlockContentContribution.reverse() - repeatedPatternArray.push(...repeatedPatternArrayContribution) + blockContent.push(...blockContentContribution) if(endAncestor === blockEndNode) break; } - //console.log('repeatedPatternArray', repeatedPatternArray.map(n => n.textContent)) + //console.log('blockContent', blockContent.map(n => n.textContent)) - for(const sibling of repeatedPatternArray) { + for(const sibling of blockContent) { sibling.parentNode?.removeChild(sibling) contentFragment.appendChild(sibling) }