I am using django templating, and for readability I have html that looks similar to the following:
{% if some_variable %}
text
{% else %}
nothing exi
Looking around I just found django-pipeline, I just tried, by now, the middleware and it's just what I'm expected. It minify all html and text nodes and keep javascript nodes untouched.
Middleware implementation and basic test result is about 4 minutes, just pip install and activate the middleware after you gzip middleware or on top of your MIDDLEWARE_CLASSES setting.
https://github.com/cyberdelia/django-pipeline
http://django-pipeline.readthedocs.org/en/latest/