Metadata-Version: 2.4
Name: mdto-messages
Version: 0.1.0
Summary: Offline Markdown conversion for messaging and email
Project-URL: Homepage, https://github.com/jmeinke/mdto-messages
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: chatbot,llm,markdown,slack,telegram,whatsapp
Classifier: Development Status :: 3 - Alpha
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.12
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

For a published PyPI version, install with:

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

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

To install directly from GitHub:

```sh
python -m pip install "mdto-messages @ git+https://github.com/jmeinke/mdto-messages.git#subdirectory=packages/python"
```

To install from a local checkout, run `python -m pip install ./packages/python` at the repository root.

## 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 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`. 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).
