Last active
July 20, 2020 17:41
-
-
Save hoelzro/968d0434f5b9fedc142efa74edb0f4b2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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