A package for converting markdown to HTML for chat Telegram bots
Project description
ChatGPT Markdown to Telegram HTML Parser
Overview
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.
Features
- Converts Markdown syntax to Telegram-compatible HTML.
- Supports inline code, bold, italic, underline, and strikethrough formatting.
- Handles nested bold and italic formatting.
- Converts Markdown links and lists to their HTML equivalents.
- Processes code blocks with optional language specification, preserving formatting within
<pre><code>
tags. - Automatically appends missing closing delimiters for code blocks.
- Escapes HTML special characters to prevent unwanted HTML rendering outside code blocks.
Usage
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 -
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.
Example
formatted_text = telegram_format("Here is some **bold**, __underline__, and `inline code`.\n```python\nprint('Hello, world!')\n```")
print(formatted_text)
Requirements
- Python 3.x
- No external libraries required (uses built-in
re
module for regex operations)
Contribution
Feel free to contribute to this project by submitting pull requests or opening issues for bugs, feature requests, or improvements.
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 chatgpt_md_converter-0.1.0.tar.gz
.
File metadata
- Download URL: chatgpt_md_converter-0.1.0.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6edfcc96178d0d96776dc8155ba012e00ccf0a7833eb5600230e9fe6fa4f4248 |
|
MD5 | 1e7c81fd05a56436e5f13f65cad62494 |
|
BLAKE2b-256 | 9a11a685d52324f0cb5a799a57b3fcea01bb9dbc6d88b9ea7bd325895d52b4b2 |
File details
Details for the file chatgpt_md_converter-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: chatgpt_md_converter-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0043cfe695084259fde51708c8609d928abd7db72044c856053885d329007d63 |
|
MD5 | afa96aa09382a7a6da04f6816b368a86 |
|
BLAKE2b-256 | ff0b03c16c257e9b083b0e229103e716944c4eb823e8889c9b0a4097db2ca3d2 |