From d44e8303668a93942644f78adc11c34ec07e6abd Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Tue, 18 Oct 2016 16:50:58 +0800 Subject: Update emoji parser using markdown-it-emoji instead of emojify to solve issue #217 --- public/js/extra.js | 34 +++++++++++++++++++--------------- public/js/index.js | 4 +++- 2 files changed, 22 insertions(+), 16 deletions(-) (limited to 'public/js') diff --git a/public/js/extra.js b/public/js/extra.js index 01aff7c7..436721a3 100644 --- a/public/js/extra.js +++ b/public/js/extra.js @@ -246,12 +246,6 @@ function finishView(view) { if ($(value).children().length == 0) $(value).gist(viewAjaxCallback); }); - //emojify - try { - emojify.run(view[0]); - } catch (err) { - console.warn(err); - } //mathjax var mathjaxdivs = view.find('span.mathjax.raw').removeClass("raw").toArray(); try { @@ -823,15 +817,6 @@ function highlightRender(code, lang) { return result.value; } -emojify.setConfig({ - blacklist: { - elements: ['script', 'textarea', 'a', 'pre', 'code', 'svg'], - classes: ['no-emojify'] - }, - img_dir: serverurl + '/vendor/emojify/images', - ignore_emoticons: true -}); - var markdownit = require('markdown-it'); var markdownitContainer = require('markdown-it-container'); @@ -855,6 +840,25 @@ md.use(require('markdown-it-sup')); md.use(require('../vendor/markdown-it-mathjax')); md.use(require('markdown-it-imsize')); +md.use(require('markdown-it-emoji'), { + shortcuts: false +}); + +var emojify = require('emojify.js'); + +emojify.setConfig({ + blacklist: { + elements: ['script', 'textarea', 'a', 'pre', 'code', 'svg'], + classes: ['no-emojify'] + }, + img_dir: serverurl + '/vendor/emojify.js/dist/images/basic', + ignore_emoticons: true +}); + +md.renderer.rules.emoji = function(token, idx) { + return emojify.replace(':' + token[idx].markup + ':'); +}; + function renderContainer(tokens, idx, options, env, self) { tokens[idx].attrJoin('role', 'alert'); tokens[idx].attrJoin('class', 'alert'); diff --git a/public/js/index.js b/public/js/index.js index 7294a5ba..bdd4c822 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -3732,6 +3732,8 @@ function matchInContainer(text) { } } +var emojify = require('emojify.js'); + $(editor.getInputField()) .textcomplete([ { // emoji strategy @@ -3751,7 +3753,7 @@ $(editor.getInputField()) callback(list); }, template: function (value) { - return ' ' + value; + return ' ' + value; }, replace: function (value) { return '$1:' + value + ': '; -- cgit v1.2.3