Skip to main content

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.3.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

tg_markdown_to_flex-0.3.1.tar.gz (21.1 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

tg_markdown_to_flex-0.3.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (256.1 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

tg_markdown_to_flex-0.3.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (250.5 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

tg_markdown_to_flex-0.3.1-cp313-cp313-macosx_11_0_arm64.whl (223.7 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

tg_markdown_to_flex-0.3.1-cp313-cp313-macosx_10_12_x86_64.whl (226.0 kB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

File details

Details for the file tg_markdown_to_flex-0.3.1.tar.gz.

File metadata

  • Download URL: tg_markdown_to_flex-0.3.1.tar.gz
  • Upload date:
  • Size: 21.1 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

Hashes for tg_markdown_to_flex-0.3.1.tar.gz
Algorithm Hash digest
SHA256 2cf2803d427a723993b1f8655954661158aebb527aa05661c99eb4d4c093eb52
MD5 69c138fcc524ff394631c2b1f3b77752
BLAKE2b-256 059002d3a1ae3dbdeccf4f2b123ad545902cf65908200af11e0daa00a270c725

See more details on using hashes here.

File details

Details for the file tg_markdown_to_flex-0.3.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: tg_markdown_to_flex-0.3.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 256.1 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

Hashes for tg_markdown_to_flex-0.3.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 dde5be4cadd2133362b2b71340204f608560827caf9720dcc1d73a1911924bc2
MD5 adb14bf4a483223ce2d1ebdee114269e
BLAKE2b-256 19aac9206aff653beb83b01c1e15f61636b654c745b1b8d96e35caf93e8040c9

See more details on using hashes here.

File details

Details for the file tg_markdown_to_flex-0.3.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

  • Download URL: tg_markdown_to_flex-0.3.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
  • Upload date:
  • Size: 250.5 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

Hashes for tg_markdown_to_flex-0.3.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 676fb636b8dd8da4554eb509b949fb011e1554d2c2dad1bf6344c477307bcc03
MD5 58e5906dea0748865b6323e1c3bfb308
BLAKE2b-256 ba7f311c7a7c4a90646e75cce3da8c77cdb6b8378aa430597f4ed65440f43e9a

See more details on using hashes here.

File details

Details for the file tg_markdown_to_flex-0.3.1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

  • Download URL: tg_markdown_to_flex-0.3.1-cp313-cp313-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 223.7 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

Hashes for tg_markdown_to_flex-0.3.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ef44489ba8843bfa5184524bc4e9de30a1709bc672bb674350df917d151ce551
MD5 c1b4dd8b6db33b466b5c72b802273177
BLAKE2b-256 c613a1a2d2f8bdd9dcc0787ffac53684e6ac039af9a213052a41399fca59c515

See more details on using hashes here.

File details

Details for the file tg_markdown_to_flex-0.3.1-cp313-cp313-macosx_10_12_x86_64.whl.

File metadata

  • Download URL: tg_markdown_to_flex-0.3.1-cp313-cp313-macosx_10_12_x86_64.whl
  • Upload date:
  • Size: 226.0 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

Hashes for tg_markdown_to_flex-0.3.1-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 c3b353af40af73383efdb802511ec69836304e9a05f9edfcb4b8f743907e9ef6
MD5 93d8902211af99e641b545915dcae05c
BLAKE2b-256 922117c80dc4cff049a4300f8c69614b9ab13c09b24d3187b2dac7db985a2d41

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page