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~~
- Spoilers
||Spoiler||
- Task Lists
- Strikethrough
~Strikethrough~
- Telegram Emojis
- Telegram User Mentions
[!NOTE]
Since mistletoe doesn't parse- [ ] TODO
, we can't implement it.
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 = """
# Title
## Subtitle
### Subsubtitle
#### Subsubsubtitle
'\_', '\*', '\[', '\]', '\(', '\)', '\~', '\`', '\>', '\#', '\+', '\-', '\=', '\|', '\{', '\}', '\.', '\!'
_ , * , [ , ] , ( , ) , ~ , ` , > , # , + , - , = , | , { , } , . , !
We will remove the \ symbol from the original 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
> Multiline Quote In Markdown it's not possible to send multiline quote in telegram without using code block or html tag but telegramify_markdown can do it.
```python
print("Hello, World!")
```
This is `inline code`
1. First ordered list item
2. Another item
- Unordered sub-list.
- Another item.
1. Actual numbers don't matter, just that it's a number
"""
converted = telegramify_markdown.markdownify(
markdown_text,
max_line_length=None, # If you want to change the max line length for links, images, set it to the desired value.
normalize_whitespace=False
)
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
Hashes for telegramify_markdown-0.1.12.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb1b435e18eb6886e2898595221d5ff3ded841b6b7c21d5b021de7b942144827 |
|
MD5 | c59a41a7c953e1ab0369178c1496bf6f |
|
BLAKE2b-256 | 5873929c4c2fbb87ac833144eef3d203b5eae89bc5879cba912c77f6a89d76a3 |
Hashes for telegramify_markdown-0.1.12-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6661b1fea9fec514268b2e8752274d9fb46ae0a46ea0e77d0438a59e0e1a9b64 |
|
MD5 | 467fba3cd2b8afea915023d36d256694 |
|
BLAKE2b-256 | 17fe10799e56ce9b8af8af6c47c79b0bdefb24c7a023963286d68026accd2f36 |