cobrateam / django-htmlmin

HTML minifier for Python frameworks (not only Django, despite the name).
http://pypi.python.org/pypi/django-htmlmin
BSD 2-Clause "Simplified" License
542 stars 73 forks source link

need to retain space around inline, inline-block, and comment #151

Open tisdall opened 3 years ago

tisdall commented 3 years ago

Currently django-htmlmin retains space around inline text elements. However, there are other inline/inline-block elements that still render whitespace around them that are currently not handled. Also, comment removal takes spaces outside the comment with it.

examples:

>>> from htmlmin.minify import html_minify
>>> html_minify('''<img src="http://example.com/image.jpg" alt="example">  hi''')
'<html><head></head><body><img alt="example" src="http://example.com/image.jpg"/>hi</body></html>'
>>> html_minify('''name: <input type="text">''')
'<html><head></head><body>name:<input type="text"/></body></html>'
>>> html_minify('''<p>a <!-- --> b</p>''')
'<html><head></head><body><p>ab</p></body></html>'
>>> html_minify('''<em>a <!-- --> b</em>''')  # this works as `em` is a text context
'<html><head></head><body><em>a  b</em></body></html>'
>>> html_minify('''<button> click me  </button>  text after''')
'<html><head></head><body><button>click me</button>text after</body></html>'

Some of these can be fixed by adding attributes to TEXT_FLOW, but they aren't really text elements so naming would probably need adjusting.