Skip to Content
Md2Docx logo Md2Docx

Configuration & Custom Shortcodes

Updated 11 hr ago

Configure @m2d/emoji options to add custom emoji shortcodes or override built-in Unicode mappings.

@m2d/emoji works out of the box with no arguments, and accepts an optional configuration object to extend or override its built-in GitHub-style shortcode table.

Options Reference

The emojiPlugin(options) factory accepts IEmojiPluginOptions:

export interface IEmojiPluginOptions {
  /**
   * A mapping of emoji shortcodes (without colons) to their corresponding Unicode characters.
   * Merged with the built-in shortcode table, allowing custom additions or overrides.
   */
  emojis?: Record<string, string>;
}

Adding or Overriding Shortcodes

Keys in options.emojis are shortcode names without surrounding colons (:):

import { toDocx } from "@m2d/core";
import { emojiPlugin } from "@m2d/emoji";

const docx = await toDocx(
  mdast,
  {},
  {
    plugins: [
      emojiPlugin({
        emojis: {
          ship_it: "🚢",
          rocket: "🛸", // Overrides built-in :rocket: (🚀)
        },
      }),
    ],
  },
);

Matching Rules

  • Only MDAST text nodes are scanned; inlineCode and fenced code blocks are left untouched.
  • Shortcodes must match /:[a-z0-9_+-]+:/g.
  • Unrecognized shortcodes are preserved verbatim in the output document.

On this page