Convert Telegram MarkdownV2 text to LINE Flex Messages
Project description
tg-markdown-to-flex
Convert Telegram MarkdownV2 text to LINE Flex Messages.
Available as both a Rust crate and a Python package (via PyO3).
What it does
Takes a string with Telegram MarkdownV2 formatting and produces a LINE Flex Message JSON — a bubble with styled text spans, code blocks, and link buttons.
Formatting mapping
| Telegram MarkdownV2 | LINE Flex |
|---|---|
*bold* |
span weight: "bold" |
_italic_ |
span style: "italic" |
__underline__ |
span decoration: "underline" |
~strikethrough~ |
span decoration: "line-through" |
`inline code` |
span with red color, small size |
```code block``` |
separate text component, red/small |
||spoiler|| |
span with near-white color |
[text](url) |
link button (see below) |
Smart link dedup
By default, links at the end of a line are rendered as a button in the message body (with a separator and grey background), avoiding duplication. Links in the middle of text still get an inline blue/underlined span plus a footer button.
This behavior is configurable — see the options below.
Python
Requires Python 3.13+.
Installation
uv add tg-markdown-to-flex
# or
pip install tg-markdown-to-flex
Usage
import json
from tg_markdown_to_flex import tg_markdown_to_flex
flex_json = tg_markdown_to_flex("Hello *bold* and _italic_ with [a link](https://example.com)")
message = json.loads(flex_json)
# Send via LINE Messaging API
# line_bot_api.push_message(to, FlexMessage(alt_text=message["altText"], contents=message["contents"]))
The function returns a JSON string representing a complete Flex Message (type "flex" with altText and contents).
Options
tg_markdown_to_flex(
text,
*,
standalone_links_as_buttons=True, # dedup trailing links as body buttons
decorate_links=True, # blue/underline styling on inline links
)
Type checking
The package ships with PEP 561 type stubs.
Rust
Installation
[dependencies]
tg-markdown-to-flex = "0.2.0"
Usage
use tg_markdown_to_flex::{tg_markdown_to_flex, tg_markdown_to_flex_json};
// Get a FlexMessage struct
let message = tg_markdown_to_flex("Hello *world*");
// Or get JSON directly
let json = tg_markdown_to_flex_json("Hello *world*");
With options:
use tg_markdown_to_flex::{tg_markdown_to_flex_with_options, ConvertOptions};
let options = ConvertOptions {
standalone_links_as_buttons: false,
decorate_links: false,
};
let message = tg_markdown_to_flex_with_options("Hello *world*", &options);
Testing
cargo nextest run
License
MIT
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
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tg_markdown_to_flex-0.2.1.tar.gz.
File metadata
- Download URL: tg_markdown_to_flex-0.2.1.tar.gz
- Upload date:
- Size: 21.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0bebea9242822d488db68080a40f3f4b51456b93f0397d10eb77b15dbb1b0a8f
|
|
| MD5 |
1eb926a4664dedbc524e8a772c73b72a
|
|
| BLAKE2b-256 |
ba7ccdcca9b213228276018a9fc6994ca2a08b5b4d8b0c1f123d4eca44194b3f
|
File details
Details for the file tg_markdown_to_flex-0.2.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: tg_markdown_to_flex-0.2.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 257.9 kB
- Tags: CPython 3.13, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8c854c1735565f81f401f2390d9d8380d7a77188ef0d6492ef9dbd708b04cebb
|
|
| MD5 |
fe2b1f37f64a82532c4a625305ea6c52
|
|
| BLAKE2b-256 |
205150e62ca22c81aa0e69435e6f0bb17a1fad5bb3b4221a4f3748aa426e4e2e
|
File details
Details for the file tg_markdown_to_flex-0.2.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: tg_markdown_to_flex-0.2.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 251.4 kB
- Tags: CPython 3.13, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eeb2e3ab5e24a036703932f119baacf7eeb7649f702181dbffeb96e03442c0bb
|
|
| MD5 |
8b78cad0ed1c278a177d975e91c4a9d8
|
|
| BLAKE2b-256 |
e756c5ab5a1b1e79c68f8d3eec18ec94a225791340dd1e0300cabc89b6ee2a1b
|
File details
Details for the file tg_markdown_to_flex-0.2.1-cp313-cp313-macosx_11_0_arm64.whl.
File metadata
- Download URL: tg_markdown_to_flex-0.2.1-cp313-cp313-macosx_11_0_arm64.whl
- Upload date:
- Size: 225.1 kB
- Tags: CPython 3.13, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
76fbd41c6b2c14bbdce9ff70b6561a2f4b618cd530cf2d13ab8b4833d2a74189
|
|
| MD5 |
e443b129203f473ab9e97564ffa04b31
|
|
| BLAKE2b-256 |
ca690d0e5da0f67da7231d5ca75a954258db5e19b192fcae8c8d2e24c051f1de
|
File details
Details for the file tg_markdown_to_flex-0.2.1-cp313-cp313-macosx_10_12_x86_64.whl.
File metadata
- Download URL: tg_markdown_to_flex-0.2.1-cp313-cp313-macosx_10_12_x86_64.whl
- Upload date:
- Size: 227.5 kB
- Tags: CPython 3.13, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c2d6075c8f0bc51d35ed3c950fc11cd5a21fdfe592aa118c96376555e7b565c
|
|
| MD5 |
7f13470bf6fc356c23cf45affe649b74
|
|
| BLAKE2b-256 |
c264e611c9b6d59e6e3ad33a36f1db2ce2b46aa0e9a56594df140b2b7fba81f7
|