From 53b008f8bc8560c424284732d12c85bad43e2298 Mon Sep 17 00:00:00 2001 From: Alina Sireneva Date: Mon, 18 Sep 2023 03:40:20 +0300 Subject: [PATCH] fix: support `` and `tg-spoiler` in html parser --- packages/html-parser/README.md | 30 +++++++++++++++--------------- packages/html-parser/src/index.ts | 6 ++++-- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/packages/html-parser/README.md b/packages/html-parser/README.md index c21dcf7e..cd28519c 100644 --- a/packages/html-parser/README.md +++ b/packages/html-parser/README.md @@ -35,23 +35,23 @@ of features is documented below: Line breaks are **not** preserved, `
` is used instead, 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 are entities that are in-line with other text. We support these entities: -| Name | Code | Result (visual) | -|------------------|-------------------------------------------|------------------------------| -| Bold | `text` | **text** | -| Italic | `text` | _text_ | -| Underline | `text` | text | -| Strikethrough | `text` | ~~text~~ | -| Spoiler | `text` | N/A | -| Monospace (code) | `text` | `text` | -| Text link | `Google` | [Google](https://google.com) | -| Text mention | `Name` | N/A | -| Custom emoji | `😄` | N/A | +| Name | Code | Result (visual) | +| ---------------- | ---------------------------------------------------------------- | ---------------------------- | +| Bold | `text` | **text** | +| Italic | `text` | _text_ | +| Underline | `text` | text | +| Strikethrough | `text` | ~~text~~ | +| Spoiler | `text` (or `tg-spoiler`) | N/A | +| Monospace (code) | `text` | `text` | +| Text link | `Google` | [Google](https://google.com) | +| Text mention | `Name` | N/A | +| Custom emoji | `😄` (or ``) | N/A | > **Note**: ``, ``, ``, ``, `` 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: > `Name`, 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. ## Block entities @@ -74,10 +74,10 @@ Optionally, language for `
` block can be specified like this:
 ```
 
 > 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)              |
-|-------------------------------------------------------------------------------------|------------------------------|
+| ----------------------------------------------------------------------------------- | ---------------------------- |
 | 
<pre>multiline\ntext</pre>
|
multiline
text
| |
<pre language="javascript">
export default 42
</pre>
|
export default 42
| diff --git a/packages/html-parser/src/index.ts b/packages/html-parser/src/index.ts index e7e89cb2..6e45b5db 100644 --- a/packages/html-parser/src/index.ts +++ b/packages/html-parser/src/index.ts @@ -188,6 +188,7 @@ export class HtmlMessageEntityParser implements IMessageEntityParser { } break case 'spoiler': + case 'tg-spoiler': entity = { _: 'messageEntitySpoiler', offset: plainText.length, @@ -195,8 +196,9 @@ export class HtmlMessageEntityParser implements IMessageEntityParser { } break - case 'emoji': { - const id = attribs.id + case 'emoji': + case 'tg-emoji': { + const id = attribs.id || attribs['emoji-id'] if (!id || !id.match(/^-?\d+$/)) return entity = {