Skip to content

Instantly share code, notes, and snippets.

@prof3ssorSt3v3
Created December 1, 2025 01:23
Show Gist options
  • Select an option

  • Save prof3ssorSt3v3/a80df5ee9833b6062e3e62b0c828221b to your computer and use it in GitHub Desktop.

Select an option

Save prof3ssorSt3v3/a80df5ee9833b6062e3e62b0c828221b to your computer and use it in GitHub Desktop.
Starter code for a utility file
// Encode: converts '<tags> & "quotes"' to "&lt;tags&gt; &amp; &quot;quotes&quot;"
function encodeHtmlEntitiesDOM(str) {
const div = document.createElement('div');
div.appendChild(document.createTextNode(str));
return div.innerHTML;
}
// Decode: converts "&lt;tags&gt; &amp; &quot;quotes&quot;" back to '<tags> & "quotes"'
function decodeHtmlEntitiesDOM(str) {
const textarea = document.createElement('textarea');
textarea.innerHTML = String(str ?? '');
return textarea.value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment