mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-06 23:30:28 +03:00
Twemojified all text
Signed-off-by: Ajay Bura <ajbura@gmail.com>
This commit is contained in:
parent
9d0f99c509
commit
647d085c5f
18 changed files with 266 additions and 248 deletions
21
src/util/twemojify.js
Normal file
21
src/util/twemojify.js
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
/* eslint-disable import/prefer-default-export */
|
||||
import linkifyHtml from 'linkifyjs/html';
|
||||
import parse from 'html-react-parser';
|
||||
import twemoji from 'twemoji';
|
||||
import { sanitizeText } from './sanitize';
|
||||
|
||||
/**
|
||||
* @param {string} text - text to twemojify
|
||||
* @param {object|undefined} opts - options for tweomoji.parse
|
||||
* @param {boolean} [linkify=false] - convert links to html tags (default: false)
|
||||
* @param {boolean} [sanitize=true] - sanitize html text (default: true)
|
||||
* @returns React component
|
||||
*/
|
||||
export function twemojify(text, opts, linkify = false, sanitize = true) {
|
||||
if (typeof text !== 'string') return text;
|
||||
let content = sanitize ? twemoji.parse(sanitizeText(text), opts) : twemoji.parse(text, opts);
|
||||
if (linkify) {
|
||||
content = linkifyHtml(content, { target: '_blank', rel: 'noreferrer noopener' });
|
||||
}
|
||||
return parse(content);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue