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 Distribution

py_whatsapp_formatter-1.0.1.tar.gz (5.5 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.1-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: py_whatsapp_formatter-1.0.1.tar.gz
  • Upload date:
  • Size: 5.5 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.1.tar.gz
Algorithm Hash digest
SHA256 04c81fc66bd9cd49f761838685b6184fd2a749b1d2ff5d70d4dda9a1e94d73e1
MD5 1bee4715f8f20531bc0e4855c7fbf41e
BLAKE2b-256 d2489446734c041023647de71eca890536a5a938d53a82b81093f220f344a8e2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_whatsapp_formatter-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f84c19949b7b3b4c977add78f750f13372b4351bc41ea66dabb16e4f252a06c8
MD5 40f76ac3199f161f210450e6a43aacc2
BLAKE2b-256 1fda7b57b35a222554fd64facd9ba143bf71a2d25a985ee1317cdbbd495303bc

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