mirror of
https://github.com/element-hq/element-web
synced 2024-11-27 19:56:47 +03:00
feat: render unicode emoji as emojione images
This commit is contained in:
parent
87300e3a9f
commit
48f2c4a696
1 changed files with 22 additions and 29 deletions
|
@ -20,6 +20,8 @@ var React = require('react');
|
|||
var sanitizeHtml = require('sanitize-html');
|
||||
var highlight = require('highlight.js');
|
||||
var linkifyMatrix = require('./linkify-matrix');
|
||||
import escape from 'lodash/escape';
|
||||
import {unicodeToImage} from 'emojione';
|
||||
|
||||
var sanitizeHtmlParams = {
|
||||
allowedTags: [
|
||||
|
@ -185,9 +187,9 @@ module.exports = {
|
|||
opts = opts || {};
|
||||
|
||||
var isHtml = (content.format === "org.matrix.custom.html");
|
||||
let body = isHtml ? content.formatted_body : escape(content.body);
|
||||
|
||||
var safeBody;
|
||||
if (isHtml) {
|
||||
// XXX: We sanitize the HTML whilst also highlighting its text nodes, to avoid accidentally trying
|
||||
// to highlight HTML tags themselves. However, this does mean that we don't highlight textnodes which
|
||||
// are interrupted by HTML tags (not that we did before) - e.g. foo<span/>bar won't get highlighted
|
||||
|
@ -203,22 +205,13 @@ module.exports = {
|
|||
return highlighter.applyHighlights(safeText, safeHighlights).join('');
|
||||
};
|
||||
}
|
||||
safeBody = sanitizeHtml(content.formatted_body, sanitizeHtmlParams);
|
||||
safeBody = sanitizeHtml(body, sanitizeHtmlParams);
|
||||
safeBody = unicodeToImage(safeBody);
|
||||
}
|
||||
finally {
|
||||
delete sanitizeHtmlParams.textFilter;
|
||||
}
|
||||
return <span className="markdown-body" dangerouslySetInnerHTML={{ __html: safeBody }} />;
|
||||
} else {
|
||||
safeBody = content.body;
|
||||
if (highlights && highlights.length > 0) {
|
||||
var highlighter = new TextHighlighter("mx_EventTile_searchHighlight", opts.highlightLink);
|
||||
return highlighter.applyHighlights(safeBody, highlights);
|
||||
}
|
||||
else {
|
||||
return safeBody;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
highlightDom: function(element) {
|
||||
|
|
Loading…
Reference in a new issue