mdto-messages 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,8 @@
1
+ node_modules/
2
+ dist/
3
+ *.tgz
4
+
5
+ .venv/
6
+ __pycache__/
7
+ .ruff_cache/
8
+ *.py[cod]
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jerome Meinke
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,66 @@
1
+ Metadata-Version: 2.4
2
+ Name: mdto-messages
3
+ Version: 0.1.0
4
+ Summary: Offline Markdown conversion for messaging and email
5
+ Project-URL: Homepage, https://github.com/jmeinke/mdto-messages
6
+ Project-URL: Issues, https://github.com/jmeinke/mdto-messages/issues
7
+ Project-URL: Repository, https://github.com/jmeinke/mdto-messages
8
+ Author: Jerome Meinke
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: chatbot,llm,markdown,slack,telegram,whatsapp
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Programming Language :: Python :: 3 :: Only
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Topic :: Text Processing :: Markup :: Markdown
17
+ Classifier: Typing :: Typed
18
+ Requires-Python: >=3.10
19
+ Requires-Dist: idna<4,>=3.10
20
+ Requires-Dist: markdown-it-py<5,>=4.3.0
21
+ Requires-Dist: mdit-py-plugins<0.7,>=0.6.1
22
+ Description-Content-Type: text/markdown
23
+
24
+ # mdto-messages for Python
25
+
26
+ 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.
27
+
28
+ ## Install
29
+
30
+ For a published PyPI version, install with:
31
+
32
+ ```sh
33
+ python -m pip install mdto-messages
34
+ ```
35
+
36
+ [PyPI versions](https://pypi.org/project/mdto-messages/) · [Source repository](https://github.com/jmeinke/mdto-messages)
37
+
38
+ To install directly from GitHub:
39
+
40
+ ```sh
41
+ python -m pip install "mdto-messages @ git+https://github.com/jmeinke/mdto-messages.git#subdirectory=packages/python"
42
+ ```
43
+
44
+ To install from a local checkout, run `python -m pip install ./packages/python` at the repository root.
45
+
46
+ ## Convert a draft
47
+
48
+ ```python
49
+ from mdto_messages import convert, to_messages
50
+
51
+ draft = convert("Please **review**.", "whatsapp")
52
+ assert draft.text == "Please *review*."
53
+
54
+ message = to_messages("😀 **Ready**", "telegram").messages[0]
55
+ assert message["entities"] == [{"type": "bold", "offset": 3, "length": 5}]
56
+ ```
57
+
58
+ `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`.
59
+
60
+ `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.
61
+
62
+ 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.
63
+
64
+ 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.
65
+
66
+ Try the browser tools for [chat drafts](https://mdtochat.com), [email](https://mdtoemail.com), and [plain text](https://mdtoplaintext.com).
@@ -0,0 +1,43 @@
1
+ # mdto-messages for Python
2
+
3
+ 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.
4
+
5
+ ## Install
6
+
7
+ For a published PyPI version, install with:
8
+
9
+ ```sh
10
+ python -m pip install mdto-messages
11
+ ```
12
+
13
+ [PyPI versions](https://pypi.org/project/mdto-messages/) · [Source repository](https://github.com/jmeinke/mdto-messages)
14
+
15
+ To install directly from GitHub:
16
+
17
+ ```sh
18
+ python -m pip install "mdto-messages @ git+https://github.com/jmeinke/mdto-messages.git#subdirectory=packages/python"
19
+ ```
20
+
21
+ To install from a local checkout, run `python -m pip install ./packages/python` at the repository root.
22
+
23
+ ## Convert a draft
24
+
25
+ ```python
26
+ from mdto_messages import convert, to_messages
27
+
28
+ draft = convert("Please **review**.", "whatsapp")
29
+ assert draft.text == "Please *review*."
30
+
31
+ message = to_messages("😀 **Ready**", "telegram").messages[0]
32
+ assert message["entities"] == [{"type": "bold", "offset": 3, "length": 5}]
33
+ ```
34
+
35
+ `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`.
36
+
37
+ `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.
38
+
39
+ 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.
40
+
41
+ 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.
42
+
43
+ Try the browser tools for [chat drafts](https://mdtochat.com), [email](https://mdtoemail.com), and [plain text](https://mdtoplaintext.com).
@@ -0,0 +1,38 @@
1
+ [build-system]
2
+ requires = ["hatchling==1.28.0"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "mdto-messages"
7
+ version = "0.1.0"
8
+ license = "MIT"
9
+ license-files = ["LICENSE"]
10
+ readme = "README.md"
11
+ requires-python = ">=3.10"
12
+ description = "Offline Markdown conversion for messaging and email"
13
+ authors = [{ name = "Jerome Meinke" }]
14
+ keywords = ["markdown", "chatbot", "llm", "telegram", "slack", "whatsapp"]
15
+ classifiers = [
16
+ "Development Status :: 3 - Alpha",
17
+ "Programming Language :: Python :: 3 :: Only",
18
+ "Programming Language :: Python :: 3.10",
19
+ "Programming Language :: Python :: 3.12",
20
+ "Typing :: Typed",
21
+ "Topic :: Text Processing :: Markup :: Markdown",
22
+ ]
23
+ dependencies = [
24
+ "idna>=3.10,<4",
25
+ "markdown-it-py>=4.3.0,<5",
26
+ "mdit-py-plugins>=0.6.1,<0.7",
27
+ ]
28
+
29
+ [project.urls]
30
+ Homepage = "https://github.com/jmeinke/mdto-messages"
31
+ Issues = "https://github.com/jmeinke/mdto-messages/issues"
32
+ Repository = "https://github.com/jmeinke/mdto-messages"
33
+
34
+ [tool.hatch.build.targets.wheel]
35
+ packages = ["src/mdto_messages"]
36
+
37
+ [tool.hatch.build.targets.sdist]
38
+ include = ["src/mdto_messages", "README.md", "LICENSE", "pyproject.toml"]
@@ -0,0 +1,33 @@
1
+ """Offline Markdown conversion and message bodies."""
2
+
3
+ from .core import ConversionError, Result, convert, parse_document
4
+ from .diagnostics import DIAGNOSTICS
5
+ from .document import Document, Node
6
+ from .messages import to_messages
7
+ from .types import (
8
+ Batch,
9
+ Diagnostic,
10
+ DiagnosticCode,
11
+ MessageBody,
12
+ MessageTarget,
13
+ Policy,
14
+ Target,
15
+ )
16
+
17
+ __all__ = [
18
+ "DIAGNOSTICS",
19
+ "Batch",
20
+ "ConversionError",
21
+ "Diagnostic",
22
+ "DiagnosticCode",
23
+ "Document",
24
+ "MessageBody",
25
+ "MessageTarget",
26
+ "Node",
27
+ "Policy",
28
+ "Result",
29
+ "Target",
30
+ "convert",
31
+ "parse_document",
32
+ "to_messages",
33
+ ]
@@ -0,0 +1,34 @@
1
+ from .core import ConversionError, Result, convert
2
+ from .types import Policy, Target
3
+
4
+
5
+ class DraftBuffer:
6
+ """Single-consumer UTF-8 buffer. Finish once to convert the complete draft."""
7
+
8
+ def __init__(self):
9
+ self._data = bytearray()
10
+ self._closed = False
11
+
12
+ def append(self, chunk: bytes) -> None:
13
+ if self._closed or not isinstance(chunk, bytes):
14
+ raise ConversionError("INVALID_INPUT")
15
+ if len(self._data) + len(chunk) > 131072:
16
+ raise ConversionError("LIMIT")
17
+ self._data.extend(chunk)
18
+
19
+ def finish(
20
+ self,
21
+ target: Target = "plaintext",
22
+ *,
23
+ policy: Policy = "readable",
24
+ ) -> Result:
25
+ if self._closed:
26
+ raise ConversionError("INVALID_INPUT")
27
+ self._closed = True
28
+ try:
29
+ text = self._data.decode("utf-8")
30
+ except UnicodeDecodeError:
31
+ raise ConversionError("INVALID_INPUT") from None
32
+ finally:
33
+ self._data.clear()
34
+ return convert(text, target, policy=policy)