Skip to main content

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 notation disabled,checked and selected
  • 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.

Metadata

Release files for htmlfy 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for htmlfy 0.1.3
File Size Uploaded
htmlfy-0.1.3.tar.gz 3.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for htmlfy 0.1.3
File Interpreter ABI Platform
htmlfy-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 7.5 kB

Release files / htmlfy-0.1.3.tar.gz

Download URL htmlfy-0.1.3.tar.gz
Size 3.0 kB
Tags Source
SHA-256 checksum
How to use checksums
9c94162b24e30af5d333c11f848d4c4f11fd82b07531e38c38ddbd81bd00c63c
BLAKE2b-256 checksum
How to use checksums
1a302db9b0d1216e5346555237aa275650a7800e7ab86d6d8812b4ea7289f735
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / htmlfy-0.1.3-py3-none-any.whl

Download URL htmlfy-0.1.3-py3-none-any.whl
Size 4.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bba81521055172c47e3366b612c00d33165d4c7f9334bc8eae3f41b19faa8cfd
BLAKE2b-256 checksum
How to use checksums
8cddc8ebefaa482957462286b6f64187fd82319c42f6a6567422ebc4660328c4
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page