core framework for tgsnake for parsing message.
example :
'**bold**';
it will be
[
'bold',
[
{
offset: 0,
length: 4,
type: 'bold',
},
],
];
Breaking Changes in v2!
In this v2 is not supported gramjs framework by default! Unlike v1 which supports it, in v2 we fully use@tgsnake/core
.
// index.ts
import { Parser } from '@tgsnake/parser'
import { Client } from '@tgsnake/core'
const client = new Client(...)
const entities = Parser.parse('**Hello World**,'markdown')
Parser.toRaw(client, entities);
Parser.fromRaw(TypeMessageEntities);
'**bold**';
'__italic__';
'~~strike~~';
'`code`';
'```pre```';
'[text](link)';
'--underline--';
'||spoiler||';
'>blockquote';
'**>expandable blockquote';
Escaping
for escaping just add backslash (\
) before markdown syntax.
'\\**bold\\**';
'\\__italic\\__';
'\\~~strike\\~~';
'\\`code\\`';
'\\```pre\\```';
'[text]\\(link)';
'\\--underline\\--';
'\\||spoiler\\||';
'\\>blockquote';
'\\**>expandable blockquote';
"<b>bold</b>" || "<strong>bold</strong>"
"<i>italic</i>" || "<em>italic</em>"
"<s>strike</s>" || "<del>strike</del>"
"<code>code</code>"
"<pre><code>pre</code></pre>" || "<pre><code language-javascript >pre</code></pre>"
"<a href="link">text</a>"
"<u>underline</u>"
"<spoiler>spoiler</spoiler>" || "<sp>spoiler</sp>" || "<tg-spoiler>spoiler</tg-spoiler>" || '<span class="tg-spoiler">spoiler</span>'
"<tg-emoji id="1">text<tg-emoji>" || "<span id="1" class="tg-emoji">text<span>"
"<blockquote>blockquote</blockquote>"
"<blockquote expandable>expandable blockquote</blockquote>"
Escaping
for escaping replace <
with <
, >
with &rt;
, &
with &
"<b&rt;bold</b&rt;" || "<strong&rt;bold</strong&rt;"
"<i&rt;italic</i&rt;" || "<em&rt;italic</em&rt;"
"<s&rt;strike</s&rt;" || "<del&rt;strike</del&rt;"
"<code&rt;code</code&rt;"
"<pre&rt;<code&rt;pre</code&rt;</pre&rt;" || "<pre&rt;<code language-javascript &rt;pre</code&rt;</pre&rt;"
"<a href="link"&rt;text</a&rt;"
"<u&rt;underline</u&rt;"
"<spoiler&rt;spoiler</spoiler&rt;" || "<sp&rt;spoiler</sp&rt;" || "<tg-spoiler&rt;spoiler</tg-spoiler&rt;" || '<span class="tg-spoiler"&rt;spoiler</span&rt;'
"<blockquote&rt;blockquote</blockquote&rt;"
Entity Type | Markdown style | HTML style | Description |
---|---|---|---|
Bold | *text* |
<b>text</b> or <strong>text</strong>
|
|
Italic | __text__ |
<i>text</i> or <em>text</em>
|
|
~~text~~ |
<s>text</s> or <del>text</del>
|
||
Code |
`text` |
<code>text</code> |
|
Pre |
```text``` |
<pre><code>text</code></pre> or <pre language-javascript><code>text</code></pre>
|
|
Link | [text](link) |
<a href="link">text</a> |
You can fill the link params with tg://user?id=123456 for mentioning user and tg://emoji?id=123456 for custom emoji. |
Underline | --text-- |
<u>text</u> |
|
Spoiler | ||text|| |
<spoiler>text</spoiler> or <sp>text</sp> or <tg-spoiler>text</tg-spoiler> or <span class="tg-spoiler">text</span>
|
|
Custom Emoji | [text](tg://emoji?id=123456) |
<tg-emoji id="123456">text</tg-emoji> or <emoji id="123456">text</emoji> or <span class="tg-emoji" id="123456">text</span>
|
HTML tag has 2 way to define the emojiId. First using id attribute and seconds use emojiId attribute. |
Blockquote | >text |
<blockquote>text</blockquote> |
Build with