Convert Markdown and HTML to WhatsApp-compatible formatting
Project description
WhatsApp Formatter
A Python library to convert Markdown and HTML to WhatsApp-compatible formatting.
Installation
pip install py-whatsapp-formatter
Usage
from whatsapp_formatter import convert_markdown_to_whatsapp, convert_html_to_whatsapp
# Convert Markdown to WhatsApp format
text = convert_markdown_to_whatsapp("**Bold** and *italic* and ~~strikethrough~~")
# Output: "*Bold* and _italic_ and ~strikethrough~"
# Convert HTML to WhatsApp format
text = convert_html_to_whatsapp("<strong>Bold</strong> <em>italic</em>")
# Output: "*Bold* _italic_"
WhatsApp Formatting Reference
| Format | WhatsApp Syntax | Markdown | HTML |
|---|---|---|---|
| Bold | *text* |
**text** |
<b>, <strong> |
| Italic | _text_ |
*text* |
<i>, <em> |
| Strikethrough | ~text~ |
~~text~~ |
<s>, <strike>, <del> |
| Monospace | `text` |
`text` |
<code> |
| Code block | ```text``` |
```text``` |
- |
Advanced Usage
For more control, use the converter classes directly:
from whatsapp_formatter import MarkdownToWhatsAppConverter, HTMLToWhatsAppConverter
# Custom Markdown converter
converter = MarkdownToWhatsAppConverter()
converter.add_post_processor(lambda x: x.strip())
result = converter.convert(" **Hello** ")
# HTML converter without tag stripping
converter = HTMLToWhatsAppConverter(strip_remaining_tags=False)
result = converter.convert("<b>Bold</b> <span>kept</span>")
Requirements
- Python 3.9+
- No external dependencies
License
MIT License
Project details
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 py_whatsapp_formatter-1.0.2.tar.gz.
File metadata
- Download URL: py_whatsapp_formatter-1.0.2.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e79460b8910ba45533e3e0ea56416649304af4069c9db4e984d5ec2e89de850
|
|
| MD5 |
0d77a2627e648bee1f709ddcb68924d8
|
|
| BLAKE2b-256 |
803fe44f8d17f9311bf75daf9f37958644385b540bd63d8165d5f089159ae12f
|
File details
Details for the file py_whatsapp_formatter-1.0.2-py3-none-any.whl.
File metadata
- Download URL: py_whatsapp_formatter-1.0.2-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fe06bb58fc97236ad103d1b50bfbb1154bc23942305fba0c61ba91ed63990277
|
|
| MD5 |
d24372cc8b1cbfa0aea9e0a303e8b0ea
|
|
| BLAKE2b-256 |
bd713ed6f8dfe4311512f85a428c0ad0e5783ef311a5c64b49bd44a8215c6053
|