markdown-it-unicode-emoji
Plugin for markdown-it markdown parser, adding unicode emoji & emoticon syntax support.
Note:
- this package is a fork of markdown-it/markdown-it-emoji
- the
emojimarkdown-it token name which means it'll conflict with the markdown-it/markdown-emoji package.
(This shouldn't be a problem because the functionality of markdown-it is extended)
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.jsonbased on the dataset from emoji-java emoji-javaversion 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 --saveIn 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, ... }
- example:
- enabled (
Array) - disable all emojies except whitelisted - shortcuts (
Object) - rewrite default shortcuts- example:
{ "smile": [ ":)", ":-)" ], "laughing": ":D" }
- example:
- 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 ES5String.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);
};