Swaagie / minimize

Minimize HTML
MIT License
162 stars 18 forks source link

Allow some comments #51

Open adam-lynch opened 9 years ago

adam-lynch commented 9 years ago

See https://github.com/murphydanger/gulp-minify-html/issues/27

adam-lynch commented 9 years ago

Nevermind, going with gulp-htmlclean (it accepts regular expressions).

Swaagie commented 9 years ago

Sure feel free to use what you want :) thats why OS is awesome. Re-opening this though as I can easily add this functionality.

adam-lynch commented 9 years ago

:+1:

What would the API look like?

Swaagie commented 9 years ago

I was thinking about a plugin that would allow the comments, have to give it some thought though, don't want to just make it a configurable option, as it is highly opinionated towards Knockout (which is fine, but not for a general HTML minifier ;))

dtipson commented 9 years ago

Have this need as well: would it make sense to allow the ssi option to accept a regex in addition to a boolean that would then protect anything that matches? I'm using this in conjunction with underscore/lodash templates, and if I try to use the spare:true option, then something like <% if (data){ print="foo"; } %> becomes something like <% if="" (data)="" {="" print="foo";="" }="" %>

Swaagie commented 9 years ago

Minimize really shouldn't be used on templates though, only the rendered output of the template should be ran through minimize. In your defence, do you render the template client side/browser as I can see a use case for that? In your example spare won't help as it only works for element attributes not variable assignments

dtipson commented 8 years ago

Yep, in my case of templates, there is no final rendered output: the html templates (plus language specific control code) is intended to be minified (currently using minimize via a gulp task) before being run through a template compiler. Javascript code like value == 5 gets turned into value "==" 5. Would definitely be nice to specify custom ignore delimiters, but I understand if you think that's out of scope of something intended to deal just with compliant html.

Swaagie commented 8 years ago

I dont see why template code needs to be minified before parsing it though? Its just an order of task executions. Compile first, minimize after and you should be fine. The reason the JS code (in case of ejs) is mistakingly minified is because the checks look like HTML attribute assignments. Could you give an example of why the order of execution has to be minimize and then compile?