Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 4069886

Browse files
committed
feat: large emoji support
1 parent 48f2c4a commit 4069886

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/HtmlUtils.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ var sanitizeHtml = require('sanitize-html');
2121
var highlight = require('highlight.js');
2222
var linkifyMatrix = require('./linkify-matrix');
2323
import escape from 'lodash/escape';
24-
import {unicodeToImage} from 'emojione';
24+
import {unicodeToImage, unicodeRegexp} from 'emojione';
25+
import classNames from 'classnames';
26+
27+
const EMOJI_REGEX = new RegExp(unicodeRegexp+"+", "gi");
2528

2629
var sanitizeHtmlParams = {
2730
allowedTags: [
@@ -211,7 +214,15 @@ module.exports = {
211214
finally {
212215
delete sanitizeHtmlParams.textFilter;
213216
}
214-
return <span className="markdown-body" dangerouslySetInnerHTML={{ __html: safeBody }} />;
217+
218+
EMOJI_REGEX.lastIndex = 0;
219+
let match = EMOJI_REGEX.exec(body);
220+
let emojiBody = match && match[0] && match[0].length === body.length;
221+
222+
let className = classNames('markdown-body', {
223+
'emoji-body': emojiBody,
224+
});
225+
return <span className={className} dangerouslySetInnerHTML={{ __html: safeBody }} />;
215226
},
216227

217228
highlightDom: function(element) {

0 commit comments

Comments
 (0)