Skip to content

Instantly share code, notes, and snippets.

@hoelzro
Last active July 20, 2020 17:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hoelzro/968d0434f5b9fedc142efa74edb0f4b2 to your computer and use it in GitHub Desktop.
Save hoelzro/968d0434f5b9fedc142efa74edb0f4b2 to your computer and use it in GitHub Desktop.
/*
title: $:/custom/ui/wikiparser/rules/emoji.js
type: application/javascript
module-type: wikirule
*/
(function() {
exports.name = 'emoji';
exports.types = {inline: true};
const EMOJI_LOOKUP = {
'+1': 'πŸ‘',
'-1': 'πŸ‘Ž',
'confused-parrot': '{{$:/custom/images/confused_parrot}}',
'crossed-fingers': '🀞',
'disappointed': '😞',
'facepalm': 'πŸ€¦β€β™‚οΈ',
'flip-table': '',
'grimace': '😬',
'grimacing': '😬',
'joy': 'πŸ˜‚',
'laugh': '🀣',
'laughing': '🀣',
'point-up': '☝️',
'puke': '🀒',
'scream': '😱',
'sob': '😭',
'tired': '😫',
'tired-face': '😫',
'worried': '😟',
null: null // for trailing comma
};
exports.init = function(parser) {
this.parser = parser;
this.matchRegExp = /(?<=\s):([-_+a-z0-9]+):/mg;
};
exports.parse = function() {
this.parser.pos = this.matchRegExp.lastIndex;
let emojiName = this.match[1].replaceAll(/([a-z])_([a-z])/g, '$1-$2');
if(EMOJI_LOOKUP.hasOwnProperty(emojiName)) {
let emojiValue = EMOJI_LOOKUP[emojiName];
if(emojiValue.startsWith('{{') && emojiValue.endsWith('}}')) {
let emojiTiddler = emojiValue.slice(2, -2);
return [{
"type": "image",
"attributes": {
"source": {
"name": "source",
"type": "string",
"value": emojiTiddler
},
"height": {
"name": "height",
"type": "string",
"value": "28"
}
},
"tag": "$image",
"isSelfClosing": true,
"isBlock": false
}];
}
return [{
type: 'text',
text: emojiValue
}];
} else {
return [{
type: 'text',
text: this.match[0]
}];
}
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment