mirror of
https://github.com/vector-im/element-web.git
synced 2024-11-17 05:55:00 +08:00
Add HtmlUtils.linkifyString()
Add HtmlUtils.linkifyElement() Add HtmlUtils.linkifyAndSanitize() Refactor module imports Signed-off-by: Bastian <matrix@noxware.de>
This commit is contained in:
parent
3e2bcd1d3c
commit
9cd13a8893
@ -19,16 +19,21 @@ limitations under the License.
|
|||||||
|
|
||||||
import ReplyThread from "./components/views/elements/ReplyThread";
|
import ReplyThread from "./components/views/elements/ReplyThread";
|
||||||
|
|
||||||
const React = require('react');
|
import React from 'react';
|
||||||
const sanitizeHtml = require('sanitize-html');
|
import sanitizeHtml from 'sanitize-html';
|
||||||
const highlight = require('highlight.js');
|
import highlight from 'highlight.js';
|
||||||
const linkifyMatrix = require('./linkify-matrix');
|
import * as linkify from 'linkifyjs';
|
||||||
|
import linkifyMatrix from './linkify-matrix';
|
||||||
|
import _linkifyElement from 'linkifyjs/element';
|
||||||
|
import _linkifyString from 'linkifyjs/string';
|
||||||
import escape from 'lodash/escape';
|
import escape from 'lodash/escape';
|
||||||
import emojione from 'emojione';
|
import emojione from 'emojione';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import MatrixClientPeg from './MatrixClientPeg';
|
import MatrixClientPeg from './MatrixClientPeg';
|
||||||
import url from 'url';
|
import url from 'url';
|
||||||
|
|
||||||
|
linkifyMatrix(linkify);
|
||||||
|
|
||||||
emojione.imagePathSVG = 'emojione/svg/';
|
emojione.imagePathSVG = 'emojione/svg/';
|
||||||
// Store PNG path for displaying many flags at once (for increased performance over SVG)
|
// Store PNG path for displaying many flags at once (for increased performance over SVG)
|
||||||
emojione.imagePathPNG = 'emojione/png/';
|
emojione.imagePathPNG = 'emojione/png/';
|
||||||
@ -508,3 +513,35 @@ export function emojifyText(text) {
|
|||||||
__html: unicodeToImage(escape(text)),
|
__html: unicodeToImage(escape(text)),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Linkifies the given string. This is a wrapper around 'linkifyjs/string'.
|
||||||
|
*
|
||||||
|
* @param {string} str
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
export function linkifyString(str) {
|
||||||
|
return _linkifyString(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Linkifies the given DOM element. This is a wrapper around 'linkifyjs/element'.
|
||||||
|
*
|
||||||
|
* @param {object} element DOM element to linkify
|
||||||
|
* @param {object} [options] Options for linkifyElement. Default: linkifyMatrix.options
|
||||||
|
* @returns {object}
|
||||||
|
*/
|
||||||
|
export function linkifyElement(element, options = linkifyMatrix.options) {
|
||||||
|
return _linkifyElement(element, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Linkify the given string and sanitize the HTML afterwards.
|
||||||
|
*
|
||||||
|
* @param {string} dirtyHtml The HTML string to sanitize and linkify
|
||||||
|
* @param {object} [sanitizeHtmlOptions] Optional settings for sanitize-html
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
export function linkifyAndSanitizeHtml(dirtyHtml, sanitizeHtmlOptions = undefined) {
|
||||||
|
return sanitizeHtml(linkifyString(dirtyHtml), sanitizeHtmlOptions);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user