Skip to content

Commit

Permalink
Merge pull request #556 from WWWPiramalFinanceCOM/feature/optimization
Browse files Browse the repository at this point in the history
Feature/optimization
  • Loading branch information
VaibhavSasulkar authored Oct 14, 2024
2 parents 9aaff66 + 4e9b786 commit 24694a0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions blocks/code/code.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -9,7 +9,7 @@ export default async function decorate(block) {
decorateTable(block)
return block
}
const titleData = block.children[0]?.querySelector('p')?.innerHTML.trim().replaceAll('&lt;', '<').replaceAll('&gt;', '>') || '';
const titleData = decodeHtmlSymbols(block.children[0]?.querySelector('p')?.innerHTML.trim() || '');
block.innerHTML = '';
if (titleData) {
const titleElement = document.createElement('div');
Expand Down
9 changes: 9 additions & 0 deletions scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 24694a0

Please sign in to comment.