Compress HTML CSS and Java Script of a page. Passes all original unittests.
>>> import htmlcompressor
>>> htmlcompressor.compress('''
...<html>
... <head>
... <title> Test </title>
... <script type="text/javascript"> alert(1) </script>
... <script type="text/javascript"> alert(2); </script>
... </head>
... <body>
... <style type="text/css"> .class { display: none; } </style>
... </body>
...</html>
... ''')
'<html><head><title>Test</title><script>alert(1);alert(2)</script></head><body><style>.class{display:none}</style></body></html>'
>>> import htmlcompressor
>>> @htmlcompressor.decorator()
>>> def index():
>>> return '''
...<html>
... <head>
... <title> Test </title>
... <script type="text/javascript"> alert(1) </script>
... <script type="text/javascript"> alert(2); </script>
... </head>
... <body>
... <style type="text/css"> .class { display: none; } </style>
... </body>
...</html>
... '''
>>> index()
'<html><head><title>Test</title><script>alert(1);alert(2)</script></head><body><style>.class{display:none}</style></body></html>'
Use pip
or easy_install
:
$ pip install htmlcompressor
Use py.test to run unittests