Created
April 18, 2023 19:08
-
-
Save Whitecx/b6de8a0cd6886e308c593fa5b689a6e3 to your computer and use it in GitHub Desktop.
Render ChatGPT HTML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Select all code elements containing HTML code snippets | |
const codeElements = document.querySelectorAll('code'); | |
// Loop through each code element | |
codeElements.forEach(codeElement => { | |
// Get the inner HTML of the code element and replace entities | |
let codeHTML = codeElement.innerHTML | |
// Remove the syntax highlighting tags and surrounding quotes using a regular expression | |
codeHTML = codeHTML.replace(/^['"]?<code>|<\/code>['"]?$/g, '').replace(/<[^>]+>/g, ''); | |
codeHTML = codeHTML.replace(/</g, '<').replace(/>/g, '>'); | |
codeElement.innerHTML = codeHTML; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ask ChatGPT to write something in a single file using html, css, and js, and then render it within the code block