From 73272e3ffa9b276492caba4289800b8c55c458c0 Mon Sep 17 00:00:00 2001 From: Miroslav Russev Date: Thu, 30 Aug 2018 16:16:02 +0300 Subject: [PATCH 1/3] Add basic template support This adds basic HTML template support for image and sprite elements by adding two new options to the global settings. ``` emojione.spriteTemplate = '{{alt}}'; emojione.imageTemplate = '{{alt}}'; ``` Current possible replacements are: `{{src}}` `{{size}}` `{{category}}` `{{code}}` `{{title}}` `{{alt}}` --- lib/js/emojione.js | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/lib/js/emojione.js b/lib/js/emojione.js index 37343b812..f121776ef 100644 --- a/lib/js/emojione.js +++ b/lib/js/emojione.js @@ -154,6 +154,9 @@ ns.ascii = false; // change to true to convert ascii smileys ns.riskyMatchAscii = false; // set true to match ascii without leading/trailing space char + ns.spriteTemplate = '{{alt}}'; + ns.imageTemplate = '{{alt}}'; + ns.regShortNames = new RegExp("]*>.*?<\/object>|]*>.*?<\/span>|<(?:object|embed|svg|img|div|span|p|a)[^>]*>|("+ns.shortnames+")", "gi"); ns.regAscii = new RegExp("]*>.*?<\/object>|]*>.*?<\/span>|<(?:object|embed|svg|img|div|span|p|a)[^>]*>|((\\s|^)"+ns.asciiRegexp+"(?=\\s|$|[!,.?]))", "gi"); ns.regAsciiRisky = new RegExp("]*>.*?<\/object>|]*>.*?<\/span>|<(?:object|embed|svg|img|div|span|p|a)[^>]*>|(()"+ns.asciiRegexp+"())", "gi"); @@ -270,12 +273,16 @@ // depending on the settings, we'll either add the native unicode as the alt tag, otherwise the shortname alt = (ns.unicodeAlt) ? ns.convert(unicode.toUpperCase()) : shortname; - if(ns.sprites) { - replaceWith = '' + alt + ''; - } - else { - replaceWith = '' + alt + ''; - } + replaceWith = ns.sprites ? ns.spriteTemplate : ns.imageTemplate; + + replaceWith = + replaceWith + .replace('{{src}}', ePath + fname + ns.fileExtension) + .replace('{{size}}', size) + .replace('{{category}}', category) + .replace('{{code}}', fname) + .replace('{{title}}', title) + .replace('{{alt}}', alt); return replaceWith; } @@ -304,12 +311,16 @@ // depending on the settings, we'll either add the native unicode as the alt tag, otherwise the shortname alt = (ns.unicodeAlt) ? ns.convert(unicode.toUpperCase()) : ns.escapeHTML(m3); - if(ns.sprites) { - replaceWith = m2+'' + alt + ''; - } - else { - replaceWith = m2+''+alt+''; - } + replaceWith = ns.sprites ? ns.spriteTemplate : ns.imageTemplate; + + replaceWith = + m2 + replaceWith + .replace('{{src}}', ePath + unicode + ns.fileExtension) + .replace('{{size}}', size) + .replace('{{category}}', category) + .replace('{{code}}', unicode) + .replace('{{title}}', title) + .replace('{{alt}}', alt); return replaceWith; }); @@ -478,4 +489,4 @@ }; }(this.emojione = this.emojione || {})); -if(typeof module === "object") module.exports = this.emojione; \ No newline at end of file +if(typeof module === "object") module.exports = this.emojione; From 49c479f35316e37ae8d093d93cd3939751f6227f Mon Sep 17 00:00:00 2001 From: Miroslav Russev Date: Thu, 30 Aug 2018 16:26:26 +0300 Subject: [PATCH 2/3] Fix whitespace --- lib/js/emojione.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/js/emojione.js b/lib/js/emojione.js index f121776ef..26a9fca26 100644 --- a/lib/js/emojione.js +++ b/lib/js/emojione.js @@ -155,7 +155,7 @@ ns.riskyMatchAscii = false; // set true to match ascii without leading/trailing space char ns.spriteTemplate = '{{alt}}'; - ns.imageTemplate = '{{alt}}'; + ns.imageTemplate = '{{alt}}'; ns.regShortNames = new RegExp("]*>.*?<\/object>|]*>.*?<\/span>|<(?:object|embed|svg|img|div|span|p|a)[^>]*>|("+ns.shortnames+")", "gi"); ns.regAscii = new RegExp("]*>.*?<\/object>|]*>.*?<\/span>|<(?:object|embed|svg|img|div|span|p|a)[^>]*>|((\\s|^)"+ns.asciiRegexp+"(?=\\s|$|[!,.?]))", "gi"); From c8cfe43bb72e55ebdcada2d971874a5247ed0f99 Mon Sep 17 00:00:00 2001 From: Miroslav Russev Date: Thu, 30 Aug 2018 16:28:19 +0300 Subject: [PATCH 3/3] Fix curly brackets --- lib/js/emojione.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/js/emojione.js b/lib/js/emojione.js index 26a9fca26..693dc06f4 100644 --- a/lib/js/emojione.js +++ b/lib/js/emojione.js @@ -155,7 +155,7 @@ ns.riskyMatchAscii = false; // set true to match ascii without leading/trailing space char ns.spriteTemplate = '{{alt}}'; - ns.imageTemplate = '{{alt}}'; + ns.imageTemplate = '{{alt}}'; ns.regShortNames = new RegExp("]*>.*?<\/object>|]*>.*?<\/span>|<(?:object|embed|svg|img|div|span|p|a)[^>]*>|("+ns.shortnames+")", "gi"); ns.regAscii = new RegExp("]*>.*?<\/object>|]*>.*?<\/span>|<(?:object|embed|svg|img|div|span|p|a)[^>]*>|((\\s|^)"+ns.asciiRegexp+"(?=\\s|$|[!,.?]))", "gi");