Convert Markdown to a format usable by Telegram.
Project description
telegramify-markdown
🪄 Python Telegram markdown Converter | No more worrying about formatting.
Raw Markdown -> Telegram MarkdownV2 Style
Before this repo came along, when you wanted to send and render unknown Markdown content (like GitHub's Readme), you had to use complex parsing and reconstruction methods. Today, you can make it easier and customize it to achieve better results!
I used a custom Render to achieve this, using a real environment server to verify the applicability of this tool.
Installation
pip install telegramify-markdown
or if you use pdm
:
pdm add telegramify-markdown
Supported Input
- Headings (1-6)
-
Links [text](url)
-
Images ![alt]
- Lists (Ordered, Unordered)
-
Tables |-|-|
-
Horizontal Rule ----
-
*Text* **Styles**
-
__Underline__
(ifcustomize.strict_markdown
is False) - Code Blocks
-
Inline Code
-
Block Quotes >
-
~~Strikethrough~~
- Task Lists
-
~Strikethrough~
- ||Spoiler||
- Tg Emoji
- Tg User At
[!NOTE] Since mistletoe doesn't parse
- [] TODO
and Spoiler, we can't apply it.~Strikethrough~
is incorrect, even if it comes from telegram official documentation, its cant 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.convert(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
Hashes for telegramify_markdown-0.1.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 132cbf3a4fcc1accd19e097c35c36738b9e1fe6b92c47bf5ffa331a01585edae |
|
MD5 | 1de5eb58fbb2e026cc65406238ad80f3 |
|
BLAKE2b-256 | 846883e8ca2cdf08f47466891196532ea8463d80564b5ee4efc99b8ea3444234 |
Hashes for telegramify_markdown-0.1.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76fe989c00399206400477eef3464b375ab6779b73132b8ccc023923ced5cbbd |
|
MD5 | 62f906be9c0f1182f2a450532c699e9c |
|
BLAKE2b-256 | 17922680dd541f5bd95d1b9db3672420695e15c274c716ded061b7e83e436220 |