Skip to content

Commit aa6e2aa

Browse files
committed
Support Emoji interpolation in text tag
1 parent 3e3665c commit aa6e2aa

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

docs/concepts/text.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,18 @@ The above code will create a text like this:
138138

139139
> Hello, [@fedify@hollo.social](https://hollo.social/@fedify).
140140
141+
### `Emoji`
142+
143+
*This API is available since BotKit 0.2.0.*
144+
145+
If you put an `Emoji` object (provided by Fedify) inside the interpolation,
146+
it will be rendered as a custom emoji. You usually get `Emoji` objects from
147+
the `Reaction.emoji` property. For example:
148+
149+
~~~~ typescript
150+
text`Here's a custom emoji: ${reaction.emoji}.`
151+
~~~~
152+
141153
### `URL` object
142154

143155
If you put a `URL` object inside the interpolation, it will be rendered as a

src/text.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// along with this program. If not, see <https://www.gnu.org/licenses/>.
1616
import {
1717
type Actor,
18-
type Emoji,
18+
Emoji,
1919
getActorHandle,
2020
isActor,
2121
Link,
@@ -30,7 +30,7 @@ import {
3030
} from "@fedify/markdown-it-mention";
3131
import { escape } from "@std/html/entities";
3232
import MarkdownIt from "markdown-it";
33-
import type { DeferredCustomEmoji } from "./emoji.ts";
33+
import { type DeferredCustomEmoji, emoji } from "./emoji.ts";
3434
import type { Session } from "./session.ts";
3535

3636
/**
@@ -129,6 +129,7 @@ export class TemplatedText<TContextData>
129129
if (isText<TContextData>(v)) return v;
130130
if (v instanceof URL) return link(v);
131131
if (isActor(v)) return mention(v);
132+
if (v instanceof Emoji) return customEmoji(v);
132133
return new PlainText(String(v));
133134
});
134135
}

0 commit comments

Comments
 (0)