-
-
Save thelaarn/333978a24e00ee14a7f66958166bdf03 to your computer and use it in GitHub Desktop.
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
function escapeHtml(str) { | |
// TODO more | |
return str | |
.replace(/&/g, '&') | |
.replace(/</g, '<') | |
.replace(/>/g, '<') | |
.replace(/'/g, ''') | |
.replace(/"/g, '"') | |
; | |
} | |
function html(strs, ...vars) { | |
console.log(strs, vars); | |
let out = []; | |
strs = strs.slice(); | |
for (;strs.length;) { | |
out.push(strs.shift()); | |
if (vars.length) { | |
out.push(escapeHtml(vars.shift())); | |
} | |
} | |
return out.join(''); | |
} | |
let username = 'Bobby <Drop script="tables.js">'; | |
let inline = html`<h1>Hero ${username}</h1>`; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment