Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trim Whitespace #1

Open
lukeed opened this issue Jun 2, 2021 · 0 comments
Open

Trim Whitespace #1

lukeed opened this issue Jun 2, 2021 · 0 comments

Comments

@lukeed
Copy link
Owner

lukeed commented Jun 2, 2021

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.

lukeed added a commit that referenced this issue Jun 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant