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 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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

py_whatsapp_formatter-1.0.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for py_whatsapp_formatter-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2a774f5c96037471cffdb449c7ec970924d4862e78b50990d597fdb0252c4e4f
MD5 a9353a297eb0a3839772e9b49276cac0
BLAKE2b-256 b9e035c1e8bb04981877ebd9e7e31e6f66bf2bf78a271b15ab06835d8e69178a

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