mark up text @mdsvex/plugin-emoji
Emoji
Emoji shortcodes, :tada: becomes the emoji, with an optional accessible label
Install
pnpm add -D @mdsvex/plugin-emoji@next Turn it on
import { emoji } from '@mdsvex/plugin-emoji';
mdsvex({ plugins: [emoji()] }); What it reads
:tada:reads text as it is written
An example
We shipped it :tada: and nobody was paged :+1:
We shipped it 🎉 and nobody was paged 👍
Turns a shortcode into its emoji:
We shipped it :tada: and nobody was paged :+1:<p>We shipped it 🎉 and nobody was paged 👍</p>The shortcodes are the ones GitHub uses, 1913 names for 1870 emoji. The table is part of the package, built from gemoji (MIT), so there is nothing else to install.
A shortcode is replaced in prose and nowhere else: not in code, math, a url, the value of an attribute or an {expression}. What is not a shortcode stays as you wrote it:
- a name the table does not have, such as
:not_an_emoji: - a name that touches a letter or a digit, so
10:30:00and1:100:1are safe although:100:is an emoji - a shortcode you escaped,
\:tada: - an inline directive,
:tada[text], whose name is followed by a bracket and not a colon
emoji({
table: Record<string, string>,
extend: Record<string, string | null>,
label: boolean | ((emoji: string, name: string | undefined) => string | undefined),
attrs: Record<string, string>
});extendadds shortcodes to the table, replaces one of the same name, and takes one out withnull:{ shipit: '...', 100: null }.tableis the whole table in place of the built in one.labelwraps each emoji in a<span>with a name for a screen reader.trueuses the Unicode name of the emoji, and a function gives the name, for a page that is not in English. Emoji you typed as characters are wrapped as well:
emoji({ label: true });<p>We shipped it <span role="img" aria-label="party popper">🎉</span></p>attrsare attributes for a<span>around each emoji, such as a class, with or without a label.
It writes the character and adds no image set, and emoticons such as :) are left alone. A heading id is made from what you wrote, so ## Done :tada: gets done-tada. The plugin reads the finished tree, so put it after a plugin that turns urls into links, such as references with linkify.