mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-12-23 21:23:08 +02:00
[common] text & [web] common > scripts > text compiler: support emoji
This commit is contained in:
parent
a7021b9514
commit
67ea1498ff
4 changed files with 20 additions and 1 deletions
|
@ -82,6 +82,7 @@
|
||||||
"deepcopy": "0.6.3",
|
"deepcopy": "0.6.3",
|
||||||
"download": "5.0.3",
|
"download": "5.0.3",
|
||||||
"elasticsearch": "12.1.3",
|
"elasticsearch": "12.1.3",
|
||||||
|
"emojinize": "1.0.0",
|
||||||
"escape-html": "1.0.3",
|
"escape-html": "1.0.3",
|
||||||
"escape-regexp": "0.0.1",
|
"escape-regexp": "0.0.1",
|
||||||
"event-stream": "3.3.4",
|
"event-stream": "3.3.4",
|
||||||
|
|
14
src/common/text/elements/emoji.js
Normal file
14
src/common/text/elements/emoji.js
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
/**
|
||||||
|
* Emoji
|
||||||
|
*/
|
||||||
|
|
||||||
|
module.exports = text => {
|
||||||
|
const match = text.match(/^:[a-zA-Z0-9+-_]+:/);
|
||||||
|
if (!match) return null;
|
||||||
|
const emoji = match[0];
|
||||||
|
return {
|
||||||
|
type: 'emoji',
|
||||||
|
content: emoji,
|
||||||
|
emoji: emoji.substr(1, emoji.length - 2)
|
||||||
|
};
|
||||||
|
};
|
|
@ -8,7 +8,8 @@ const elements = [
|
||||||
require('./elements/mention'),
|
require('./elements/mention'),
|
||||||
require('./elements/hashtag'),
|
require('./elements/hashtag'),
|
||||||
require('./elements/code'),
|
require('./elements/code'),
|
||||||
require('./elements/inline-code')
|
require('./elements/inline-code'),
|
||||||
|
require('./elements/emoji')
|
||||||
];
|
];
|
||||||
|
|
||||||
function analyze(source) {
|
function analyze(source) {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
const riot = require('riot');
|
const riot = require('riot');
|
||||||
const nyaize = require('nyaize').default;
|
const nyaize = require('nyaize').default;
|
||||||
|
const emojinize = require('emojinize');
|
||||||
const CONFIG = require('./config');
|
const CONFIG = require('./config');
|
||||||
|
|
||||||
const escape = function(text) {
|
const escape = function(text) {
|
||||||
|
@ -35,6 +36,8 @@ module.exports = function(tokens, shouldBreak, shouldEscape) {
|
||||||
return '<pre><code>' + token.html + '</code></pre>';
|
return '<pre><code>' + token.html + '</code></pre>';
|
||||||
case 'inline-code':
|
case 'inline-code':
|
||||||
return '<code>' + token.html + '</code>';
|
return '<code>' + token.html + '</code>';
|
||||||
|
case 'emoji':
|
||||||
|
return emojinize.encode(token.content)
|
||||||
}
|
}
|
||||||
}).join('');
|
}).join('');
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue