Skip to content

Instantly share code, notes, and snippets.

@souporserious
Created March 17, 2026 20:30
Show Gist options
  • Select an option

  • Save souporserious/adfc4c68e5a369bcc54e43504c124ca3 to your computer and use it in GitHub Desktop.

Select an option

Save souporserious/adfc4c68e5a369bcc54e43504c124ca3 to your computer and use it in GitHub Desktop.
/**
* @param {TemplateStringsArray} strings
* @param {...any} values
* @returns {DocumentFragment}
*/
function html(strings, ...values) {
let out = ''
for (let index = 0; index < strings.length; index++) {
out += strings[index]
if (index < values.length) {
const value = values[index]
out +=
value == null
? ''
: Array.isArray(value)
? value.join('')
: String(value)
}
}
const template = document.createElement('template')
template.innerHTML = out.trim()
return template.content
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment