Skip to content

Commit 63aae92

Browse files
committed
feat: support expandable blockquote and custom emoji
1 parent 346ecee commit 63aae92

File tree

4 files changed

+39
-5
lines changed

4 files changed

+39
-5
lines changed

deno.lock

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mod.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as serialisers from "./serialisers.ts";
22
import * as escapers from "./escapers.ts";
33
import type { Message, TextMessage, Tree, MessageEntity } from "./types.ts";
44

5-
// https://github.com/tdlib/td/blob/d79bd4b69403868897496da39b773ab25c69f6af/td/telegram/MessageEntity.cpp#L39
5+
// https://github.com/tdlib/td/blob/721300bcb4d0f2114505712f4dc6350af1ce1a09/td/telegram/MessageEntity.cpp#L39
66
const TYPE_PRIORITY: Record<MessageEntity["type"], number> = {
77
mention: 50,
88
hashtag: 50,
@@ -22,6 +22,7 @@ const TYPE_PRIORITY: Record<MessageEntity["type"], number> = {
2222
blockquote: 0,
2323
spoiler: 94,
2424
custom_emoji: 99,
25+
expandable_blockquote: 0,
2526
};
2627

2728
function findChildren(fromEntityIndex: number, parent: MessageEntity, entities: MessageEntity[]) {

serialisers.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ export const HTML: Serialiser = (match: string, node?: Node) => {
2525
return `<a href="tg://user?id=${node.user.id}">${match}</a>`;
2626
case "blockquote":
2727
return `<blockquote>${match}</blockquote>`;
28-
case "mention":
28+
case "expandable_blockquote":
29+
return `<blockquote expandable>${match}</blockquote>`;
2930
case "custom_emoji":
31+
return `<tg-emoji emoji-id="${node.custom_emoji_id}">${match}</tg-emoji>`;
32+
case "mention":
3033
case "hashtag":
3134
case "cashtag":
3235
case "bot_command":
@@ -61,9 +64,22 @@ export function MarkdownV2(match: string, node?: Node): string {
6164
case "text_mention":
6265
return `[${match}](tg://user?id=${node.user.id})`;
6366
case "blockquote":
64-
return `${match.split("\n").map((line) => `>${line}`).join("\n")}`;
65-
case "mention":
67+
return match
68+
.split("\n")
69+
.map(line => `>${line}`)
70+
.join("\n");
71+
case "expandable_blockquote":
72+
return (
73+
"**" +
74+
match
75+
.split("\n")
76+
.map(line => `>${line}`)
77+
.join("\n") +
78+
"||"
79+
);
6680
case "custom_emoji":
81+
return `![${match}](tg://emoji?id=${node.custom_emoji_id})`;
82+
case "mention":
6783
case "hashtag":
6884
case "cashtag":
6985
case "bot_command":

types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { MessageEntity } from "https://deno.land/x/telegraf_types@v7.0.1/message.ts";
1+
import type { MessageEntity } from "https://deno.land/x/telegraf_types@v8.3.1/message.ts";
22

33
export type { MessageEntity };
44

0 commit comments

Comments
 (0)