Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

markdown-it-emoji

markdown-it1.2mMIT3.0.0TypeScript support: definitely-typed

Emoji plugin for markdown-it markdown parser.

markdown-it-plugin, markdown-it, markdown, emoji, emojies, emoticon, emoticons

readme

markdown-it-emoji

CI NPM version Coverage Status

Plugin for markdown-it markdown parser, adding emoji & emoticon syntax support. Also supports emoticons shortcuts like :), :-(, and others.

NOTE. v3 changed exports, see below.

Install

npm install i markdown-it-emoji

Use

init

//
// { full, light, bare } configs available.
//
//  full:  includes all available emojis support
//  light: includes small subset of most useable emojis
//  bare:  no defaults
//
// Also CJS & UMD builds available in `dist/` folder of published package,
// if your env not supports ESM modules use.
//
import { full as emoji } from 'markdown-it-emoji'
import markdownit from 'markdown-it'

const md = markdownit().use(emoji/* , options */);

Options are not mandatory:

  • defs (Object) - rewrite available emoji definitions
    • example: { name1: char1, name2: char2, ... }
  • enabled (Array) - disable all emojis except whitelisted
  • shortcuts (Object) - rewrite default shortcuts
    • example: { "smile": [ ":)", ":-)" ], "laughing": ":D" }

Differences in browser. If you load the script directly into the page without using a package system, the module will add itself globally with the name markdownitEmoji.

change output

By default, emojis are rendered as appropriate unicode chars. But you can change the renderer function as you wish.

Render as span blocks (for example, to use a custom iconic font):

// ...
// initialize

md.renderer.rules.emoji = function(token, idx) {
  return '<span class="emoji emoji_' + token[idx].markup + '"></span>';
};

Or use twemoji:

// ...
// initialize

import twemoji from 'twemoji'

md.renderer.rules.emoji = function(token, idx) {
  return twemoji.parse(token[idx].content);
};

NB 1. Read twemoji docs! In case you need more options to change image size & type.

NB 2. When using twemoji you can make image height match the line height with this style:

.emoji {
  height: 1.2em;
}

In your markdown file

Hello from mars :satellite:

becomes

Hello from mars 📡

changelog

3.0.0 / 2023-12-07

  • Breaking: changed exports. See README.
  • Rewrite to ESM.
  • Remove dist/ from repo (build on package publish).

2.0.2 / 2022-04-22

  • Updated dist build, missed in previous release.

2.0.1 / 2022-04-22

  • Emojis can now be escaped (e.g. \:)) with markdown-it@13 and above.

2.0.0 / 2020-10-15

  • Update emojis db.
  • Added bare.js with zero config.
  • istanbul => nyc
  • browserify => rollup.js
  • Dev deps bump & cleanup.
  • Configs cleanup

1.4.0 / 2017-06-20

  • Emoji list update (full set only).

1.3.0 / 2016-10-04

  • Emoji lists update.
  • Don't miss emojis with variation chars after.
  • Filter emojis with fake names ("uXXXX").

1.2.0 / 2016-05-27

  • Don't apply replacements in auto-generated links.
  • More strong restrictions for aliaces - don't allow letters before and after.

1.1.1 / 2016-03-24

  • Fixed shortcuts for >:( and >:-(.

1.1.0 / 2015-08-13

  • Fixed improper names mapping.

1.0.0 / 2015-03-12

  • Markdown-it 4.0.0 support. Use previous version for 2.x-3.x.

0.1.3 / 2014-12-28

  • Removed conflicting shortcuts :/ & :\ until logic improved

0.1.2 / 2014-12-24

  • Updated emoticon shortcuts

0.1.1 / 2014-12-23

  • Updated twemoji instructions.
  • Minor code & tests cleanup.

0.1.0 / 2014-12-22

  • First release.