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,checkedandselected - 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.
Source Distribution
htmlfy-0.1.3.tar.gz
(3.0 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file htmlfy-0.1.3.tar.gz.
File metadata
- Download URL: htmlfy-0.1.3.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.9.1 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.5.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c94162b24e30af5d333c11f848d4c4f11fd82b07531e38c38ddbd81bd00c63c
|
|
| MD5 |
797e1cf4b18347d027594f7a4048f453
|
|
| BLAKE2b-256 |
1a302db9b0d1216e5346555237aa275650a7800e7ab86d6d8812b4ea7289f735
|
File details
Details for the file htmlfy-0.1.3-py3-none-any.whl.
File metadata
- Download URL: htmlfy-0.1.3-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.9.1 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.5.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bba81521055172c47e3366b612c00d33165d4c7f9334bc8eae3f41b19faa8cfd
|
|
| MD5 |
56ab6284d6c5320bed730eb5f63b2427
|
|
| BLAKE2b-256 |
8cddc8ebefaa482957462286b6f64187fd82319c42f6a6567422ebc4660328c4
|