Prettierfier
Prettierfier is a Python library designed to intelligently pretty-print HTML/XML strings, specifically addressing the issue of unwanted line breaks that often occur with other tools like BeautifulSoup's `prettify()` method. It focuses on preserving inline tags without introducing extraneous whitespace. The current version is 1.0.3, and its release cadence appears to be inactive, with the last update in 2019, suggesting a stable but unmaintained project.
Warnings
- gotcha This library (prettierfier) is distinct from the popular JavaScript code formatter 'Prettier'. Do not confuse the two; `prettierfier` is for HTML/XML string formatting in Python, while the main Prettier formatter is a multi-language (primarily JS) code formatter with a separate, deprecated Python plugin.
- gotcha The `prettierfier` library's `prettify_html()` function is 'originally created to process BeautifulSoup.prettify() output' and 'does not add or remove regular line breaks' in general HTML if they are not already present. It primarily cleans up whitespace around inline tags, rather than imposing a complete formatting style from scratch.
- deprecated The library has not received updates since version 1.0.3 in July 2019. While it uses only the Python Standard Library, long-term maintenance, compatibility with future Python versions, and community support might be limited.
Install
-
pip install prettierfier
Imports
- prettierfier
import prettierfier
Quickstart
import prettierfier ugly_html = """<p> Introducing GitHub <sup> ® </sup> </p>""" pretty_html = prettierfier.prettify_html(ugly_html) print(pretty_html) ugly_xml = """<root><tag1>Text</tag1><tag2 attr='value'></tag2></root>""" pretty_xml = prettierfier.prettify_xml(ugly_xml, indent=4) print(pretty_xml)