From 27eb1c0583d22893a5f4581037fd03123b607e43 Mon Sep 17 00:00:00 2001 From: Vaibhav sasulkar Date: Mon, 14 Oct 2024 21:23:12 +0530 Subject: [PATCH] add unicode replace function for table --- blocks/code/code.js | 4 ++-- scripts/scripts.js | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/blocks/code/code.js b/blocks/code/code.js index 631a1183d0..9a7bfce353 100644 --- a/blocks/code/code.js +++ b/blocks/code/code.js @@ -1,5 +1,5 @@ import { decorateIcons } from "../../scripts/aem.js"; -import { decoratePlaceholder } from "../../scripts/scripts.js"; +import { decodeHtmlSymbols, decoratePlaceholder } from "../../scripts/scripts.js"; import { mobileHeaderAnalytics } from "./code-analytics.js"; import { decorateTable } from "./table.js"; export default async function decorate(block) { @@ -9,7 +9,7 @@ export default async function decorate(block) { decorateTable(block) return block } - const titleData = block.children[0]?.querySelector('p')?.innerHTML.trim().replaceAll('<', '<').replaceAll('>', '>') || ''; + const titleData = decodeHtmlSymbols(block.children[0]?.querySelector('p')?.innerHTML.trim() || ''); block.innerHTML = ''; if (titleData) { const titleElement = document.createElement('div'); diff --git a/scripts/scripts.js b/scripts/scripts.js index f140d7f5cc..4a1cf79d49 100644 --- a/scripts/scripts.js +++ b/scripts/scripts.js @@ -547,6 +547,15 @@ export function decorateAnchorTag(main) { } } +export function decodeHtmlSymbols(str) { + // Create a temporary DOM element + let textarea = document.createElement('textarea'); + // Set the input string as the element's inner HTML + textarea.innerHTML = str; + // The browser automatically decodes any HTML entities in the innerHTML property + return textarea.value; +} + function scrollToComponentNearBranch(component) { if (window.matchMedia('(max-width: 767px)').matches) { window.scroll({