Skip to content

Instantly share code, notes, and snippets.

@Whitecx
Created April 18, 2023 19:08
Show Gist options
  • Save Whitecx/b6de8a0cd6886e308c593fa5b689a6e3 to your computer and use it in GitHub Desktop.
Save Whitecx/b6de8a0cd6886e308c593fa5b689a6e3 to your computer and use it in GitHub Desktop.
Render ChatGPT HTML
// 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(/&lt;/g, '<').replace(/&gt;/g, '>');
codeElement.innerHTML = codeHTML;
});
@Whitecx
Copy link
Author

Whitecx commented Apr 18, 2023

Ask ChatGPT to write something in a single file using html, css, and js, and then render it within the code block

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment