Skip to main content

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

py_whatsapp_formatter-1.0.3.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_whatsapp_formatter-1.0.3-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file py_whatsapp_formatter-1.0.3.tar.gz.

File metadata

  • Download URL: py_whatsapp_formatter-1.0.3.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for py_whatsapp_formatter-1.0.3.tar.gz
Algorithm Hash digest
SHA256 b2c1365dd7a85375c040030bc0ee786bad22a1718d5bcdcc950737abbfa93437
MD5 56988e21373816f9250cb2f2896eb2e0
BLAKE2b-256 2e3151be1a7556c690b0d6c694b3308b82009e6a96203d82e5e83a632ff37046

See more details on using hashes here.

File details

Details for the file py_whatsapp_formatter-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for py_whatsapp_formatter-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6d4f1726fd44a794f54511cd617dd07a8a506fadac0c5ad39a277f1228c204ae
MD5 74775137b81599922ff4ed021ba05796
BLAKE2b-256 4264fbc62cf4e6e8697b10f04db78e8fcdefc017a170318f5012e9f09b6370dc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page