middleman / middleman-minify-html

A HTML whitespace minifier for Middleman
https://middlemanapp.com/
MIT License
77 stars 13 forks source link

Some content spaces are removed #7

Closed mcoms closed 11 years ago

mcoms commented 11 years ago

The following input:

<h1><a href="./">mysite.com</a> <small>Subtitle</small></h1>
<h2>There's been a problem <small>Error 404</small></h2>

Produces the following output:

<h1><a href="./">mysite.com</a><small>Subtitle</small></h1><h2>There's been a problem <small>Error 404</small></h2>

The space between </a> and <small> is missing, which affects the content of the page. Note the second line is minified correctly, since it doesn't contain a link.

It really messes with Twitter Bootstrap.

/ed: After investigation, this is caused by the following issue: https://github.com/paolochiodi/htmlcompressor/issues/4. Should this gem pass its own set of consistent options?

tdreyno commented 11 years ago

Thanks for reporting that with the upstream project. I'd suggest using &nbsp; as a work-around for spaces you really want to keep which minifying hmtl.

mcoms commented 11 years ago

np!

Sadly &nbsp; won't do it, since it then breaks Bootstrap's responsive features. &ensp; is a no-go too, since many browsers (including webkit) fail to render it properly as a breaking character. Yay!

For now, I took the hit of including extra spaces:

activate :minify_html, remove_intertag_spaces: false
paolochiodi commented 11 years ago

Hi, I closed the issue on htmlcompressor but also reporting my thoughts here. remove_intertag_spaces: true behave as intended. At the moment it is not smart enough to preserve spaces around inline tags and this feature at the moment is not planned. For better clarity I'm going to update the rack middleware in the gem changing remove_intertag_spaces to false as the default option since I think it is safer and the consequences of removing all intertag spaces need to be evaluated by the user

For further considerations please see the referenced issue https://github.com/paolochiodi/htmlcompressor/issues/4

tdreyno commented 11 years ago

Thanks for the clarification, @paolochiodi.

@mcoms, thanks for reporting and debugging, I'm going to close this issue. The solution is documented in this thread and the cost of a couple whitespaces in a world with retina graphics isn't the end of the world.