formatter-chatgpt-telegram
v1.0.0
Published
A package for converting markdown to HTML for chat Telegram bots
Maintainers
Readme
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-telegramUsage
import telegramFormat from 'formatter-chatgpt-telegram';
// Your Markdown text
const markdown = `
# Heading
This is _italic_ and **bold** text.
\`\`\`python
def hello():
print("Hello, world!")
\`\`\`
- First list item
- Second list item
`;
// Convert to HTML compatible with Telegram
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
| Markdown | HTML | Result in Telegram |
| ------------------------ | ----------------------------------------- | --------------------------------------- |
| **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
Headers are converted to bold text:
# Header 1
## Header 2
### Header 3Will be converted to:
<b>Header 1</b>
<b>Header 2</b>
<b>Header 3</b>Lists
Unordered lists using * or -:
- First item
- Second itemWill be converted to:
• First item
• Second itemLinks
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 linesWill be converted to:
<blockquote>This is a quote spanning multiple lines</blockquote>Expandable Blockquotes
**> This is an expandable quote
**> spanning multiple linesWill be converted to:
<blockquote expandable>This is an expandable quote spanning multiple lines</blockquote>Development
npm run format # code fomatting
npm run test # testingActive maintenance with care and ❤️.
Feel free to send a PR.
License
MIT
