feat(markdown-parser): added support for custom emojis
This commit is contained in:
parent
34f783aa66
commit
7eb843dd20
2 changed files with 15 additions and 2 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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<tl.RawMessageEntityMentionName>
|
||||
).userId = userId
|
||||
}
|
||||
} else if ((m = EMOJI_REGEX.exec(url))) {
|
||||
;(
|
||||
ent as tl.Mutable<tl.RawMessageEntityCustomEmoji>
|
||||
)._ = 'messageEntityCustomEmoji'
|
||||
;(
|
||||
ent as tl.Mutable<tl.RawMessageEntityCustomEmoji>
|
||||
).documentId = Long.fromString(m[1])
|
||||
} else {
|
||||
if (url.match(/^\/\//)) url = 'http:' + url
|
||||
;(ent as tl.Mutable<tl.RawMessageEntityTextUrl>)._ =
|
||||
|
|
Loading…
Reference in a new issue