Skip to main content

Convert Markdown and HTML to WhatsApp-compatible formatting

Project description

WhatsApp Formatter

A Python library for bidirectional conversion between WhatsApp, Markdown, and HTML formatting.

Installation

pip install py-whatsapp-formatter

Usage

Convert to WhatsApp Format

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_"

Convert from WhatsApp Format

from whatsapp_formatter import convert_whatsapp_to_markdown, convert_whatsapp_to_html

# Convert WhatsApp to Markdown format
text = convert_whatsapp_to_markdown("*Bold* and _italic_ and ~strikethrough~")
# Output: "**Bold** and *italic* and ~~strikethrough~~"

# Convert WhatsApp to HTML format
text = convert_whatsapp_to_html("*Bold* and _italic_ and ~strikethrough~")
# Output: "<strong>Bold</strong> and <em>italic</em> and <del>strikethrough</del>"

WhatsApp Formatting Reference

Format WhatsApp 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``` <pre><code>

All conversions are bidirectional. Nested formatting is supported (e.g., *_bold and italic_*).

Advanced Usage

For more control, use the converter classes directly:

from whatsapp_formatter import (
    MarkdownToWhatsAppConverter,
    HTMLToWhatsAppConverter,
    WhatsAppToMarkdownConverter,
    WhatsAppToHTMLConverter,
)

# Custom Markdown converter with post-processing
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>")

# WhatsApp to Markdown
converter = WhatsAppToMarkdownConverter()
result = converter.convert("*bold* _italic_ ~strike~")
# Output: "**bold** *italic* ~~strike~~"

# WhatsApp to HTML (with optional line break conversion)
converter = WhatsAppToHTMLConverter(include_line_breaks=True)
result = converter.convert("*bold*\n_italic_")
# Output: "<strong>bold</strong><br>\n<em>italic</em>"

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.4.tar.gz (7.8 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.4-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: py_whatsapp_formatter-1.0.4.tar.gz
  • Upload date:
  • Size: 7.8 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.4.tar.gz
Algorithm Hash digest
SHA256 8fcd4632c4ca3bcbdd16a080ec6a58bc9a4ac3770fbcf584275072738dbdc93d
MD5 170ebe61030bddf1f653faae878601e8
BLAKE2b-256 e3d02bb7189c475f7461d361f114da80b427ff6075cd41d66a76df68b2a7f6f3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_whatsapp_formatter-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 29543cdb7a7e1c05fac689ae853b3026988c9d551d670947dff3a69f087b30bc
MD5 074e6598a7c8ecc558db710c1efb6108
BLAKE2b-256 89eb7f903fc0f16fdb888ac3d44467b26656b5cf24118481f6f433d1394683a5

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