diff --git a/packages/markdown-parser/README.md b/packages/markdown-parser/README.md index 50a06d19..885ea391 100644 --- a/packages/markdown-parser/README.md +++ b/packages/markdown-parser/README.md @@ -82,7 +82,10 @@ Defined like this: `[Link text](https://example.com)`. - `[` (opening square bracket) inside link text will be treated like a normal character. A markdown-style link can also be used to define a name mention like this: `[Name](tg://user?id=1234567)`, -where `1234567` is the ID of the user you want to mention +where `1234567` is the ID of the user you want to mention. + +Additionally, a markdown-style link can be used to define a custom emoji like this: +`[😄](tg://emoji?id=123456)`, where `123456` is ID of the emoji. > **Note**: It is up to the client to look up user's input entity by ID. > In most cases, you can only use IDs of users that were seen by the client while using given storage. @@ -98,6 +101,7 @@ where `1234567` is the ID of the user you want to mention | `[empty link]()` | empty link | `empty link` | | `[empty link]` | [empty link] | `[empty link]` | | `[User](tg://user?id=1234567)` | N/A | N/A | +| `[😄](tg://emoji?id=123456)` | N/A | N/A | ### Nested and overlapping entities diff --git a/packages/markdown-parser/src/index.ts b/packages/markdown-parser/src/index.ts index a683b2bb..3178e152 100644 --- a/packages/markdown-parser/src/index.ts +++ b/packages/markdown-parser/src/index.ts @@ -4,6 +4,8 @@ import { FormattedString } from '@mtcute/client' const MENTION_REGEX = /^tg:\/\/user\?id=(\d+)(?:&hash=(-?[0-9a-fA-F]+)(?:&|$)|&|$)/ +const EMOJI_REGEX = + /^tg:\/\/emoji\?id=(-?\d+)/ const TAG_BOLD = '**' const TAG_ITALIC = '__' @@ -160,7 +162,7 @@ export class MarkdownMessageEntityParser implements IMessageEntityParser { if (url.length) { ent.length = result.length - ent.offset - const m = url.match(MENTION_REGEX) + let m = url.match(MENTION_REGEX) if (m) { const userId = parseInt(m[1]) const accessHash = m[2] @@ -187,6 +189,13 @@ export class MarkdownMessageEntityParser implements IMessageEntityParser { ent as tl.Mutable ).userId = userId } + } else if ((m = EMOJI_REGEX.exec(url))) { + ;( + ent as tl.Mutable + )._ = 'messageEntityCustomEmoji' + ;( + ent as tl.Mutable + ).documentId = Long.fromString(m[1]) } else { if (url.match(/^\/\//)) url = 'http:' + url ;(ent as tl.Mutable)._ =