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

Whitespace in <pre> and <code> tags in the templates need to be respected. #12

Open
amylo opened this issue Jan 10, 2013 · 3 comments
Open

Comments

@amylo
Copy link

amylo commented Jan 10, 2013

I noticed that any leading or trailing whitespace gets stripped out of templates. That's great and all, except for <pre> and <code> tags that really are useful because of the pre-formatted text.

@aefxx
Copy link
Owner

aefxx commented Jan 10, 2013

Could you provide an example? What exactely are you trying to achieve?

@amylo
Copy link
Author

amylo commented Jan 10, 2013

Say I have a template:

<script type="text/html" id="TplPoem"><![CDATA[
<h3>My poem</h2>
<pre>
Roses are red,
Violets are blue,
Sugar is sweet,
And so are you.
</pre>
]]></script>

When I render this template, I get:

My poem

Roses are red,Violets are blue,Sugar is sweet,And so are you.

What I expect to get:

My poem

Roses are red,
Violets are blue,
Sugar is sweet,
And so are you.

@aefxx
Copy link
Owner

aefxx commented Jan 11, 2013

Ok, I see. I've already figured out a workaround for you but I won't commit the changes,yet, as these might cause issues for people that rely on unit tests (tabs and line-endings now being kept). You are free to patch your copy, though.

On line 132 replace

arr = tmpl.replace(/\s*<!\[CDATA\[\s*|\s*\]\]>\s*|[\r\n\t]/g, '')

with

arr = tmpl.replace(/\s*<!\[CDATA\[\s*|\s*\]\]>\s*/g, '')

On line 138 replace

"out+='" + arr[m].replace(/(\\|["'])/g, '\\$1') + "'" : (arr[m].charAt(1) === '=' ?

with

"out+='" + arr[m].replace(/(\\|["'])/g, '\\$1').replace(/\n/g, '\\n') + "'" : (arr[m].charAt(1) === '=' ?

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

2 participants