用于html缩小的python包
htmlf的Python项目详细描述
htmlfy
用于HTML缩小的Python包。
安装
python3 -mpip install htmlfy
用法
在变量
中缩小html标记>>>importhtmlfy>>>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>'
缩小HTML文件
>>>importhtmlfy>>>src_path='my_file.html'>>>dst_path='my_file.min.html'>>>htmlfy.minify_html_file(src_path,dst_path)
参数
defhtmlfy.minify_html(html,strict_spaces=True,no_space_between_tags=True,preserve=True,remove_comments=True,html5_min_attr=True,html5_emptytags=True)defminify_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-将所有空格(新行、制表符等)严格到单个空格。除了保留的块。
- 标记之间没有空格-删除标记之间的所有空格。
- preserve-它将保存
<pre>
、<textarea>
、<script>
标记中的所有格式。它还将保留php表达式,如<?php ... ?>
和<?=...?>
- 删除注释-也从
<style>
和<script>
中删除所有类型的注释,例如<!-- ... -->
、/* ... */
或// comment
。您可以使用<!--! ... -->
格式保存注释。像<!--[if gte IE 7]>...<![endif]-->
这样的表达式注释也将被保留。 - html5最小属性-压缩
disabled="disabled"
、checked="checked"
、selected="selected"
到html5符号disabled
、checked
和selected
- html5_emptyTags-删除空标记中的尾部斜线,如
<br />
、<img ... />
或<input ... />
许可证
版权所有(c)2019,Alexey Schebelev