Overview
Updated 11 hr ago
@m2d/emoji: Emoji shortcode support for md2docx (@m2d/core). Transforms :shortcode: tokens (such as :smile:, :rocket:, and :tada:) into Unicode emojis during MDAST-to-DOCX conversion.
✨ Why @m2d/emoji?
- 🚀 GitHub-Style Shortcode Support: Converts standard
:shortcode:syntax into Unicode emojis using a built-in lookup table. - 🎨 Extensible & Overridable: Pass custom
emojismappings to add domain-specific shortcodes or override defaults. - 🛡️ Safe In-Place AST Transform: Only targets MDAST
textnodes, leaving inline code and unrecognized shortcodes untouched. - ⚡ Zero-Config Integration: Works seamlessly in browser, Node.js, and edge runtimes alongside
@m2d/core.
📦 Installation
$ pnpm add @m2d/emoji @m2d/core docxor
$ npm install @m2d/emoji @m2d/core docxor
$ yarn add @m2d/emoji @m2d/core docx🚀 Quick Start
import { toDocx } from "@m2d/core";
import { emojiPlugin } from "@m2d/emoji";
import remarkParse from "remark-parse";
import { unified } from "unified";
const markdown = `
# Release Notes :rocket:
Shipped with zero-server AST compilation :tada: :sparkles:
`;
const mdast = unified().use(remarkParse).parse(markdown);
const docxBlob = await toDocx(mdast, {}, { plugins: [emojiPlugin()] });Custom Emoji Shortcodes
const plugin = emojiPlugin({
emojis: {
custom_badge: "🏅",
rocket: "🛸", // Override an existing shortcode
},
});🧠 How It Works
During @m2d/core inline node traversal, emojiPlugin scans MDAST text nodes for :[a-z0-9_+-]+: patterns and replaces recognized shortcodes with their corresponding Unicode characters from the consolidated emoji table. Unrecognized shortcodes remain unchanged.
License
This library is licensed under the MIT open-source license.
with 💖 by Mayank Kumar Chaudhari