diff --git a/dist/aem.js b/dist/aem.js index 451ace4..3f3d434 100644 --- a/dist/aem.js +++ b/dist/aem.js @@ -404,14 +404,11 @@ function wrapTextNodes(block) { && validWrappers.some((tagName) => blockColumn.firstElementChild.tagName === tagName); if (!hasWrapper) { wrap(blockColumn); - } else if (blockColumn.firstElementChild.tagName === 'PICTURE') { - const nonEmptySiblings = [...blockColumn.childNodes].some((n) => { - if (n.nodeType === Node.TEXT_NODE) return !!n.textContent.trim(); - return n !== blockColumn.firstElementChild; - }); - if (nonEmptySiblings) { - wrap(blockColumn); - } + } else if ( + blockColumn.firstElementChild.tagName === 'PICTURE' + && (blockColumn.children.length > 1 || !!blockColumn.textContent.trim()) + ) { + wrap(blockColumn); } } }); diff --git a/src/dom-utils.js b/src/dom-utils.js index c6004e2..450107f 100644 --- a/src/dom-utils.js +++ b/src/dom-utils.js @@ -151,14 +151,9 @@ export function wrapTextNodes(block) { && validWrappers.some((tagName) => blockColumn.firstElementChild.tagName === tagName); if (!hasWrapper) { wrap(blockColumn); - } else if (blockColumn.firstElementChild.tagName === 'PICTURE') { - const nonEmptySiblings = [...blockColumn.childNodes].some((n) => { - if (n.nodeType === Node.TEXT_NODE) return !!n.textContent.trim(); - return n !== blockColumn.firstElementChild; - }); - if (nonEmptySiblings) { - wrap(blockColumn); - } + } else if (blockColumn.firstElementChild.tagName === 'PICTURE' + && (blockColumn.children.length > 1 || !!blockColumn.textContent.trim())) { + wrap(blockColumn); } } });