From d74430fff92d8528ef71dd7e5037954984d254f4 Mon Sep 17 00:00:00 2001 From: bazooka07 Date: Sat, 25 Nov 2017 16:31:01 +0100 Subject: [PATCH 1/2] upgrade autoloader --- plugins/autoloader/prism-autoloader.js | 15 +++++++++++++-- plugins/autoloader/prism-autoloader.min.js | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/plugins/autoloader/prism-autoloader.js b/plugins/autoloader/prism-autoloader.js index 41f405d550..f5d34ee0a1 100644 --- a/plugins/autoloader/prism-autoloader.js +++ b/plugins/autoloader/prism-autoloader.js @@ -10,8 +10,19 @@ var ignored_language = 'none'; + var script = document.getElementsByTagName('script'); + script = script[script.length - 1]; + var languages_path; + if(script.hasAttribute('data-autoloader-path')) { + var path = script.getAttribute('data-autoloader-path').trim(); + if(path != '') { + languages_path = path; + } + } else { + path = script.src.replace(/[\w\-]+\.js$/, 'components/'); + } var config = Prism.plugins.autoloader = { - languages_path: 'components/', + languages_path: path, use_minified: true }; @@ -195,4 +206,4 @@ } }); -}()); +}()); \ No newline at end of file diff --git a/plugins/autoloader/prism-autoloader.min.js b/plugins/autoloader/prism-autoloader.min.js index bc8ce703cd..b31afb2e61 100644 --- a/plugins/autoloader/prism-autoloader.min.js +++ b/plugins/autoloader/prism-autoloader.min.js @@ -1 +1 @@ -!function(){if("undefined"!=typeof self&&self.Prism&&self.document&&document.createElement){var e={javascript:"clike",actionscript:"javascript",arduino:"cpp",aspnet:"markup",bison:"c",c:"clike",csharp:"clike",cpp:"c",coffeescript:"javascript",crystal:"ruby","css-extras":"css",d:"clike",dart:"clike",django:"markup",fsharp:"clike",flow:"javascript",glsl:"clike",go:"clike",groovy:"clike",haml:"ruby",handlebars:"markup",haxe:"clike",java:"clike",jolie:"clike",kotlin:"clike",less:"css",markdown:"markup",n4js:"javascript",nginx:"clike",objectivec:"c",opencl:"cpp",parser:"markup",php:"clike","php-extras":"php",processing:"clike",protobuf:"clike",pug:"javascript",qore:"clike",jsx:["markup","javascript"],reason:"clike",ruby:"clike",sass:"css",scss:"css",scala:"java",smarty:"markup",swift:"clike",textile:"markup",twig:"markup",typescript:"javascript",vbnet:"basic",wiki:"markup"},c={},a="none",s=Prism.plugins.autoloader={languages_path:"components/",use_minified:!0},n=function(e,c,a){var s=document.createElement("script");s.src=e,s.async=!0,s.onload=function(){document.body.removeChild(s),c&&c()},s.onerror=function(){document.body.removeChild(s),a&&a()},document.body.appendChild(s)},r=function(e){return s.languages_path+"prism-"+e+(s.use_minified?".min":"")+".js"},i=function(e,a){var s=c[e];s||(s=c[e]={});var n=a.getAttribute("data-dependencies");!n&&a.parentNode&&"pre"===a.parentNode.tagName.toLowerCase()&&(n=a.parentNode.getAttribute("data-dependencies")),n=n?n.split(/\s*,\s*/g):[],t(n,function(){l(e,function(){Prism.highlightElement(a)})})},t=function(e,c,a){"string"==typeof e&&(e=[e]);var s=0,n=e.length,r=function(){n>s?l(e[s],function(){s++,r()},function(){a&&a(e[s])}):s===n&&c&&c(e)};r()},l=function(a,s,i){var l=function(){var e=!1;a.indexOf("!")>=0&&(e=!0,a=a.replace("!",""));var t=c[a];if(t||(t=c[a]={}),s&&(t.success_callbacks||(t.success_callbacks=[]),t.success_callbacks.push(s)),i&&(t.error_callbacks||(t.error_callbacks=[]),t.error_callbacks.push(i)),!e&&Prism.languages[a])o(a);else if(!e&&t.error)u(a);else if(e||!t.loading){t.loading=!0;var l=r(a);n(l,function(){t.loading=!1,o(a)},function(){t.loading=!1,t.error=!0,u(a)})}},p=e[a];p&&p.length?t(p,l):l()},o=function(e){c[e]&&c[e].success_callbacks&&c[e].success_callbacks.length&&c[e].success_callbacks.forEach(function(c){c(e)})},u=function(e){c[e]&&c[e].error_callbacks&&c[e].error_callbacks.length&&c[e].error_callbacks.forEach(function(c){c(e)})};Prism.hooks.add("complete",function(e){e.element&&e.language&&!e.grammar&&e.language!==a&&i(e.language,e.element)})}}(); \ No newline at end of file +!function(){if("undefined"!=typeof self&&self.Prism&&self.document&&document.createElement){var e={javascript:"clike",actionscript:"javascript",arduino:"cpp",aspnet:"markup",bison:"c",c:"clike",csharp:"clike",cpp:"c",coffeescript:"javascript",crystal:"ruby","css-extras":"css",d:"clike",dart:"clike",django:"markup",fsharp:"clike",flow:"javascript",glsl:"clike",go:"clike",groovy:"clike",haml:"ruby",handlebars:"markup",haxe:"clike",java:"clike",jolie:"clike",kotlin:"clike",less:"css",markdown:"markup",n4js:"javascript",nginx:"clike",objectivec:"c",opencl:"cpp",parser:"markup",php:"clike","php-extras":"php",processing:"clike",protobuf:"clike",pug:"javascript",qore:"clike",jsx:["markup","javascript"],reason:"clike",ruby:"clike",sass:"css",scss:"css",scala:"java",smarty:"markup",swift:"clike",textile:"markup",twig:"markup",typescript:"javascript",vbnet:"basic",wiki:"markup"},a={},c="none",r=document.getElementsByTagName("script");r=r[r.length-1];var s;if(r.hasAttribute("data-autoloader-path")){var t=r.getAttribute("data-autoloader-path").trim();""!=t&&(s=t)}else t=r.src.replace(/[\w\-]+\.js$/,"components/");var n=Prism.plugins.autoloader={languages_path:t,use_minified:!0},r=function(e,a,c){var r=document.createElement("script");r.src=e,r.async=!0,r.onload=function(){document.body.removeChild(r),a&&a()},r.onerror=function(){document.body.removeChild(r),c&&c()},document.body.appendChild(r)},i=function(e){return n.languages_path+"prism-"+e+(n.use_minified?".min":"")+".js"},l=function(e,c){var r=a[e];r||(r=a[e]={});var s=c.getAttribute("data-dependencies");!s&&c.parentNode&&"pre"===c.parentNode.tagName.toLowerCase()&&(s=c.parentNode.getAttribute("data-dependencies")),s=s?s.split(/\s*,\s*/g):[],o(s,function(){u(e,function(){Prism.highlightElement(c)})})},o=function(e,a,c){"string"==typeof e&&(e=[e]);var r=0,s=e.length,t=function(){s>r?u(e[r],function(){r++,t()},function(){c&&c(e[r])}):r===s&&a&&a(e)};t()},u=function(c,s,t){var n=function(){var e=!1;c.indexOf("!")>=0&&(e=!0,c=c.replace("!",""));var n=a[c];if(n||(n=a[c]={}),s&&(n.success_callbacks||(n.success_callbacks=[]),n.success_callbacks.push(s)),t&&(n.error_callbacks||(n.error_callbacks=[]),n.error_callbacks.push(t)),!e&&Prism.languages[c])p(c);else if(!e&&n.error)k(c);else if(e||!n.loading){n.loading=!0;var l=i(c);r(l,function(){n.loading=!1,p(c)},function(){n.loading=!1,n.error=!0,k(c)})}},l=e[c];l&&l.length?o(l,n):n()},p=function(e){a[e]&&a[e].success_callbacks&&a[e].success_callbacks.length&&a[e].success_callbacks.forEach(function(a){a(e)})},k=function(e){a[e]&&a[e].error_callbacks&&a[e].error_callbacks.length&&a[e].error_callbacks.forEach(function(a){a(e)})};Prism.hooks.add("complete",function(e){e.element&&e.language&&!e.grammar&&e.language!==c&&l(e.language,e.element)})}}(); \ No newline at end of file From e66de38bb8c2d4d6bac16698266a8dd19bcf54e8 Mon Sep 17 00:00:00 2001 From: bazooka07 Date: Wed, 6 Dec 2017 23:03:15 +0100 Subject: [PATCH 2/2] fix for autoloader plugin --- plugins/autoloader/prism-autoloader.js | 12 ++++++------ plugins/autoloader/prism-autoloader.min.js | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/autoloader/prism-autoloader.js b/plugins/autoloader/prism-autoloader.js index f5d34ee0a1..e3e9bcf54c 100644 --- a/plugins/autoloader/prism-autoloader.js +++ b/plugins/autoloader/prism-autoloader.js @@ -12,17 +12,17 @@ var script = document.getElementsByTagName('script'); script = script[script.length - 1]; - var languages_path; + var languages_path = 'components/'; if(script.hasAttribute('data-autoloader-path')) { var path = script.getAttribute('data-autoloader-path').trim(); - if(path != '') { - languages_path = path; + if(path.length > 0 && !/^[a-z]+:\/\//i.test(script.src)) { + languages_path = path.replace(/\/?$/, '/'); } - } else { - path = script.src.replace(/[\w\-]+\.js$/, 'components/'); + } else if (/[\w-]+\.js$/.test(script.src)) { + languages_path = script.src.replace(/[\w-]+\.js$/, 'components/'); } var config = Prism.plugins.autoloader = { - languages_path: path, + languages_path: languages_path, use_minified: true }; diff --git a/plugins/autoloader/prism-autoloader.min.js b/plugins/autoloader/prism-autoloader.min.js index b31afb2e61..0a8c9c3b08 100644 --- a/plugins/autoloader/prism-autoloader.min.js +++ b/plugins/autoloader/prism-autoloader.min.js @@ -1 +1 @@ -!function(){if("undefined"!=typeof self&&self.Prism&&self.document&&document.createElement){var e={javascript:"clike",actionscript:"javascript",arduino:"cpp",aspnet:"markup",bison:"c",c:"clike",csharp:"clike",cpp:"c",coffeescript:"javascript",crystal:"ruby","css-extras":"css",d:"clike",dart:"clike",django:"markup",fsharp:"clike",flow:"javascript",glsl:"clike",go:"clike",groovy:"clike",haml:"ruby",handlebars:"markup",haxe:"clike",java:"clike",jolie:"clike",kotlin:"clike",less:"css",markdown:"markup",n4js:"javascript",nginx:"clike",objectivec:"c",opencl:"cpp",parser:"markup",php:"clike","php-extras":"php",processing:"clike",protobuf:"clike",pug:"javascript",qore:"clike",jsx:["markup","javascript"],reason:"clike",ruby:"clike",sass:"css",scss:"css",scala:"java",smarty:"markup",swift:"clike",textile:"markup",twig:"markup",typescript:"javascript",vbnet:"basic",wiki:"markup"},a={},c="none",r=document.getElementsByTagName("script");r=r[r.length-1];var s;if(r.hasAttribute("data-autoloader-path")){var t=r.getAttribute("data-autoloader-path").trim();""!=t&&(s=t)}else t=r.src.replace(/[\w\-]+\.js$/,"components/");var n=Prism.plugins.autoloader={languages_path:t,use_minified:!0},r=function(e,a,c){var r=document.createElement("script");r.src=e,r.async=!0,r.onload=function(){document.body.removeChild(r),a&&a()},r.onerror=function(){document.body.removeChild(r),c&&c()},document.body.appendChild(r)},i=function(e){return n.languages_path+"prism-"+e+(n.use_minified?".min":"")+".js"},l=function(e,c){var r=a[e];r||(r=a[e]={});var s=c.getAttribute("data-dependencies");!s&&c.parentNode&&"pre"===c.parentNode.tagName.toLowerCase()&&(s=c.parentNode.getAttribute("data-dependencies")),s=s?s.split(/\s*,\s*/g):[],o(s,function(){u(e,function(){Prism.highlightElement(c)})})},o=function(e,a,c){"string"==typeof e&&(e=[e]);var r=0,s=e.length,t=function(){s>r?u(e[r],function(){r++,t()},function(){c&&c(e[r])}):r===s&&a&&a(e)};t()},u=function(c,s,t){var n=function(){var e=!1;c.indexOf("!")>=0&&(e=!0,c=c.replace("!",""));var n=a[c];if(n||(n=a[c]={}),s&&(n.success_callbacks||(n.success_callbacks=[]),n.success_callbacks.push(s)),t&&(n.error_callbacks||(n.error_callbacks=[]),n.error_callbacks.push(t)),!e&&Prism.languages[c])p(c);else if(!e&&n.error)k(c);else if(e||!n.loading){n.loading=!0;var l=i(c);r(l,function(){n.loading=!1,p(c)},function(){n.loading=!1,n.error=!0,k(c)})}},l=e[c];l&&l.length?o(l,n):n()},p=function(e){a[e]&&a[e].success_callbacks&&a[e].success_callbacks.length&&a[e].success_callbacks.forEach(function(a){a(e)})},k=function(e){a[e]&&a[e].error_callbacks&&a[e].error_callbacks.length&&a[e].error_callbacks.forEach(function(a){a(e)})};Prism.hooks.add("complete",function(e){e.element&&e.language&&!e.grammar&&e.language!==c&&l(e.language,e.element)})}}(); \ No newline at end of file +!function(){if("undefined"!=typeof self&&self.Prism&&self.document&&document.createElement){var e={javascript:"clike",actionscript:"javascript",arduino:"cpp",aspnet:"markup",bison:"c",c:"clike",csharp:"clike",cpp:"c",coffeescript:"javascript",crystal:"ruby","css-extras":"css",d:"clike",dart:"clike",django:"markup",fsharp:"clike",flow:"javascript",glsl:"clike",go:"clike",groovy:"clike",haml:"ruby",handlebars:"markup",haxe:"clike",java:"clike",jolie:"clike",kotlin:"clike",less:"css",markdown:"markup",n4js:"javascript",nginx:"clike",objectivec:"c",opencl:"cpp",parser:"markup",php:"clike","php-extras":"php",processing:"clike",protobuf:"clike",pug:"javascript",qore:"clike",jsx:["markup","javascript"],reason:"clike",ruby:"clike",sass:"css",scss:"css",scala:"java",smarty:"markup",swift:"clike",textile:"markup",twig:"markup",typescript:"javascript",vbnet:"basic",wiki:"markup"},a={},c="none",s=document.getElementsByTagName("script");s=s[s.length-1];var r="components/";if(s.hasAttribute("data-autoloader-path")){var t=s.getAttribute("data-autoloader-path").trim();t.length>0&&!/^[a-z]+:\/\//i.test(s.src)&&(r=t.replace(/\/?$/,"/"))}else/[\w-]+\.js$/.test(s.src)&&(r=s.src.replace(/[\w-]+\.js$/,"components/"));var n=Prism.plugins.autoloader={languages_path:r,use_minified:!0},s=function(e,a,c){var s=document.createElement("script");s.src=e,s.async=!0,s.onload=function(){document.body.removeChild(s),a&&a()},s.onerror=function(){document.body.removeChild(s),c&&c()},document.body.appendChild(s)},i=function(e){return n.languages_path+"prism-"+e+(n.use_minified?".min":"")+".js"},l=function(e,c){var s=a[e];s||(s=a[e]={});var r=c.getAttribute("data-dependencies");!r&&c.parentNode&&"pre"===c.parentNode.tagName.toLowerCase()&&(r=c.parentNode.getAttribute("data-dependencies")),r=r?r.split(/\s*,\s*/g):[],o(r,function(){u(e,function(){Prism.highlightElement(c)})})},o=function(e,a,c){"string"==typeof e&&(e=[e]);var s=0,r=e.length,t=function(){r>s?u(e[s],function(){s++,t()},function(){c&&c(e[s])}):s===r&&a&&a(e)};t()},u=function(c,r,t){var n=function(){var e=!1;c.indexOf("!")>=0&&(e=!0,c=c.replace("!",""));var n=a[c];if(n||(n=a[c]={}),r&&(n.success_callbacks||(n.success_callbacks=[]),n.success_callbacks.push(r)),t&&(n.error_callbacks||(n.error_callbacks=[]),n.error_callbacks.push(t)),!e&&Prism.languages[c])p(c);else if(!e&&n.error)k(c);else if(e||!n.loading){n.loading=!0;var l=i(c);s(l,function(){n.loading=!1,p(c)},function(){n.loading=!1,n.error=!0,k(c)})}},l=e[c];l&&l.length?o(l,n):n()},p=function(e){a[e]&&a[e].success_callbacks&&a[e].success_callbacks.length&&a[e].success_callbacks.forEach(function(a){a(e)})},k=function(e){a[e]&&a[e].error_callbacks&&a[e].error_callbacks.length&&a[e].error_callbacks.forEach(function(a){a(e)})};Prism.hooks.add("complete",function(e){e.element&&e.language&&!e.grammar&&e.language!==c&&l(e.language,e.element)})}}(); \ No newline at end of file