Handling whitespace in ES6 template literals
In this blog post, we look at problems that arise when template literals contain whitespace: Breaking up long lines Dedenting content Joining Arrays Indenting inserted content I’m using the library common-tags by Declan de Wet (with “useful template literal tags for dealing with strings in ES6”) to demonstrate solutions for some of these problems. Breaking up long lines Occasionally, you have long lines that you want to break up. common-tag’s tag function oneLine lets you do that: console.log(oneLine` a single line with many words `); // a single line with many words Dedenting content Template literals let you embed multi-line text content inside JavaScript. The main challenge is that the text must both have proper indentation and fit nicely into its JavaScript surroundings: function foo() { console.log(`<ul> <li>first</li> <li>second</li> </ul>`); } This does not look good...