Convert Markdown to a format usable by Telegram.
Project description
telegramify-markdown
🪄 Python Telegram Markdown Converter | No more formatting headaches.
Convert Raw Markdown to Telegram's MarkdownV2 Style
Introducing a robust Python library that enhances Markdown formatting support in Telegram. This library automatically processes various Markdown inputs, preserving the original formatting without requiring manual escaping. It simplifies your Markdown interactions on Telegram with seamless auto-processing.
Before this library, sending and rendering unknown Markdown content (like GitHub's README files) required complex parsing and reconstruction. Now, you can easily handle this and customize it for better results!
Utilizing a custom renderer, the library has been tested in a real server environment to ensure its efficacy.
For those interested, there is also a Node.js version of the library with the same name: npm:telegramify-markdown
Installation
To install the library, run:
pip install telegramify-markdown
or, if you use pdm
:
pdm add telegramify-markdown
Supported Input
- Headings (Levels 1-6)
-
Links [text](url)
-
Images ![alt](url)
- Lists (Ordered and Unordered)
- Tables
|-|-|
- Horizontal Rules
----
- Text Styles
*Italic*
and**Bold**
- Underline
__Underline__
(ifcustomize.strict_markdown
is False) - Code Blocks
- Inline Code
- Block Quotes
>
- Strikethrough
~~Strikethrough~~
- Task Lists
- Strikethrough
~Strikethrough~
- Spoilers
||Spoiler||
- Telegram Emojis
- Telegram User Mentions
[!NOTE]
Since mistletoe doesn't parse- [ ] TODO
or Spoilers, we can't implement them.
Despite~Strikethrough~
being mentioned in Telegram's official documentation, it can't be parsed as strikethrough.
Use case
import telegramify_markdown
from telegramify_markdown import customize
customize.markdown_symbol.head_level_1 = "📌" # If you want, Customizing the head level 1 symbol
customize.markdown_symbol.link = "🔗" # If you want, Customizing the link symbol
customize.strict_markdown = True # If you want to use __underline__ as underline, set it to False or it will be converted to bold.
markdown_text = """
'\_', '\*', '\[', '\]', '\(', '\)', '\~', '\`', '\>', '\#', '\+', '\-', '\=', '\|', '\{', '\}', '\.', '\!'
_ , * , [ , ] , ( , ) , ~ , ` , > , # , + , - , = , | , { , } , . , !
**bold text**
*bold text*
_italic text_
__underline__
~no valid strikethrough~
~~strikethrough~~
||spoiler||
*bold _italic bold ~~italic bold strikethrough ||italic bold strikethrough spoiler||~~ __underline italic bold___ bold*
__underline italic bold__
[link](https://www.google.com)
- [ ] Uncompleted task list item
- [x] Completed task list item
> Quote
```python
print("Hello, World!")
```
This is `inline code`
1. First ordered list item
2. Another item
- Unordered sub-list.
1. Actual numbers don't matter, just that it's a number
"""
converted = telegramify_markdown.markdownify(markdown_text)
print(converted)
# export Markdown to Telegram MarkdownV2 style.
output as follows:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file telegramify_markdown-0.1.6.tar.gz
.
File metadata
- Download URL: telegramify_markdown-0.1.6.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: pdm/2.15.4 CPython/3.10.12 Linux/6.5.0-1021-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c2369091dad500c0293898cd4075f9f6bbfda590cdc278960ab6794e1af2e4d8 |
|
MD5 | c7253d4615c606577823349a388379ab |
|
BLAKE2b-256 | dcae987a034cb17d68702ea8a68595ec92866bffa1430552d33dc927972e089d |
Provenance
File details
Details for the file telegramify_markdown-0.1.6-py3-none-any.whl
.
File metadata
- Download URL: telegramify_markdown-0.1.6-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: pdm/2.15.4 CPython/3.10.12 Linux/6.5.0-1021-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1346a3731caf705d9b696bd1e63f15cc7ef32a466c1c5153553c1294109c0886 |
|
MD5 | 8a7a787d9ffd6762c3aded9617717ff0 |
|
BLAKE2b-256 | 2648967087f0eb63ac383698ee515042450b7968ba39b48f78b7569427e8d8df |