line-markdown-parser 0.1.2__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.
- line_markdown_parser-0.1.2/CHANGELOG.md +20 -0
- line_markdown_parser-0.1.2/LICENSE +21 -0
- line_markdown_parser-0.1.2/MANIFEST.in +12 -0
- line_markdown_parser-0.1.2/PKG-INFO +97 -0
- line_markdown_parser-0.1.2/README-ja.md +68 -0
- line_markdown_parser-0.1.2/README.md +68 -0
- line_markdown_parser-0.1.2/_build_backend.py +59 -0
- line_markdown_parser-0.1.2/docs/spec.md +75 -0
- line_markdown_parser-0.1.2/line_markdown_parser/__init__.py +20 -0
- line_markdown_parser-0.1.2/line_markdown_parser/_renderer.py +1565 -0
- line_markdown_parser-0.1.2/line_markdown_parser/converter.py +260 -0
- line_markdown_parser-0.1.2/line_markdown_parser/py.typed +0 -0
- line_markdown_parser-0.1.2/line_markdown_parser.egg-info/PKG-INFO +97 -0
- line_markdown_parser-0.1.2/line_markdown_parser.egg-info/SOURCES.txt +17 -0
- line_markdown_parser-0.1.2/line_markdown_parser.egg-info/dependency_links.txt +1 -0
- line_markdown_parser-0.1.2/line_markdown_parser.egg-info/requires.txt +6 -0
- line_markdown_parser-0.1.2/line_markdown_parser.egg-info/top_level.txt +1 -0
- line_markdown_parser-0.1.2/pyproject.toml +52 -0
- line_markdown_parser-0.1.2/setup.cfg +4 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.2 — 2026-10-18
|
|
4
|
+
|
|
5
|
+
- Publish distributions to PyPI with Trusted Publishing and update installation instructions.
|
|
6
|
+
|
|
7
|
+
## 0.1.1 — 2026-10-18
|
|
8
|
+
|
|
9
|
+
- Avoid excessive parsing time for unfinished links and emphasis.
|
|
10
|
+
- Preserve inline code, brackets in link labels, punctuation-only text, and URL delimiters; reject malformed action URLs.
|
|
11
|
+
- Improve internal-URL checks, archive error reporting, and source-distribution file permissions.
|
|
12
|
+
- Clarify alpha status and simplify usage and contribution guides.
|
|
13
|
+
|
|
14
|
+
## 0.1.0 — 2026-10-18
|
|
15
|
+
|
|
16
|
+
- Initial dependency-free Python library for converting Markdown into LINE Flex Message dictionaries.
|
|
17
|
+
- Support for headings, paragraphs, emphasis, lists, quotes, separators, fenced code, links, and code-style tables.
|
|
18
|
+
- Long-output splitting by source length and rendered bubble size, preserving recognized links.
|
|
19
|
+
- UTF-16-bounded alternative text and a 200,000-byte UTF-8 input limit.
|
|
20
|
+
- APIs for complete messages, body components, text splitting, and rendered-size estimation.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 line-markdown-parser contributors
|
|
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,12 @@
|
|
|
1
|
+
include LICENSE README.md README-ja.md CHANGELOG.md
|
|
2
|
+
include _build_backend.py
|
|
3
|
+
include docs/spec.md
|
|
4
|
+
recursive-include line_markdown_parser *.py py.typed
|
|
5
|
+
prune tests
|
|
6
|
+
prune scripts
|
|
7
|
+
prune examples
|
|
8
|
+
prune .github
|
|
9
|
+
prune .private
|
|
10
|
+
prune docs/_internal
|
|
11
|
+
exclude CONTRIBUTING.md SECURITY.md AGENTS.md
|
|
12
|
+
global-exclude __pycache__ *.py[cod] .DS_Store
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: line-markdown-parser
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: Convert LLM Markdown into readable LINE Flex Messages without runtime dependencies.
|
|
5
|
+
Author: line-markdown-parser contributors
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/darkgaldragon/line-markdown-parser
|
|
8
|
+
Project-URL: Source, https://github.com/darkgaldragon/line-markdown-parser
|
|
9
|
+
Project-URL: Issues, https://github.com/darkgaldragon/line-markdown-parser/issues
|
|
10
|
+
Keywords: line,markdown,flex-message,llm,chatbot
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
25
|
+
Requires-Dist: ruff>=0.11; extra == "dev"
|
|
26
|
+
Requires-Dist: build>=1.2; extra == "dev"
|
|
27
|
+
Requires-Dist: twine>=6; extra == "dev"
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
|
|
30
|
+
# line-markdown-parser
|
|
31
|
+
|
|
32
|
+
Convert LLM Markdown into readable LINE Flex Message dictionaries with no runtime dependencies.
|
|
33
|
+
|
|
34
|
+
[日本語](README-ja.md)
|
|
35
|
+
|
|
36
|
+
Headings, paragraphs, lists, quotes, code, and links receive a chat-friendly layout. Long output is split into separate messages. Sending remains the responsibility of your application.
|
|
37
|
+
|
|
38
|
+
## Installation
|
|
39
|
+
|
|
40
|
+
Requires Python 3.10 or later.
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
python -m pip install line-markdown-parser
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Quick start
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
import json
|
|
50
|
+
|
|
51
|
+
from line_markdown_parser import convert_markdown_to_line_messages
|
|
52
|
+
|
|
53
|
+
markdown = """# Project update
|
|
54
|
+
|
|
55
|
+
The **first draft** is ready.
|
|
56
|
+
|
|
57
|
+
- Review the examples
|
|
58
|
+
- Read the [guide](https://example.com/guide)
|
|
59
|
+
"""
|
|
60
|
+
|
|
61
|
+
messages = convert_markdown_to_line_messages(markdown)
|
|
62
|
+
print(json.dumps(messages, ensure_ascii=False, indent=2))
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Each item has `type: "flex"`, `altText`, and one `bubble` in `contents`. Pass these dictionaries to your LINE API integration. The library makes no network requests and does not require the LINE SDK.
|
|
66
|
+
|
|
67
|
+
The converter returns all generated messages. LINE accepts up to five message objects per [reply](https://developers.line.biz/en/reference/messaging-api/#send-reply-message) or [push](https://developers.line.biz/en/reference/messaging-api/#send-push-message) request, so your application must handle longer results and reply-token restrictions.
|
|
68
|
+
|
|
69
|
+
## API
|
|
70
|
+
|
|
71
|
+
All functions are exported from `line_markdown_parser`.
|
|
72
|
+
|
|
73
|
+
| Function | Purpose |
|
|
74
|
+
| --- | --- |
|
|
75
|
+
| `convert_markdown_to_line_messages` | Split Markdown and return a `list[dict]` of Flex Messages. |
|
|
76
|
+
| `build_flex_message` | Build one message without splitting; reject oversized input. |
|
|
77
|
+
| `build_flex_contents` | Build body components for a custom bubble, without a bubble size check. |
|
|
78
|
+
| `split_long_text` | Return Markdown chunks as a `list[str]`. |
|
|
79
|
+
| `estimate_flex_payload_size` | Measure the rendered bubble's compact UTF-8 JSON size. |
|
|
80
|
+
|
|
81
|
+
The converter defaults to 1,600 source characters and 28,000 rendered bytes per chunk. See the [API specification](docs/spec.md) for signatures, limits, alternative text, and error behavior.
|
|
82
|
+
|
|
83
|
+
## Limitations
|
|
84
|
+
|
|
85
|
+
- Markdown tables use code-style text boxes; column alignment varies by client font.
|
|
86
|
+
- Images appear as labels and links, without fetching or embedding images.
|
|
87
|
+
- Only `http` and `https` links receive URI actions; destinations are not verified.
|
|
88
|
+
- Full CommonMark support, arbitrary nesting, and every code-fence style are outside the scope.
|
|
89
|
+
- This is an alpha release with automated tests. Live LINE delivery and client appearance have not been verified. Check integration with the [Flex Message Simulator](https://developers.line.biz/flex-simulator/) and your target LINE clients.
|
|
90
|
+
|
|
91
|
+
## Contributing
|
|
92
|
+
|
|
93
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for setup and checks, [SECURITY.md](SECURITY.md) for vulnerability reporting, and [CHANGELOG.md](CHANGELOG.md) for release history.
|
|
94
|
+
|
|
95
|
+
## License
|
|
96
|
+
|
|
97
|
+
[MIT](LICENSE). This independent project is not an official LINE product.
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# line-markdown-parser
|
|
2
|
+
|
|
3
|
+
LLMが生成したMarkdownを、LINEで読みやすいFlex Messageの辞書に変換するPythonライブラリです。実行時の外部依存はありません。
|
|
4
|
+
|
|
5
|
+
[English](README.md)
|
|
6
|
+
|
|
7
|
+
見出し、段落、リスト、引用、コード、リンクをチャットに適したレイアウトに変換し、長文を複数メッセージに分割します。送信処理はアプリケーション側で実装してください。
|
|
8
|
+
|
|
9
|
+
## インストール
|
|
10
|
+
|
|
11
|
+
Python 3.10以上が必要です。
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
python -m pip install line-markdown-parser
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## 使い方
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
import json
|
|
21
|
+
|
|
22
|
+
from line_markdown_parser import convert_markdown_to_line_messages
|
|
23
|
+
|
|
24
|
+
markdown = """# プロジェクトの状況
|
|
25
|
+
|
|
26
|
+
**初稿**ができました。
|
|
27
|
+
|
|
28
|
+
- サンプルを確認する
|
|
29
|
+
- [ガイド](https://example.com/guide)を読む
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
messages = convert_markdown_to_line_messages(markdown)
|
|
33
|
+
print(json.dumps(messages, ensure_ascii=False, indent=2))
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
各要素は `type: "flex"`、`altText`、1つの `bubble` を含む `contents` で構成されます。この辞書をLINE APIとの連携処理に渡してください。ライブラリはネットワーク通信を行わず、LINE SDKにも依存しません。
|
|
37
|
+
|
|
38
|
+
変換結果は省略せずすべて返します。LINEの[reply](https://developers.line.biz/ja/reference/messaging-api/#send-reply-message)・[push](https://developers.line.biz/ja/reference/messaging-api/#send-push-message)リクエストで一度に送れるメッセージは最大5件です。これを超える場合の送信方法とリプライトークンの制約には、呼び出し側で対応してください。
|
|
39
|
+
|
|
40
|
+
## API
|
|
41
|
+
|
|
42
|
+
すべての関数は `line_markdown_parser` からインポートできます。
|
|
43
|
+
|
|
44
|
+
| 関数 | 用途 |
|
|
45
|
+
| --- | --- |
|
|
46
|
+
| `convert_markdown_to_line_messages` | Markdownを分割し、Flex Messageの `list[dict]` を返す。 |
|
|
47
|
+
| `build_flex_message` | 分割せずに1件のメッセージを生成する。サイズ超過はエラー。 |
|
|
48
|
+
| `build_flex_contents` | 独自のbubble用に本文コンポーネントを生成する。bubbleのサイズ検査は行わない。 |
|
|
49
|
+
| `split_long_text` | 分割したMarkdownを `list[str]` で返す。 |
|
|
50
|
+
| `estimate_flex_payload_size` | 生成したbubbleをコンパクトなJSONにしたときのUTF-8バイト数を返す。 |
|
|
51
|
+
|
|
52
|
+
既定では、1チャンクあたり元テキスト1,600文字、bubbleのJSONサイズ28,000バイトを上限に分割します。引数、上限値、代替テキスト、エラー条件は[API仕様書](docs/spec.md)を参照してください。
|
|
53
|
+
|
|
54
|
+
## 制約
|
|
55
|
+
|
|
56
|
+
- 表はコード風のテキスト枠で表示します。列の揃い方はクライアントのフォントに依存します。
|
|
57
|
+
- 画像はラベルとリンクで表示し、取得や埋め込みは行いません。
|
|
58
|
+
- URIアクションは `http` と `https` のみに対応します。リンク先の検証は行いません。
|
|
59
|
+
- 完全なCommonMark互換と任意のネストには対応していません。コードフェンスもすべての形式に対応しているわけではありません。
|
|
60
|
+
- 自動テストで検証したアルファ版です。実際のLINEでの送信・表示は未確認のため、導入時に[Flex Message Simulator](https://developers.line.biz/flex-simulator/)と対象のLINEクライアントで確認してください。
|
|
61
|
+
|
|
62
|
+
## 開発への参加
|
|
63
|
+
|
|
64
|
+
開発環境と確認コマンドは [CONTRIBUTING.md](CONTRIBUTING.md)、脆弱性報告は [SECURITY.md](SECURITY.md)、変更履歴は [CHANGELOG.md](CHANGELOG.md) を参照してください。
|
|
65
|
+
|
|
66
|
+
## ライセンス
|
|
67
|
+
|
|
68
|
+
[MIT](LICENSE)。本プロジェクトは独立したOSSであり、LINEの公式製品ではありません。
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# line-markdown-parser
|
|
2
|
+
|
|
3
|
+
Convert LLM Markdown into readable LINE Flex Message dictionaries with no runtime dependencies.
|
|
4
|
+
|
|
5
|
+
[日本語](README-ja.md)
|
|
6
|
+
|
|
7
|
+
Headings, paragraphs, lists, quotes, code, and links receive a chat-friendly layout. Long output is split into separate messages. Sending remains the responsibility of your application.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
Requires Python 3.10 or later.
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
python -m pip install line-markdown-parser
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Quick start
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
import json
|
|
21
|
+
|
|
22
|
+
from line_markdown_parser import convert_markdown_to_line_messages
|
|
23
|
+
|
|
24
|
+
markdown = """# Project update
|
|
25
|
+
|
|
26
|
+
The **first draft** is ready.
|
|
27
|
+
|
|
28
|
+
- Review the examples
|
|
29
|
+
- Read the [guide](https://example.com/guide)
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
messages = convert_markdown_to_line_messages(markdown)
|
|
33
|
+
print(json.dumps(messages, ensure_ascii=False, indent=2))
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Each item has `type: "flex"`, `altText`, and one `bubble` in `contents`. Pass these dictionaries to your LINE API integration. The library makes no network requests and does not require the LINE SDK.
|
|
37
|
+
|
|
38
|
+
The converter returns all generated messages. LINE accepts up to five message objects per [reply](https://developers.line.biz/en/reference/messaging-api/#send-reply-message) or [push](https://developers.line.biz/en/reference/messaging-api/#send-push-message) request, so your application must handle longer results and reply-token restrictions.
|
|
39
|
+
|
|
40
|
+
## API
|
|
41
|
+
|
|
42
|
+
All functions are exported from `line_markdown_parser`.
|
|
43
|
+
|
|
44
|
+
| Function | Purpose |
|
|
45
|
+
| --- | --- |
|
|
46
|
+
| `convert_markdown_to_line_messages` | Split Markdown and return a `list[dict]` of Flex Messages. |
|
|
47
|
+
| `build_flex_message` | Build one message without splitting; reject oversized input. |
|
|
48
|
+
| `build_flex_contents` | Build body components for a custom bubble, without a bubble size check. |
|
|
49
|
+
| `split_long_text` | Return Markdown chunks as a `list[str]`. |
|
|
50
|
+
| `estimate_flex_payload_size` | Measure the rendered bubble's compact UTF-8 JSON size. |
|
|
51
|
+
|
|
52
|
+
The converter defaults to 1,600 source characters and 28,000 rendered bytes per chunk. See the [API specification](docs/spec.md) for signatures, limits, alternative text, and error behavior.
|
|
53
|
+
|
|
54
|
+
## Limitations
|
|
55
|
+
|
|
56
|
+
- Markdown tables use code-style text boxes; column alignment varies by client font.
|
|
57
|
+
- Images appear as labels and links, without fetching or embedding images.
|
|
58
|
+
- Only `http` and `https` links receive URI actions; destinations are not verified.
|
|
59
|
+
- Full CommonMark support, arbitrary nesting, and every code-fence style are outside the scope.
|
|
60
|
+
- This is an alpha release with automated tests. Live LINE delivery and client appearance have not been verified. Check integration with the [Flex Message Simulator](https://developers.line.biz/flex-simulator/) and your target LINE clients.
|
|
61
|
+
|
|
62
|
+
## Contributing
|
|
63
|
+
|
|
64
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for setup and checks, [SECURITY.md](SECURITY.md) for vulnerability reporting, and [CHANGELOG.md](CHANGELOG.md) for release history.
|
|
65
|
+
|
|
66
|
+
## License
|
|
67
|
+
|
|
68
|
+
[MIT](LICENSE). This independent project is not an official LINE product.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"""Setuptools build hooks with anonymous source-archive ownership metadata."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import gzip
|
|
6
|
+
import os
|
|
7
|
+
import stat
|
|
8
|
+
import tarfile
|
|
9
|
+
import tempfile
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
from setuptools import build_meta as _backend
|
|
13
|
+
|
|
14
|
+
build_wheel = _backend.build_wheel
|
|
15
|
+
build_editable = _backend.build_editable
|
|
16
|
+
get_requires_for_build_wheel = _backend.get_requires_for_build_wheel
|
|
17
|
+
get_requires_for_build_sdist = _backend.get_requires_for_build_sdist
|
|
18
|
+
get_requires_for_build_editable = _backend.get_requires_for_build_editable
|
|
19
|
+
prepare_metadata_for_build_wheel = _backend.prepare_metadata_for_build_wheel
|
|
20
|
+
prepare_metadata_for_build_editable = _backend.prepare_metadata_for_build_editable
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _normalize_sdist(path: Path) -> None:
|
|
24
|
+
"""Remove builder account names, numeric IDs, and local archive timestamps."""
|
|
25
|
+
mode = stat.S_IMODE(path.stat().st_mode)
|
|
26
|
+
descriptor, temporary = tempfile.mkstemp(suffix=".tar.gz", dir=path.parent)
|
|
27
|
+
try:
|
|
28
|
+
with os.fdopen(descriptor, "wb") as output:
|
|
29
|
+
with gzip.GzipFile(
|
|
30
|
+
filename="", mode="wb", fileobj=output, mtime=0
|
|
31
|
+
) as compressed:
|
|
32
|
+
with (
|
|
33
|
+
tarfile.open(path, "r:gz") as source,
|
|
34
|
+
tarfile.open(
|
|
35
|
+
fileobj=compressed, mode="w", format=tarfile.PAX_FORMAT
|
|
36
|
+
) as target,
|
|
37
|
+
):
|
|
38
|
+
for member in source.getmembers():
|
|
39
|
+
payload = (
|
|
40
|
+
source.extractfile(member) if member.isfile() else None
|
|
41
|
+
)
|
|
42
|
+
member.uid = member.gid = 0
|
|
43
|
+
member.uname = member.gname = "root"
|
|
44
|
+
member.mtime = 0
|
|
45
|
+
member.pax_headers = {}
|
|
46
|
+
target.addfile(member, payload)
|
|
47
|
+
if payload is not None:
|
|
48
|
+
payload.close()
|
|
49
|
+
os.chmod(temporary, mode)
|
|
50
|
+
os.replace(temporary, path)
|
|
51
|
+
finally:
|
|
52
|
+
if os.path.exists(temporary):
|
|
53
|
+
os.unlink(temporary)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def build_sdist(sdist_directory, config_settings=None):
|
|
57
|
+
name = _backend.build_sdist(sdist_directory, config_settings)
|
|
58
|
+
_normalize_sdist(Path(sdist_directory) / name)
|
|
59
|
+
return name
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# API specification
|
|
2
|
+
|
|
3
|
+
`line-markdown-parser` converts Markdown strings into LINE Flex Message dictionaries without runtime dependencies or network requests. The API below applies to version 0.1.2.
|
|
4
|
+
|
|
5
|
+
## Functions
|
|
6
|
+
|
|
7
|
+
All functions are exported from `line_markdown_parser`. Names beginning with `_` are implementation details.
|
|
8
|
+
|
|
9
|
+
```python
|
|
10
|
+
convert_markdown_to_line_messages(
|
|
11
|
+
text,
|
|
12
|
+
*,
|
|
13
|
+
alt_text=None,
|
|
14
|
+
max_length=1600,
|
|
15
|
+
max_payload_bytes=28000,
|
|
16
|
+
) -> list[dict]
|
|
17
|
+
|
|
18
|
+
build_flex_message(text, *, alt_text=None) -> dict
|
|
19
|
+
build_flex_contents(text) -> list[dict]
|
|
20
|
+
split_long_text(text, max_length=1600, max_payload_bytes=28000) -> list[str]
|
|
21
|
+
estimate_flex_payload_size(text) -> int
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
| Function | Behavior |
|
|
25
|
+
| --- | --- |
|
|
26
|
+
| `convert_markdown_to_line_messages` | Split and render every chunk in input order. Each item contains `type: "flex"`, `altText`, and one bubble in `contents`. Return `[]` for empty or whitespace-only input when other arguments are valid. |
|
|
27
|
+
| `build_flex_message` | Render one message without splitting. Empty or whitespace-only input, or a bubble exceeding 30,000 bytes, raises `ValueError`. |
|
|
28
|
+
| `build_flex_contents` | Return the body component list without a bubble or message wrapper. Empty or whitespace-only input returns `[]`. No splitting or bubble size check; the caller must validate the custom bubble. |
|
|
29
|
+
| `split_long_text` | Return Markdown chunks within both source-length and rendered-byte limits. Empty or whitespace-only input returns `[]` after argument validation. |
|
|
30
|
+
| `estimate_flex_payload_size` | Return the rendered bubble's compact UTF-8 JSON size, including for empty input. |
|
|
31
|
+
|
|
32
|
+
Visual properties and exact component nesting may change without changing this contract.
|
|
33
|
+
|
|
34
|
+
## Limits and splitting
|
|
35
|
+
|
|
36
|
+
- `max_length` is a positive integer measured in Python string characters. It is a source-length limit, not a LINE API character limit.
|
|
37
|
+
- `max_payload_bytes` is an integer from 1 to 30,000. Its default is 28,000, below LINE's [30 KB bubble limit](https://developers.line.biz/en/reference/messaging-api/#flex-message).
|
|
38
|
+
- Booleans, invalid limit values, or budgets too small for a rendered fragment raise `ValueError`. No oversized fragment is returned.
|
|
39
|
+
|
|
40
|
+
The byte budget and size estimator use the bubble's compact JSON with non-ASCII characters encoded directly as UTF-8. They exclude the Flex wrapper, alternative text, recipients, other messages, and HTTP headers. Layout components add overhead, so source length alone does not predict rendered size.
|
|
41
|
+
|
|
42
|
+
Splitting prefers paragraph, line, and word boundaries. Closed triple-backtick code fences are repeated around each fragment, even when splitting a single code line. Other inline formatting may become ordinary text across a split; arbitrary nesting and all fence styles are not preserved.
|
|
43
|
+
|
|
44
|
+
Outside fenced code, recognized URLs and Markdown links remain intact. A link that cannot fit either limit raises `ValueError` instead of producing a partial link. URLs inside fenced code may split as ordinary code text.
|
|
45
|
+
|
|
46
|
+
## Alternative text and input validation
|
|
47
|
+
|
|
48
|
+
`alt_text` supplies notification and chat-list text. When omitted, each message uses its source chunk. Explicit alternative text is reused for every message. Surrounding whitespace is removed; an empty result raises `ValueError`.
|
|
49
|
+
|
|
50
|
+
Alternative text is limited to 1,500 UTF-16 code units. Supplementary Unicode characters count as two units. Truncation includes an ellipsis within that limit and preserves whole Unicode characters.
|
|
51
|
+
|
|
52
|
+
All text arguments must be strings; other types raise `TypeError`. Every public function rejects text exceeding 200,000 UTF-8 bytes with `ValueError`. This also applies to explicit `alt_text` before truncation. Lone surrogate code points raise `ValueError`.
|
|
53
|
+
|
|
54
|
+
## Markdown rendering
|
|
55
|
+
|
|
56
|
+
| Input | Output |
|
|
57
|
+
| --- | --- |
|
|
58
|
+
| Headings and paragraphs | Text with spacing and visual hierarchy. |
|
|
59
|
+
| Emphasis and inline code | Styled text components or spans. |
|
|
60
|
+
| Unordered and ordered lists | List text and indentation. |
|
|
61
|
+
| Quotes | Visually separated text. |
|
|
62
|
+
| Horizontal rules | Divider text. |
|
|
63
|
+
| Fenced code and tables | Code-style text boxes; no syntax highlighting or interactive tables. |
|
|
64
|
+
| Links | Labels and supported URI actions. |
|
|
65
|
+
| Images | Labels and links; no fetching or image components. |
|
|
66
|
+
|
|
67
|
+
Full CommonMark conformance, HTML rendering, arbitrary nesting, and exact browser-style layout are outside the scope. Malformed input or unusual fences may render as ordinary text or lose formatting. Table alignment depends on client fonts and display width.
|
|
68
|
+
|
|
69
|
+
Only `http` and `https` receive [URI actions](https://developers.line.biz/en/reference/messaging-api/#uri-action). Unsupported schemes retain their labels without an action. Malformed HTTP(S) destinations and URLs exceeding the action URI length limit remain text. Existing percent escapes and URL delimiters are preserved when encoding destinations. Destinations are not verified.
|
|
70
|
+
|
|
71
|
+
## Integration
|
|
72
|
+
|
|
73
|
+
The converter returns all messages without sending or truncating them. LINE [reply](https://developers.line.biz/en/reference/messaging-api/#send-reply-message) and [push](https://developers.line.biz/en/reference/messaging-api/#send-push-message) requests accept at most five messages. Applications handle batching, reply-token restrictions, authentication, recipients, and retries.
|
|
74
|
+
|
|
75
|
+
Version 0.1.2 is covered by automated tests; live LINE delivery and client rendering have not been verified. Validate integrations using the [Flex Message Simulator](https://developers.line.biz/flex-simulator/), [message validation endpoints](https://developers.line.biz/en/reference/messaging-api/#message-objects), and target LINE clients.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""Markdown to LINE Flex Messages, with no network or SDK dependencies."""
|
|
2
|
+
|
|
3
|
+
from .converter import (
|
|
4
|
+
DEFAULT_MAX_FLEX_PAYLOAD_BYTES,
|
|
5
|
+
build_flex_contents,
|
|
6
|
+
build_flex_message,
|
|
7
|
+
convert_markdown_to_line_messages,
|
|
8
|
+
estimate_flex_payload_size,
|
|
9
|
+
split_long_text,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
__version__ = "0.1.2"
|
|
13
|
+
__all__ = [
|
|
14
|
+
"DEFAULT_MAX_FLEX_PAYLOAD_BYTES",
|
|
15
|
+
"build_flex_contents",
|
|
16
|
+
"build_flex_message",
|
|
17
|
+
"convert_markdown_to_line_messages",
|
|
18
|
+
"estimate_flex_payload_size",
|
|
19
|
+
"split_long_text",
|
|
20
|
+
]
|