diff --git a/source/html.test.ts b/source/html.test.ts index f910122..d87a351 100644 --- a/source/html.test.ts +++ b/source/html.test.ts @@ -21,6 +21,20 @@ test("underline", () => { strictEqual(format.underline("underline"), "underline"); }); +test("blockquote", () => { + strictEqual( + format.blockquote("blockquote"), + "
blockquote", + ); +}); + +test("blockquote multiline", () => { + strictEqual( + format.blockquote("blockquote\nmultiline"), + "
blockquote\nmultiline", + ); +}); + test("spoiler", () => { strictEqual( format.spoiler("spoiler"), @@ -28,6 +42,13 @@ test("spoiler", () => { ); }); +test("tgEmoji", () => { + strictEqual( + format.tgEmoji("👍", "5368324170671202286"), + '
${text}`; +} + /** Format the input text as spoiler */ export function spoiler(text: string): string { return `${text}`; } +/** Create a custom Telegram Emoji. + * + * A valid emoji must be used as the fallback. The emoji will be shown instead of the custom emoji in places where a custom emoji cannot be displayed (e.g., system notifications) or if the message is forwarded by a non-premium user. It is recommended to use the emoji from the emoji field of the custom emoji sticker. + * Custom emoji entities can only be used by bots that purchased additional usernames on Fragment. + */ +export function tgEmoji(fallback: string, emojiId: string): string { + return `
${escape(text)}
`;
diff --git a/source/markdown.test.ts b/source/markdown.test.ts
index 408e282..b09c304 100644
--- a/source/markdown.test.ts
+++ b/source/markdown.test.ts
@@ -71,6 +71,14 @@ test("underline", () => {
throws(() => format.underline("1337"));
});
+test("blockquote", () => {
+ throws(() => format.blockquote("1337"));
+});
+
test("spoiler", () => {
throws(() => format.spoiler("1337"));
});
+
+test("tgEmoji", () => {
+ throws(() => format.tgEmoji("👍", "5368324170671202286"));
+});
diff --git a/source/markdown.ts b/source/markdown.ts
index 5201b21..a2b48c2 100644
--- a/source/markdown.ts
+++ b/source/markdown.ts
@@ -30,6 +30,13 @@ export function underline(_text: string): string {
);
}
+/** unsupported by Telegram. Use MarkdownV2 or HTML instead @deprecated */
+export function blockquote(_text: string): string {
+ throw new Error(
+ "blockquote is not supported by Markdown. Use MarkdownV2 instead.",
+ );
+}
+
/** unsupported by Telegram. Use MarkdownV2 or HTML instead @deprecated */
export function spoiler(_text: string): string {
throw new Error(
@@ -37,6 +44,13 @@ export function spoiler(_text: string): string {
);
}
+/** unsupported by Telegram. Use MarkdownV2 or HTML instead @deprecated */
+export function tgEmoji(_fallback: string, _emojiId: string): string {
+ throw new Error(
+ "tgEmoji is not supported by Markdown. Use MarkdownV2 instead.",
+ );
+}
+
/** Format the input text as monospace */
export function monospace(text: string): string {
return "`" + text.replace(/`/g, "") + "`";
diff --git a/source/markdownv2.test.ts b/source/markdownv2.test.ts
index 19264fb..4e963e4 100644
--- a/source/markdownv2.test.ts
+++ b/source/markdownv2.test.ts
@@ -21,10 +21,28 @@ test("underline", () => {
strictEqual(format.underline("underline"), "__underline__");
});
+test("blockquote", () => {
+ strictEqual(format.blockquote("blockquote"), ">blockquote");
+});
+
+test("blockquote multiline", () => {
+ strictEqual(
+ format.blockquote("blockquote\nmultiline"),
+ ">blockquote\n>multiline",
+ );
+});
+
test("spoiler", () => {
strictEqual(format.spoiler("spoiler"), "||spoiler||");
});
+test("tgEmoji", () => {
+ strictEqual(
+ format.tgEmoji("👍", "5368324170671202286"),
+ "![👍](tg://emoji?id=5368324170671202286)",
+ );
+});
+
test("url", () => {
strictEqual(
format.url("me", "https://edjopato.de"),
diff --git a/source/markdownv2.ts b/source/markdownv2.ts
index 8a4d34c..ec2c319 100644
--- a/source/markdownv2.ts
+++ b/source/markdownv2.ts
@@ -30,11 +30,26 @@ export function underline(text: string): string {
return `__${text}__`;
}
+/** Format the input text as blockquote */
+export function blockquote(text: string): string {
+ const lines = text.split("\n");
+ return lines.map((o) => ">" + o).join("\n");
+}
+
/** Format the input text as spoiler */
export function spoiler(text: string): string {
return `||${text}||`;
}
+/** Create a custom Telegram Emoji.
+ *
+ * A valid emoji must be used as the fallback. The emoji will be shown instead of the custom emoji in places where a custom emoji cannot be displayed (e.g., system notifications) or if the message is forwarded by a non-premium user. It is recommended to use the emoji from the emoji field of the custom emoji sticker.
+ * Custom emoji entities can only be used by bots that purchased additional usernames on Fragment.
+ */
+export function tgEmoji(fallback: string, emojiId: string): string {
+ return `![${fallback}](tg://emoji?id=${emojiId})`;
+}
+
/** Format the input text as monospace */
export function monospace(text: string): string {
return "`" + escapeInternal(text, "`") + "`";
diff --git a/source/types.ts b/source/types.ts
index 51c97a8..4fab87e 100644
--- a/source/types.ts
+++ b/source/types.ts
@@ -2,6 +2,8 @@
export interface Formatter {
/** parse_mode which can be used on sendMessage */
parse_mode: "HTML" | "Markdown" | "MarkdownV2";
+ /** Format the input text as blockquote */
+ blockquote: (text: string) => string;
/** Format the input text bold */
bold: (text: string) => string;
/** Escape the input text to be displayed as it is */
@@ -16,6 +18,8 @@ export interface Formatter {
spoiler: (text: string) => string;
/** Strikethrough the input text */
strikethrough: (text: string) => string;
+ /** Create a custom Telegram Emoji */
+ tgEmoji: (fallback: string, emojiId: string) => string;
/** Underline the input text */
underline: (text: string) => string;
/** Create an url with a label text */