This project provides a solution for converting Markdown formatted text into HTML markup supported by the Telegram Bot API, specifically tailored for use in ChatGPT bots developed with the OpenAI API. It includes features for handling various Markdown elements and ensures proper tag closure, making it suitable for streaming mode applications.
<pre><code>
tags.To use the Markdown to Telegram HTML Parser in your ChatGPT bot, integrate the provided Python functions into your bot's processing pipeline. Here is a brief overview of how to incorporate the parser:
Ensure Closing Delimiters: Automatically appends missing closing delimiters for `
and ```
to ensure proper parsing.
Extract and Convert Code Blocks: Extracts Markdown code blocks, converts them to HTML <pre><code>
format, and replaces them with placeholders to prevent formatting within code blocks.
Markdown to HTML Conversion: Applies various regex substitutions and custom logic to convert supported Markdown formatting to Telegram-compatible HTML tags.
Reinsert Code Blocks: Reinserts the previously extracted and converted code blocks back into the main text, replacing placeholders with the appropriate HTML content.
Simply call the telegram_format(text: str) -> str
function with your Markdown-formatted text as input to receive the converted HTML output ready for use with the Telegram Bot API.
You can install the package using pip:
pip install chatgpt-md-converter
from chatgpt_md_converter import telegram_format
formatted_text = telegram_format("Here is some **bold**, __underline__, and `inline code`.\n```python\nprint('Hello, world!')\n```")
print(formatted_text)
re
module for regex operations)Feel free to contribute to this project by submitting pull requests or opening issues for bugs, feature requests, or improvements.