quicktemplate
quicktemplate copied to clipboard
Add feature to strip HTML comments
Hi,
it would be very nice to have something like "{% stripcomments %}..." to strip all static HTML comments from templates.
{% stripcomments %}
<!-- Icons -->
<link rel="shortcut icon" href="assets/img/favicons/favicon.png">
{% endstripcomments %}
would become
<link rel="shortcut icon" href="assets/img/favicons/favicon.png">
I'm skeptical about the feature, because it may complicate both implementation and semantics of quicktemplate
without significant benefit.
stripcomments
feature instantly opens the following questions:
- Should the HTML comment be stripped if it contains
quicktemplate
tags?
{% stripcomments %}
<!-- HTML comment with quicktemplate tags
{% for i := 0; i < 10; i++ %}
line {%d i %}
{% endfor %}
-->
foobar
{% endstripcomments %}
- How to handle IE-specific conditional comments?
{% stripcomments %}
Show or hide?
<!--[if IE 8]>
<p>Welcome to Internet Explorer 8.</p>
<![endif]-->
{% endstripcomments %}
- What if HTML comment is generated via
quicktemplate
tags?
{% stripcomments %}
{%s "<!--" %}Should we strip this line?{%s "-->" %}
{% stripcomments %}
I'd suggest using quicktemplate
-specific {% comment %}
tag instead of HTML comments. See also the issue #1 for more options.
My motivation comes from 3rd party templates. e.g. I buy templates on themeforest. they have a lot of comments and for development I would like to keep some of those comments.
I understand that this feature would increase complexity and I saw no easy way to implement it myself, thats why I asked. A workaround for me is to use plain html for design phase and strip comments before converting to quicktemplate. the regexp from #1 is no solutions for me.
But let me answer your questions:
- quicktemplate tags inside comments
Strip everything. If someone wants to generate comments he can't use stripcomments around that code.
- IE conditional comments:
{% stripcomments %}
Show or hide?
{% endstripcomments %}
<!--[if IE 8]>
{% stripcomments %}
<p>Welcome to Internet Explorer 8.</p>
{% endstripcomments %}
<![endif]-->
Or just start using stripcomments after your conditional comments.
- comments generated by quicktemplate tags
I think it depends on the implementation. Keep it simple. Maybe your example is possible. Or like above you have to use stripcomments after that code