Metadata-Version: 2.4
Name: mdto-messages
Version: 0.3.1
Summary: Convert LLM Markdown to WhatsApp, Telegram entities, Slack Block Kit, Discord, Teams and email HTML.
Project-URL: Homepage, https://mdtochat.com
Project-URL: Documentation, https://github.com/jmeinke/mdto-messages/blob/main/docs/api.md
Project-URL: Changelog, https://github.com/jmeinke/mdto-messages/blob/main/CHANGELOG.md
Project-URL: Issues, https://github.com/jmeinke/mdto-messages/issues
Project-URL: Repository, https://github.com/jmeinke/mdto-messages
Author: Jerome Meinke
License-Expression: MIT
License-File: LICENSE
Keywords: agent,ai,block-kit,chatbot,discord,html-email,llm,markdown,markdown-converter,microsoft-teams,signal,slack,telegram,telegram-bot,telegram-entities,threema,viber,whatsapp
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Communications :: Chat
Classifier: Topic :: Communications :: Email
Classifier: Topic :: Text Processing :: Markup :: Markdown
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: idna<4,>=3.10
Requires-Dist: markdown-it-py<5,>=4.3.0
Requires-Dist: mdit-py-plugins<0.7,>=0.6.1
Description-Content-Type: text/markdown

# mdto-messages for Python

Convert a Markdown draft into text for a chat composer, safe HTML for email, or JSON-ready request bodies for messaging APIs. Conversion runs locally. Python 3.10 or newer is required.

## Install

```sh
python -m pip install mdto-messages
```

[PyPI versions](https://pypi.org/project/mdto-messages/) · [Source repository](https://github.com/jmeinke/mdto-messages)

## Convert a draft

```python
from mdto_messages import convert, to_messages

draft = convert("Please **review**.", "whatsapp")
assert draft.text == "Please *review*."

message = to_messages("😀 **Ready**", "telegram").messages[0]
assert message["entities"] == [{"type": "bold", "offset": 3, "length": 5}]
```

`convert(markdown, target="plaintext")` returns `text`, optional `html`, `format`, `target`, and `diagnostics`. Draft targets are `plaintext`, `html`, `email`, `whatsapp`, `threema`, `viber`, `google-chat`, `signal`, `discord`, `telegram`, `slack`, and `teams`.

`to_messages(markdown, target)` returns an ordered list of message bodies in `messages`, plus `diagnostics`. API targets are `whatsapp`, `threema`, `viber`, `google-chat`, `discord`, `telegram`, `slack`, and `teams`. Each body can be passed to `json.dumps`. Slack bodies include a per-message `text` fallback for notifications and screen readers. It escapes Slack control characters, abbreviates previews that exceed 3,900 UTF-16 units after escaping, and adds part numbers to multipart replies. The rich-text blocks retain the full message. The caller provides delivery, credentials and recipient information.

Both functions accept keyword-only `policy` and `max_input_length`. The default `readable` policy preserves paragraph spacing. `compact` reduces spacing, and `strict` raises an error when formatting must be simplified. Diagnostics describe each adjustment with a stable `code`, `severity`, and suggested `action`. The default limit is 32,768 UTF-16 code units. Set a value from 1 through 131,072 to adjust it. Rendering and platform-specific size limits also apply.

Catch `ConversionError` and check `exc.code`: `INVALID_INPUT` denotes invalid Markdown input or options, `UNKNOWN_TARGET` an unsupported target, `LIMIT` an exceeded resource or payload bound, and `LOSS` an adjustment that strict policy rejects.

Try the browser tools for [chat drafts](https://mdtochat.com), [email](https://mdtoemail.com), and [plain text](https://mdtoplaintext.com).
