html
HTML escaping and unescaping library, matching Python’s html module.
Available Functions
| Function | Description |
|---|---|
escape(s) |
Escape &, <, >, " and ' so s can be embedded in HTML. |
unescape(s) |
Convert named and numeric entities (<, <, <) back to characters. |
Example
import html
safe = html.escape("<script>alert('xss')</script>")
print(safe) # <script>alert('xss')</script>
print(html.escape('Say "hi" & bye')) # Say "hi" & bye
print(html.unescape("Tom & Jerry")) # Tom & Jerry
print(html.unescape("<b> "")) # <b> "
original = '<div class="test">Content</div>'
print(html.unescape(html.escape(original)) == original) # TruePython Compatibility
unescape(s)- ✅ Compatibleescape(s, quote=True)- ✅ Compatible
See Also
- html.parser - HTML parsing for extracting tags and data
- string - String constants for character classification
- regex - Regular expressions for text processing