Skip to content

StephenBonikowsky/markdown-it-emoji

 
 

Repository files navigation

markdown-it-emoji

Build Status NPM version Coverage Status

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

v1.+ requires markdown-it v4.+, see changelog.

Two versions:

  • Full (default), with all github supported emojies.
  • Light, with only well supported unicode emojies and reduced size.

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

Install

node.js, browser:

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

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" }

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 twemoji:

// ...
// initialize

var twemoji = require('twemoji')

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

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

NB 2. For twemoji you can like to fit image height to line height with this style:

.emoji {
  height: 1.2em;
}

License

MIT

About

Emoji syntax plugin for markdown-it markdown parser

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 96.4%
  • Makefile 3.6%