Skip to content

Commit

Permalink
fixed color invalid html tags with handler in doll_script using pattt…
Browse files Browse the repository at this point in the history
…ern matching
  • Loading branch information
lele394 committed Sep 5, 2024
1 parent d9448c2 commit 9b2b574
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions pages/js/doll_script.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,36 @@ document.addEventListener('DOMContentLoaded', async () => {











// Once all is done, adapt color tags from invalid HTML to valid colors

// Select all elements containing the custom <color> tags
// Get all the elements that contain text where the <color> tag might be used
const elements = document.querySelectorAll("p");

elements.forEach(element => {
console.log("Parsing color tags");
// Get the innerHTML of the element
let htmlContent = element.innerHTML;
console.log(htmlContent);

// Replace all <color=#XXXXXX>text</color> with <span style="color:#XXXXXX">text</span>
htmlContent = htmlContent.replace(/&lt;color=#([A-Fa-f0-9]{6})&gt;(.*?)&lt;\/color&gt;/g, (match, colorCode, textContent) => {
return `<span style="color:#${colorCode}">${textContent}</span>`;
});

// Update the element's innerHTML
element.innerHTML = htmlContent;
});




});
Expand Down

0 comments on commit 9b2b574

Please sign in to comment.