Python package for HTML minification
Project description
htmlfy
Python package for HTML minification.
Installation
python3 -mpip install htmlfy
Usage
Minifing HTML markup in variable
>>> import htmlfy >>> html = """ <!DOCTYPE html> <html> <head> <title>Hello</title> </head> <body> <p>hello, world!</p> </body> </html>""" >>> htmlfy.minify_html(html) '<!DOCTYPE html><html><head><title>Hello</title></head><body><p>hello, world!</p></body></html>'
Minifing HTML file
>>> import htmlfy >>> src_path = 'my_file.html' >>> dst_path = 'my_file.min.html' >>> htmlfy.minify_html_file(src_path,dst_path)
Arguments
def htmlfy.minify_html(html, strict_spaces=True, no_space_between_tags=True, preserve=True, remove_comments=True, html5_min_attr=True, html5_emptytags=True ) def minify_html_file(source_path,minified_path, strict_spaces=True, no_space_between_tags=True, preserve=True, remove_comments=True, html5_min_attr=True, html5_emptytags=True )
- strict_spaces - strict all spaces(new lines, tabs and etc.) to single space. Except preserved blocks.
- no_space_between_tags - delete all spaces between tags.
- preserve - it will save all formating in
<pre>
,<textarea>
,<script>
tags. Also it will keep PHP expresions like<?php ... ?>
and<?=...?>
- remove_comments - delete all types of comments from the code also from
<style>
and<script>
like<!-- ... -->
,/* ... */
or// comment
. You can save the comment using<!--! ... -->
format. Expressions comments like<!--[if gte IE 7]>...<![endif]-->
will be preserved also. - html5_min_attr - shrink
disabled="disabled"
,checked="checked"
,selected="selected"
to HTML5 notationdisabled
,checked
andselected
- html5_emptytags - removes tailing slash in empty tags like
<br />
,<img ... />
or<input ... />
License
Copyright (c) 2019, Alexey Schebelev
Distributed under The BSD 3-Clause License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Filename, size | File type | Python version | Upload date | Hashes |
---|---|---|---|---|
Filename, size htmlfy-0.1.3-py3-none-any.whl (4.5 kB) | File type Wheel | Python version py3 | Upload date | Hashes View |
Filename, size htmlfy-0.1.3.tar.gz (3.0 kB) | File type Source | Python version None | Upload date | Hashes View |