Skip to main content

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:

  1. Ensure Closing Delimiters: Automatically appends missing closing delimiters for ` and ``` to ensure proper parsing.

  2. 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.

  3. Markdown to HTML Conversion: Applies various regex substitutions and custom logic to convert supported Markdown formatting to Telegram-compatible HTML tags.

  4. 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.

Installation

You can install the package using pip:

pip install chatgpt-md-converter

Example

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)

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chatgpt_md_converter-0.2.0.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

chatgpt_md_converter-0.2.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file chatgpt_md_converter-0.2.0.tar.gz.

File metadata

  • Download URL: chatgpt_md_converter-0.2.0.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for chatgpt_md_converter-0.2.0.tar.gz
Algorithm Hash digest
SHA256 92dad4444813c7e27f047f8a714367e700d45fbf1ef1535eac20d7775fa1d077
MD5 7873411641b4baf65149713135025e35
BLAKE2b-256 17c84c1be7e6f5255153bf1fd3a2983d244b5047abd7adfff221048816b02321

See more details on using hashes here.

Provenance

The following attestation bundles were made for chatgpt_md_converter-0.2.0.tar.gz:

Publisher: publish.yml on Latand/formatter-chatgpt-telegram

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file chatgpt_md_converter-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for chatgpt_md_converter-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 830b0fb51f617bdc7c9da713e3e0a9ec28832a79eb1bfe56d5d82b7a7b557184
MD5 3ed2a9052932a59a7002168490cb2f51
BLAKE2b-256 2dae8e2714ff807fdc628fa77880bf3b83475d664b204a20edcd9431a250f0b8

See more details on using hashes here.

Provenance

The following attestation bundles were made for chatgpt_md_converter-0.2.0-py3-none-any.whl:

Publisher: publish.yml on Latand/formatter-chatgpt-telegram

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page