Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/** @version 0.1 */
const html = (strings, ...values) => (
Array.from(strings).map((string, index) => (
string + (
Array.isArray(values[index])
? values[index].join("")
: (new Option(values[index])).innerHTML
)
)).join('')
)
<script src="safe-html-template-literal.js"></script>
<script>
document.addEventListener("DOMContentLoaded", () => {
document.body.innerHTML = html`
<pre>${"<b>escaped html</b>"}</pre>
<pre>${["<b>unescaped html</b>"]}<pre>
`
})
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.