Skip to content

Instantly share code, notes, and snippets.

@coolaj86
Last active May 20, 2022 03:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save coolaj86/f617e62f99701072ba4c0d17ba8f6f9d to your computer and use it in GitHub Desktop.
Save coolaj86/f617e62f99701072ba4c0d17ba8f6f9d to your computer and use it in GitHub Desktop.
function escapeHtml(str) {
// TODO more
return str
.replace(/&/g, '&')
.replace(/</g, '&lt;')
.replace(/>/g, '&lt;')
.replace(/'/g, '&#39;')
.replace(/"/g, '&quot;')
;
}
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