fix: support <tg-emoji>
and tg-spoiler
in html parser
This commit is contained in:
parent
7bf63b2507
commit
53b008f8bc
2 changed files with 19 additions and 17 deletions
|
@ -35,23 +35,23 @@ of features is documented below:
|
||||||
Line breaks are **not** preserved, `<br>` is used instead,
|
Line breaks are **not** preserved, `<br>` is used instead,
|
||||||
making the syntax very close to the one used when building web pages.
|
making the syntax very close to the one used when building web pages.
|
||||||
|
|
||||||
Multiple spaces and indents are collapsed, when you do need multiple spaces use ` ` instead.
|
Multiple spaces and indents are collapsed (except in `pre`), when you do need multiple spaces use ` ` instead.
|
||||||
|
|
||||||
## Inline entities
|
## Inline entities
|
||||||
|
|
||||||
Inline entities are entities that are in-line with other text. We support these entities:
|
Inline entities are entities that are in-line with other text. We support these entities:
|
||||||
|
|
||||||
| Name | Code | Result (visual) |
|
| Name | Code | Result (visual) |
|
||||||
|------------------|-------------------------------------------|------------------------------|
|
| ---------------- | ---------------------------------------------------------------- | ---------------------------- |
|
||||||
| Bold | `<b>text</b>` | **text** |
|
| Bold | `<b>text</b>` | **text** |
|
||||||
| Italic | `<b>text</b>` | _text_ |
|
| Italic | `<b>text</b>` | _text_ |
|
||||||
| Underline | `<u>text</u>` | <u>text</u> |
|
| Underline | `<u>text</u>` | <u>text</u> |
|
||||||
| Strikethrough | `<s>text</s>` | ~~text~~ |
|
| Strikethrough | `<s>text</s>` | ~~text~~ |
|
||||||
| Spoiler | `<spoiler>text</spoiler>` | N/A |
|
| Spoiler | `<spoiler>text</spoiler>` (or `tg-spoiler`) | N/A |
|
||||||
| Monospace (code) | `<code>text</code>` | `text` |
|
| Monospace (code) | `<code>text</code>` | `text` |
|
||||||
| Text link | `<a href="https://google.com">Google</a>` | [Google](https://google.com) |
|
| Text link | `<a href="https://google.com">Google</a>` | [Google](https://google.com) |
|
||||||
| Text mention | `<a href="tg://user?id=1234567">Name</a>` | N/A |
|
| Text mention | `<a href="tg://user?id=1234567">Name</a>` | N/A |
|
||||||
| Custom emoji | `<emoji id="12345">😄</emoji>` | N/A |
|
| Custom emoji | `<emoji id="12345">😄</emoji>` (or `<tg-emoji emoji-id="...">`) | N/A |
|
||||||
|
|
||||||
> **Note**: `<strong>`, `<em>`, `<ins>`, `<strike>`, `<del>` are not supported because they are redundant
|
> **Note**: `<strong>`, `<em>`, `<ins>`, `<strike>`, `<del>` are not supported because they are redundant
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ Inline entities are entities that are in-line with other text. We support these
|
||||||
>
|
>
|
||||||
> Alternatively, you can explicitly provide access hash like this:
|
> Alternatively, you can explicitly provide access hash like this:
|
||||||
> `<a href="tg://user?id=1234567&hash=abc">Name</a>`, where `abc` is user's access hash
|
> `<a href="tg://user?id=1234567&hash=abc">Name</a>`, where `abc` is user's access hash
|
||||||
> written as a base-16 *unsigned* integer. Order of the parameters does matter, i.e.
|
> written as a hexadecimal integer. Order of the parameters does matter, i.e.
|
||||||
> `tg://user?hash=abc&id=1234567` will not be processed as expected.
|
> `tg://user?hash=abc&id=1234567` will not be processed as expected.
|
||||||
|
|
||||||
## Block entities
|
## Block entities
|
||||||
|
@ -74,10 +74,10 @@ Optionally, language for `<pre>` block can be specified like this:
|
||||||
```
|
```
|
||||||
|
|
||||||
> However, since syntax highlighting hasn't been implemented in
|
> However, since syntax highlighting hasn't been implemented in
|
||||||
> official Telegram clients, this doesn't really matter 🤷♀️
|
> official Telegram clients except WebA, this doesn't really matter 🤷♀️
|
||||||
|
|
||||||
| Code | Result (visual) |
|
| Code | Result (visual) |
|
||||||
|-------------------------------------------------------------------------------------|------------------------------|
|
| ----------------------------------------------------------------------------------- | ---------------------------- |
|
||||||
| <pre><pre>multiline\ntext</pre></pre> | <pre>multiline<br>text</pre> |
|
| <pre><pre>multiline\ntext</pre></pre> | <pre>multiline<br>text</pre> |
|
||||||
| <pre><pre language="javascript"><br> export default 42<br></pre></pre> | <pre>export default 42</pre> |
|
| <pre><pre language="javascript"><br> export default 42<br></pre></pre> | <pre>export default 42</pre> |
|
||||||
|
|
||||||
|
|
|
@ -188,6 +188,7 @@ export class HtmlMessageEntityParser implements IMessageEntityParser {
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case 'spoiler':
|
case 'spoiler':
|
||||||
|
case 'tg-spoiler':
|
||||||
entity = {
|
entity = {
|
||||||
_: 'messageEntitySpoiler',
|
_: 'messageEntitySpoiler',
|
||||||
offset: plainText.length,
|
offset: plainText.length,
|
||||||
|
@ -195,8 +196,9 @@ export class HtmlMessageEntityParser implements IMessageEntityParser {
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
|
||||||
case 'emoji': {
|
case 'emoji':
|
||||||
const id = attribs.id
|
case 'tg-emoji': {
|
||||||
|
const id = attribs.id || attribs['emoji-id']
|
||||||
if (!id || !id.match(/^-?\d+$/)) return
|
if (!id || !id.match(/^-?\d+$/)) return
|
||||||
|
|
||||||
entity = {
|
entity = {
|
||||||
|
|
Loading…
Reference in a new issue