Trim Whitespace
lukeed opened this issue · comments
Luke Edwards commented
Add via template tag modifier. – affects the contents of the enclosed brackets only
Current
console.log(
JSON.stringify(
t.transform(`
{{#expect title}}
<h1>
{{{ title }}}
</h1>
`)
)
);
//=> "import{esc as $$1}from\"tempura/utils\";export default function($$2){var{title}=$$2,x=`\n\t\t\t`;x+=`\n\t\t\t<h1>\n\t\t\t\t${title}\n\t\t\t</h1>\n\t\t`;return x}"
console.log(
JSON.stringify(
t.compile(`
{{#expect title}}
<h1>
{{{ title }}}
</h1>
`)({ title: 'foobar' })
)
);
//=> "\n\t\t\t\n\t\t\t<h1>\n\t\t\t\tfoobar\n\t\t\t</h1>\n\t\t"
Ideal
console.log(
JSON.stringify(
t.transform(`
{{#expect title}}
<h1>
{{{~ title ~}}}
</h1>
`)
)
);
//=> "import{esc as $$1}from\"tempura/utils\";export default function($$2){var{title}=$$2,x=`\n\t\t\t`;x+=`\n\t\t\t<h1>${title}</h1>\n\t\t`;return x}"
console.log(
JSON.stringify(
t.compile(`
{{#expect title}}
<h1>
{{{~ title ~}}}
</h1>
`)({ title: 'foobar' })
)
);
//=> "\n\t\t\t\n\t\t\t<h1>foobar</h1>\n\t\t"
Purging the extra whitespace between HTML tags and/or the ends of the output string would handled by an external utility and/or.trim()
.... or I can bring back the minify
option (linked commit), which only took care of whitespace between HTML tags and newlines.