Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@FireNeslo
Last active January 2, 2018 01:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FireNeslo/e9c9be191ce90b8f7005 to your computer and use it in GitHub Desktop.
Save FireNeslo/e9c9be191ce90b8f7005 to your computer and use it in GitHub Desktop.
Simple es6 heredoc thingy
var html = heredoc `
<section>
<h1> title</h1>
<p>content</p>
</section>
`
function leastSpaces(length, line) {
if(!line.length) return length
var spaces = line.match(/^\s+/).pop().length
return spaces < length ? spaces : length
}
function heredoc(strings) {
var lines = strings.join('').split(/\r?\n/)
var spaces = lines.reduce(leastSpaces, Infinity)
return lines.map(line => line.substring(spaces)).join('\n')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment