
ChatGPT Markdown to Telegram HTML Converter - TypeScript
This library is convertation to Typescript of Python version formatter-chatgpt-telegram originally crafted by @Latand
A TypeScript library for converting Markdown to HTML format supported by the Telegram Bot API.
Installation
npm install formatter-chatgpt-telegram
Usage
import telegramFormat from 'formatter-chatgpt-telegram';
const markdown = `
# Heading
This is _italic_ and **bold** text.
\`\`\`python
def hello():
print("Hello, world!")
\`\`\`
- First list item
- Second list item
`;
const html = telegramFormat(markdown);
console.log(html);
Supported Syntax
Code Blocks
Multiline Code Blocks with Language Specification
```python
def hello_world():
print("Hello, World!")
```
Will be converted to:
<pre><code class="language-python">def hello_world():
print("Hello, World!")</code></pre>
Inline Code Blocks
Here is inline `code`.
Will be converted to:
Here is inline <code>code</code>.
Text Styling
**bold text** | <b>bold text</b> | bold text |
__underlined__ | <u>underlined</u> | underlined |
*italic* or _italic_ | <i>italic</i> | italic |
***bold and italic*** | <b><i>bold and italic</i></b> | bold and italic |
___underline italic___ | <u><i>underline italic</i></u> | underline italic |
~~strikethrough~~ | <s>strikethrough</s> | strikethrough |
||spoiler|| | <span class="tg-spoiler">spoiler</span> | spoiler |
Headers are converted to bold text:
# Header 1
## Header 2
### Header 3
Will be converted to:
<b>Header 1</b>
<b>Header 2</b>
<b>Header 3</b>
Lists
Unordered lists using *
or -
:
- First item
- Second item
Will be converted to:
• First item
• Second item
Links
Links are converted to HTML <a>
tags:
[Link text](https://example.com)
Will be converted to:
<a href="https://example.com">Link text</a>
Blockquotes
> This is a quote
> spanning multiple lines
Will be converted to:
<blockquote>This is a quote spanning multiple lines</blockquote>
Expandable Blockquotes
**> This is an expandable quote
**> spanning multiple lines
Will be converted to:
<blockquote expandable>This is an expandable quote spanning multiple lines</blockquote>
Development
npm run format
npm run test
Active maintenance with care and ❤️.
Feel free to send a PR.
License
MIT