GitHunt
MA

makepanic/markdown-it-unicode-emoji

Emoji syntax plugin for markdown-it markdown parser

markdown-it-unicode-emoji

Build Status
NPM version
Coverage Status

Plugin for markdown-it markdown parser, adding unicode emoji & emoticon syntax support.

Note:

Three versions:

  • Full (default), with all github supported emojies.
  • Light, with only well supported unicode emojies and reduced size.
  • emoji-java uses the same alias as emoji-java

Also supports emoticons shortcuts like :), :-(, and other. See full list an link above.

Differences to markdown-it/markdown-it-emoji

  • adds additional data: emoji-java.json based on the dataset from emoji-java
  • emoji-java version doesn't add any default shortcuts
  • creates tokens for unicode emojis

Install

node.js, browser:

npm install markdown-it-emoji --save
bower install markdown-it-emoji --save

In addition you need unicode emoji detection and parsing functions. If emojione is provided, its functions are used by default.

Use

init

var md = require('markdown-it')();
var emoji = require('markdown-it-emoji');
// Or for light version
// var emoji = require('markdown-it-emoji/light');

md.use(emoji [, options]);

Options are not mantatory:

  • defs (Object) - rewrite available emojies definitions
    • example: { name1: char1, name2: char2, ... }
  • enabled (Array) - disable all emojies except whitelisted
  • shortcuts (Object) - rewrite default shortcuts
    • example: { "smile": [ ":)", ":-)" ], "laughing": ":D" }
  • containsUnicodeEmoji (Function(text)) - function that returns true if a unicode emoji is found inside the text argument.
  • replaceUnicodeEmojis (Function(text, replacer)) - function that follows the ES5 String.prototype.replace(RegExp, replacer) syntax.

By default it tries to use emojione to detect and parse unicode emojis,
but it's possible to roll your own implementation by setting these properties on the config object:

containsUnicodeEmoji: function (text) {
  return emojiOneInstance.regUnicode.test(text);
},
replaceUnicodeEmojis: function (text, replacer) {
  return text.replace(emojiOneInstance.regUnicode, replacer);
}

Differences in browser. If you load script directly into the page, without
package system, module will add itself globally with name markdownitEmoji.
Then init will look a bit different:

var md = window.markdownit().use(window.markdownitEmoji);

change output

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

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

// ...
// initialize

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

Or use emojione:

// ...
// initialize

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

License

MIT

Contributors

MIT License
Created November 18, 2015
Updated April 14, 2023
makepanic/markdown-it-unicode-emoji | GitHunt