Created
November 14, 2017 17:25
-
-
Save aishikaty/dcb6e7f3441c1c8321a34437139bf17f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** @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('') | |
) |
This file contains hidden or 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
<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