Parse minimal HTML-like markup into ANSI-styled terminal output
Project description
html2term
html2term is a lightweight Python library that converts minimal HTML-like markup into ANSI-styled terminal output. It supports text styles, colors (including truecolor hex), layout tags, and nested formatting, all with zero external dependencies and full cross-platform compatibility.
✨ Features
- Text Styles:
<b>,<i>,<u>,<strike>,<blink>. - Semantic Tags:
<strong>(bold) and<em>(italic). - 16 Standard Colors:
<red>,<green>,<bg-blue>, etc. - Truecolor (24-bit): Hex color support like
<#RRGGBB>and<bg-#RRGGBB>. - Layout: Line breaks (
<br>) and tabs (<tab>). - Nested Tags:
<b><red>Important!</red></b>works as expected. - Cross-Platform: Works on Windows, macOS, and Linux.
- Zero Dependencies: Only uses the Python standard library.
💾 Installation
Install html2term directly from PyPI:
pip install html2term
🚀 Usage
The package provides a simple function printc to parse and print styled text directly to your terminal.
from html2term import printc
# --- Basic Usage ---
printc("<b>Hello, <green>World</green>!</b>")
printc("<i>This is <u>very</u> important information.</i>")
# --- Nested Styles ---
printc("<b>This is bold, but <red>this part is also red.</red></b>")
# --- Hex Colors (Truecolor) ---
printc("<#ff00ff>This is magenta text.</#ff00ff>")
printc("<bg-#003366>Dark blue background.</bg-#003366>")
printc("<b><#ffff00>Combine styles with hex colors!</#ffff00></b>")
# --- Layout ---
printc("First line.<br/>Second line.")
printc("Column 1<tab/>Column 2")
You can also use the convert() function if you need the raw string with ANSI codes.
from html2term import convert
ansi_string = convert("<b><blue>I am a string</blue></b>")
print(ansi_string)
# Output: '\x1b[1m\x1b[34mI am a string\x1b[0m\x1b[1m\x1b[0m'
🏷️ Supported Tags
Styles
<b>,<strong>- Bold<i>,<em>- Italic<u>- Underline<strike>- Strikethrough<blink>- Blinking text
Foreground Colors
- Standard:
black,red,green,yellow,blue,magenta,cyan,white,default - Hex:
<#RRGGBB>(e.g.,<#ff7f50>)
Background Colors
- Standard:
bg-black,bg-red,bg-green, etc. - Hex:
<bg-#RRGGBB>(e.g.,<bg-#0a0a0a>)
Layout
<br>,<br/>,<br />- Newline<tab>,<tab/>,<tab />- Tab character
🤝 Contributing
Contributions, issues, and feature requests are welcome! Feel free to check the issues page.
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
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 html2term-1.0.0.tar.gz.
File metadata
- Download URL: html2term-1.0.0.tar.gz
- Upload date:
- Size: 10.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8e9b09e5190fd0bef9c6013cc846527cd0ed3a2ea83fe8c1baf597aa39e6b23b
|
|
| MD5 |
f13c592d0cff2ff644d1e8a4b25485fb
|
|
| BLAKE2b-256 |
f2a81a280672c79d997c1dd5a421fa360c0d50780427a725f6c2679a69887aec
|
File details
Details for the file html2term-1.0.0-py3-none-any.whl.
File metadata
- Download URL: html2term-1.0.0-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a41573b0f4bcd06f4cd86046fc842ff4384f3f62790482eaad98eda46c08ab4a
|
|
| MD5 |
a12a65dc2bedd031d143796268ed17a2
|
|
| BLAKE2b-256 |
fd0fde90a8485f58c69475f1ebe54ee2b0f6e13e374cf65d0fec4ed297f3cefc
|