
Security News
NIST Under Federal Audit for NVD Processing Backlog and Delays
As vulnerability data bottlenecks grow, the federal government is formally investigating NISTβs handling of the National Vulnerability Database.
chatgpt-md-converter
Advanced tools
This project provides a solution for converting Telegram-style 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.
**text**
β <b>text</b>
*text*
or _text_
β <i>text</i>
__text__
β <u>text</u>
~~text~~
β <s>text</s>
||text||
β <span class="tg-spoiler">text</span>
`code`
β <code>code</code>
[text](URL)
β <a href="URL">text</a>
> text
β <blockquote>text</blockquote>
**> text
β <blockquote expandable>text</blockquote>
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 backticks 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.
pip install chatgpt-md-converter
from chatgpt_md_converter import telegram_format
# Basic formatting example
text = """
Here is some **bold**, __underline__, and `inline code`.
This is a ||spoiler text|| and *italic*.
Code example:
print('Hello, world!')
"""
# Blockquotes example
blockquote_text = """
> Regular blockquote
> Multiple lines
**> Expandable blockquote
> Hidden by default
> Multiple lines
"""
formatted_text = telegram_format(text)
formatted_blockquote = telegram_format(blockquote_text)
print(formatted_text)
print(formatted_blockquote)
Here is some <b>bold</b>, <u>underline</u>, and <code>inline code</code>.
This is a <span class="tg-spoiler">spoiler text</span> and <i>italic</i>.
Code example:
print('Hello, world!')
<blockquote>Regular blockquote
Multiple lines</blockquote>
<blockquote expandable>Expandable blockquote
Hidden by default
Multiple lines</blockquote>
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.
Note: Since standard Markdown doesn't include Telegram-specific features like spoilers (
||text||
) and expandable blockquotes (**> text
), you'll need to explicitly instruct LLMs to use these formats. Here's a suggested prompt addition to include in your system message or initial instructions:
When formatting your responses for Telegram, please use these special formatting conventions:
1. For content that should be hidden as a spoiler (revealed only when users click):
Use: ||spoiler content here||
Example: This is visible, but ||this is hidden until clicked||.
2. For lengthy explanations or optional content that should be collapsed:
Use: **> Expandable section title
> Content line 1
> Content line 2
> (Each line of the expandable blockquote should start with ">")
3. Continue using standard markdown for other formatting:
- **bold text**
- *italic text*
- __underlined text__
- ~~strikethrough~~
- `inline code`
- ```code blocks```
- [link text](URL)
Apply spoilers for:
- Solution reveals
- Potential plot spoilers
- Sensitive information
- Surprising facts
Use expandable blockquotes for:
- Detailed explanations
- Long examples
- Optional reading
- Technical details
- Additional context not needed by all users
You can add this prompt to your system message when initializing your ChatGPT interactions to ensure the model properly formats content for optimal display in Telegram.
FAQs
A package for converting markdown to HTML for chat Telegram bots
We found that chatgpt-md-converter demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Β It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
As vulnerability data bottlenecks grow, the federal government is formally investigating NISTβs handling of the National Vulnerability Database.
Research
Security News
Socketβs Threat Research Team has uncovered 60 npm packages using post-install scripts to silently exfiltrate hostnames, IP addresses, DNS servers, and user directories to a Discord-controlled endpoint.
Security News
TypeScript Native Previews offers a 10x faster Go-based compiler, now available on npm for public testing with early editor and language support.