diff --git a/blocks/enrichment/enrichment.js b/blocks/enrichment/enrichment.js index e385e2cbb3..0eead784c7 100644 --- a/blocks/enrichment/enrichment.js +++ b/blocks/enrichment/enrichment.js @@ -39,12 +39,21 @@ export default async function decorate(block) { (await Promise.all(matchingFragments.map((path) => loadFragment(path)))) .filter((fragment) => fragment) .forEach((fragment) => { - const section = fragment.querySelector(':scope .section'); - if (section) { - block.closest('.section').classList.add(...section.classList); + const sections = fragment.querySelectorAll(':scope .section'); + + // If only single section, replace enrichment block with content of section + if (sections.length === 1) { + block.closest('.section').classList.add(...sections[0].classList); const wrapper = block.closest('.enrichment-wrapper'); - Array.from(section.children) + Array.from(sections[0].children) .forEach((child) => wrapper.parentNode.insertBefore(child, wrapper)); + } else if (sections.length > 1) { + // If multiple section, append them to current section + const blockSection = block.closest('.section'); + Array.from(sections) + .reverse() + .forEach((section) => blockSection + .parentNode.insertBefore(section, blockSection.nextSibling)); } });