markdown-it-emoji-light.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. /*! markdown-it-emoji 1.4.0 https://github.com//markdown-it/markdown-it-emoji @license MIT */(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.markdownitEmoji = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  2. module.exports={
  3. "grinning": "😀",
  4. "smiley": "😃",
  5. "smile": "😄",
  6. "grin": "😁",
  7. "laughing": "😆",
  8. "satisfied": "😆",
  9. "sweat_smile": "😅",
  10. "joy": "😂",
  11. "blush": "😊",
  12. "innocent": "😇",
  13. "wink": "😉",
  14. "relieved": "😌",
  15. "heart_eyes": "😍",
  16. "kissing_heart": "😘",
  17. "kissing": "😗",
  18. "kissing_smiling_eyes": "😙",
  19. "kissing_closed_eyes": "😚",
  20. "yum": "😋",
  21. "stuck_out_tongue_winking_eye": "😜",
  22. "stuck_out_tongue_closed_eyes": "😝",
  23. "stuck_out_tongue": "😛",
  24. "sunglasses": "😎",
  25. "smirk": "😏",
  26. "unamused": "😒",
  27. "disappointed": "😞",
  28. "pensive": "😔",
  29. "worried": "😟",
  30. "confused": "😕",
  31. "persevere": "😣",
  32. "confounded": "😖",
  33. "tired_face": "😫",
  34. "weary": "😩",
  35. "angry": "😠",
  36. "rage": "😡",
  37. "pout": "😡",
  38. "no_mouth": "😶",
  39. "neutral_face": "😐",
  40. "expressionless": "😑",
  41. "hushed": "😯",
  42. "frowning": "😦",
  43. "anguished": "😧",
  44. "open_mouth": "😮",
  45. "astonished": "😲",
  46. "dizzy_face": "😵",
  47. "flushed": "😳",
  48. "scream": "😱",
  49. "fearful": "😨",
  50. "cold_sweat": "😰",
  51. "cry": "😢",
  52. "disappointed_relieved": "😥",
  53. "sob": "😭",
  54. "sweat": "😓",
  55. "sleepy": "😪",
  56. "sleeping": "😴",
  57. "mask": "😷",
  58. "smiling_imp": "😈",
  59. "smiley_cat": "😺",
  60. "smile_cat": "😸",
  61. "joy_cat": "😹",
  62. "heart_eyes_cat": "😻",
  63. "smirk_cat": "😼",
  64. "kissing_cat": "😽",
  65. "scream_cat": "🙀",
  66. "crying_cat_face": "😿",
  67. "pouting_cat": "😾",
  68. "fist_raised": "✊",
  69. "fist": "✊",
  70. "v": "✌️",
  71. "point_up": "☝️",
  72. "hand": "✋",
  73. "raised_hand": "✋",
  74. "cat": "🐱",
  75. "mouse": "🐭",
  76. "cow": "🐮",
  77. "monkey_face": "🐵",
  78. "star": "⭐️",
  79. "sparkles": "✨",
  80. "zap": "⚡️",
  81. "sunny": "☀️",
  82. "cloud": "☁️",
  83. "snowflake": "❄️",
  84. "umbrella": "☔️",
  85. "coffee": "☕️",
  86. "airplane": "✈️",
  87. "anchor": "⚓️",
  88. "watch": "⌚️",
  89. "phone": "☎️",
  90. "telephone": "☎️",
  91. "hourglass": "⌛️",
  92. "email": "✉️",
  93. "envelope": "✉️",
  94. "scissors": "✂️",
  95. "black_nib": "✒️",
  96. "pencil2": "✏️",
  97. "heart": "❤️",
  98. "aries": "♈️",
  99. "taurus": "♉️",
  100. "gemini": "♊️",
  101. "cancer": "♋️",
  102. "leo": "♌️",
  103. "virgo": "♍️",
  104. "libra": "♎️",
  105. "scorpius": "♏️",
  106. "sagittarius": "♐️",
  107. "capricorn": "♑️",
  108. "aquarius": "♒️",
  109. "pisces": "♓️",
  110. "eight_pointed_black_star": "✴️",
  111. "x": "❌",
  112. "hotsprings": "♨️",
  113. "exclamation": "❗️",
  114. "heavy_exclamation_mark": "❗️",
  115. "grey_exclamation": "❕",
  116. "question": "❓",
  117. "grey_question": "❔",
  118. "bangbang": "‼️",
  119. "interrobang": "⁉️",
  120. "part_alternation_mark": "〽️",
  121. "warning": "⚠️",
  122. "recycle": "♻️",
  123. "white_check_mark": "✅",
  124. "sparkle": "❇️",
  125. "eight_spoked_asterisk": "✳️",
  126. "negative_squared_cross_mark": "❎",
  127. "m": "Ⓜ️",
  128. "wheelchair": "♿️",
  129. "information_source": "ℹ️",
  130. "heavy_plus_sign": "➕",
  131. "heavy_minus_sign": "➖",
  132. "heavy_division_sign": "➗",
  133. "heavy_multiplication_x": "✖️",
  134. "tm": "™️",
  135. "copyright": "©️",
  136. "registered": "®️",
  137. "wavy_dash": "〰️",
  138. "curly_loop": "➰",
  139. "loop": "➿",
  140. "heavy_check_mark": "✔️",
  141. "ballot_box_with_check": "☑️",
  142. "white_circle": "⚪️",
  143. "black_circle": "⚫️",
  144. "black_small_square": "▪️",
  145. "white_small_square": "▫️",
  146. "black_medium_small_square": "◾️",
  147. "white_medium_small_square": "◽️",
  148. "black_medium_square": "◼️",
  149. "white_medium_square": "◻️",
  150. "black_large_square": "⬛️",
  151. "white_large_square": "⬜️",
  152. "black_joker": "🃏",
  153. "mahjong": "🀄️"
  154. }
  155. },{}],2:[function(require,module,exports){
  156. // Emoticons -> Emoji mapping.
  157. //
  158. // (!) Some patterns skipped, to avoid collisions
  159. // without increase matcher complicity. Than can change in future.
  160. //
  161. // Places to look for more emoticons info:
  162. //
  163. // - http://en.wikipedia.org/wiki/List_of_emoticons#Western
  164. // - https://github.com/wooorm/emoticon/blob/master/Support.md
  165. // - http://factoryjoe.com/projects/emoticons/
  166. //
  167. 'use strict';
  168. module.exports = {
  169. angry: [ '>:(', '>:-(' ],
  170. blush: [ ':")', ':-")' ],
  171. broken_heart: [ '</3', '<\\3' ],
  172. // :\ and :-\ not used because of conflict with markdown escaping
  173. confused: [ ':/', ':-/' ], // twemoji shows question
  174. cry: [ ":'(", ":'-(", ':,(', ':,-(' ],
  175. frowning: [ ':(', ':-(' ],
  176. heart: [ '<3' ],
  177. imp: [ ']:(', ']:-(' ],
  178. innocent: [ 'o:)', 'O:)', 'o:-)', 'O:-)', '0:)', '0:-)' ],
  179. joy: [ ":')", ":'-)", ':,)', ':,-)', ":'D", ":'-D", ':,D', ':,-D' ],
  180. kissing: [ ':*', ':-*' ],
  181. laughing: [ 'x-)', 'X-)' ],
  182. neutral_face: [ ':|', ':-|' ],
  183. open_mouth: [ ':o', ':-o', ':O', ':-O' ],
  184. rage: [ ':@', ':-@' ],
  185. smile: [ ':D', ':-D' ],
  186. smiley: [ ':)', ':-)' ],
  187. smiling_imp: [ ']:)', ']:-)' ],
  188. sob: [ ":,'(", ":,'-(", ';(', ';-(' ],
  189. stuck_out_tongue: [ ':P', ':-P' ],
  190. sunglasses: [ '8-)', 'B-)' ],
  191. sweat: [ ',:(', ',:-(' ],
  192. sweat_smile: [ ',:)', ',:-)' ],
  193. unamused: [ ':s', ':-S', ':z', ':-Z', ':$', ':-$' ],
  194. wink: [ ';)', ';-)' ]
  195. };
  196. },{}],3:[function(require,module,exports){
  197. // Convert input options to more useable format
  198. // and compile search regexp
  199. 'use strict';
  200. function quoteRE(str) {
  201. return str.replace(/[.?*+^$[\]\\(){}|-]/g, '\\$&');
  202. }
  203. module.exports = function normalize_opts(options) {
  204. var emojies = options.defs,
  205. shortcuts;
  206. // Filter emojies by whitelist, if needed
  207. if (options.enabled.length) {
  208. emojies = Object.keys(emojies).reduce(function (acc, key) {
  209. if (options.enabled.indexOf(key) >= 0) {
  210. acc[key] = emojies[key];
  211. }
  212. return acc;
  213. }, {});
  214. }
  215. // Flatten shortcuts to simple object: { alias: emoji_name }
  216. shortcuts = Object.keys(options.shortcuts).reduce(function (acc, key) {
  217. // Skip aliases for filtered emojies, to reduce regexp
  218. if (!emojies[key]) { return acc; }
  219. if (Array.isArray(options.shortcuts[key])) {
  220. options.shortcuts[key].forEach(function (alias) {
  221. acc[alias] = key;
  222. });
  223. return acc;
  224. }
  225. acc[options.shortcuts[key]] = key;
  226. return acc;
  227. }, {});
  228. // Compile regexp
  229. var names = Object.keys(emojies)
  230. .map(function (name) { return ':' + name + ':'; })
  231. .concat(Object.keys(shortcuts))
  232. .sort()
  233. .reverse()
  234. .map(function (name) { return quoteRE(name); })
  235. .join('|');
  236. var scanRE = RegExp(names);
  237. var replaceRE = RegExp(names, 'g');
  238. return {
  239. defs: emojies,
  240. shortcuts: shortcuts,
  241. scanRE: scanRE,
  242. replaceRE: replaceRE
  243. };
  244. };
  245. },{}],4:[function(require,module,exports){
  246. 'use strict';
  247. module.exports = function emoji_html(tokens, idx /*, options, env */) {
  248. return tokens[idx].content;
  249. };
  250. },{}],5:[function(require,module,exports){
  251. // Emojies & shortcuts replacement logic.
  252. //
  253. // Note: In theory, it could be faster to parse :smile: in inline chain and
  254. // leave only shortcuts here. But, who care...
  255. //
  256. 'use strict';
  257. module.exports = function create_rule(md, emojies, shortcuts, scanRE, replaceRE) {
  258. var arrayReplaceAt = md.utils.arrayReplaceAt,
  259. ucm = md.utils.lib.ucmicro,
  260. ZPCc = new RegExp([ ucm.Z.source, ucm.P.source, ucm.Cc.source ].join('|'));
  261. function splitTextToken(text, level, Token) {
  262. var token, last_pos = 0, nodes = [];
  263. text.replace(replaceRE, function (match, offset, src) {
  264. var emoji_name;
  265. // Validate emoji name
  266. if (shortcuts.hasOwnProperty(match)) {
  267. // replace shortcut with full name
  268. emoji_name = shortcuts[match];
  269. // Don't allow letters before any shortcut (as in no ":/" in http://)
  270. if (offset > 0 && !ZPCc.test(src[offset - 1])) {
  271. return;
  272. }
  273. // Don't allow letters after any shortcut
  274. if (offset + match.length < src.length && !ZPCc.test(src[offset + match.length])) {
  275. return;
  276. }
  277. } else {
  278. emoji_name = match.slice(1, -1);
  279. }
  280. // Add new tokens to pending list
  281. if (offset > last_pos) {
  282. token = new Token('text', '', 0);
  283. token.content = text.slice(last_pos, offset);
  284. nodes.push(token);
  285. }
  286. token = new Token('emoji', '', 0);
  287. token.markup = emoji_name;
  288. token.content = emojies[emoji_name];
  289. nodes.push(token);
  290. last_pos = offset + match.length;
  291. });
  292. if (last_pos < text.length) {
  293. token = new Token('text', '', 0);
  294. token.content = text.slice(last_pos);
  295. nodes.push(token);
  296. }
  297. return nodes;
  298. }
  299. return function emoji_replace(state) {
  300. var i, j, l, tokens, token,
  301. blockTokens = state.tokens,
  302. autolinkLevel = 0;
  303. for (j = 0, l = blockTokens.length; j < l; j++) {
  304. if (blockTokens[j].type !== 'inline') { continue; }
  305. tokens = blockTokens[j].children;
  306. // We scan from the end, to keep position when new tags added.
  307. // Use reversed logic in links start/end match
  308. for (i = tokens.length - 1; i >= 0; i--) {
  309. token = tokens[i];
  310. if (token.type === 'link_open' || token.type === 'link_close') {
  311. if (token.info === 'auto') { autolinkLevel -= token.nesting; }
  312. }
  313. if (token.type === 'text' && autolinkLevel === 0 && scanRE.test(token.content)) {
  314. // replace current node
  315. blockTokens[j].children = tokens = arrayReplaceAt(
  316. tokens, i, splitTextToken(token.content, token.level, state.Token)
  317. );
  318. }
  319. }
  320. }
  321. };
  322. };
  323. },{}],6:[function(require,module,exports){
  324. 'use strict';
  325. var emojies_defs = require('./lib/data/light.json');
  326. var emojies_shortcuts = require('./lib/data/shortcuts');
  327. var emoji_html = require('./lib/render');
  328. var emoji_replace = require('./lib/replace');
  329. var normalize_opts = require('./lib/normalize_opts');
  330. module.exports = function emoji_plugin(md, options) {
  331. var defaults = {
  332. defs: emojies_defs,
  333. shortcuts: emojies_shortcuts,
  334. enabled: []
  335. };
  336. var opts = normalize_opts(md.utils.assign({}, defaults, options || {}));
  337. md.renderer.rules.emoji = emoji_html;
  338. md.core.ruler.push('emoji', emoji_replace(md, opts.defs, opts.shortcuts, opts.scanRE, opts.replaceRE));
  339. };
  340. },{"./lib/data/light.json":1,"./lib/data/shortcuts":2,"./lib/normalize_opts":3,"./lib/render":4,"./lib/replace":5}]},{},[6])(6)
  341. });