From c58c02ca6937a29de565b0ae24403a684b341067 Mon Sep 17 00:00:00 2001 From: Suhani Jain <110388864+suhjainadobe@users.noreply.github.com> Date: Thu, 8 Aug 2024 11:12:43 +0530 Subject: [PATCH] Update utils.js --- libs/utils/utils.js | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/libs/utils/utils.js b/libs/utils/utils.js index 91e020ae40..2cd929eb77 100644 --- a/libs/utils/utils.js +++ b/libs/utils/utils.js @@ -724,27 +724,10 @@ async function decorateIcons(area, config) { async function decoratePlaceholders(area, config) { const el = area.querySelector('main') || area; const regex = /{{(.*?)}}|%7B%7B(.*?)%7D%7D/g; - const walker = document.createTreeWalker( - el, - NodeFilter.SHOW_TEXT, - { - acceptNode(node) { - return regex.test(node.nodeValue) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_REJECT; - }, - }, - ); - const nodes = []; - let node = walker.nextNode(); - while (node !== null) { - nodes.push(node); - node = walker.nextNode(); - } - if (!nodes.length) return; + const found = regex.test(el.innerHTML); + if (!found) return; const { replaceText } = await import('../features/placeholders.js'); - const replaceNodes = nodes.map(async (textNode) => { - textNode.nodeValue = await replaceText(textNode.nodeValue, config, regex); - }); - await Promise.all(replaceNodes); + el.innerHTML = await replaceText(el.innerHTML, config, regex); } async function loadFooter() {