From 9893489c04bcea81f3e14d6a00b738a3ce0c4dac Mon Sep 17 00:00:00 2001 From: Golmote Date: Sat, 18 Jun 2016 14:18:27 +0200 Subject: [PATCH] Replace flags property of RegExp with a more compatible alternative --- components/prism-core.js | 3 ++- components/prism-core.min.js | 2 +- prism.js | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/components/prism-core.js b/components/prism-core.js index aee751b658..d83beabb3e 100644 --- a/components/prism-core.js +++ b/components/prism-core.js @@ -282,7 +282,8 @@ var _ = _self.Prism = { if (greedy && !pattern.pattern.global) { // Without the global flag, lastIndex won't work - pattern.pattern = RegExp(pattern.pattern.source, pattern.pattern.flags + "g"); + var flags = pattern.pattern.toString().match(/[imuy]*$/)[0]; + pattern.pattern = RegExp(pattern.pattern.source, flags + "g"); } pattern = pattern.pattern || pattern; diff --git a/components/prism-core.min.js b/components/prism-core.min.js index 625a184424..ce80ed3072 100644 --- a/components/prism-core.min.js +++ b/components/prism-core.min.js @@ -1 +1 @@ -var _self="undefined"!=typeof window?window:"undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope?self:{},Prism=function(){var e=/\blang(?:uage)?-(\w+)\b/i,t=0,n=_self.Prism={util:{encode:function(e){return e instanceof a?new a(e.type,n.util.encode(e.content),e.alias):"Array"===n.util.type(e)?e.map(n.util.encode):e.replace(/&/g,"&").replace(/e.length)break e;if(!(y instanceof a)){u.lastIndex=0;var v=u.exec(y),b=1;if(!v&&h&&p!=r.length-1){if(u.lastIndex=m,v=u.exec(e),!v)break;for(var k=v.index+(g?v[1].length:0),w=v.index+v[0].length,_=p,P=m,S=r.length;S>_&&w>P;++_)P+=(r[_].matchedStr||r[_]).length,k>=P&&(++p,m=P);if(r[p]instanceof a||r[_-1].greedy)continue;b=_-p,y=e.slice(m,P),v.index-=m}if(v){g&&(f=v[1].length);var k=v.index+f,v=v[0].slice(f),w=k+v.length,A=y.slice(0,k),x=y.slice(w),O=[p,b];A&&O.push(A);var j=new a(i,c?n.tokenize(v,c):v,d,v,h);O.push(j),x&&O.push(x),Array.prototype.splice.apply(r,O)}}}}}return r},hooks:{all:{},add:function(e,t){var a=n.hooks.all;a[e]=a[e]||[],a[e].push(t)},run:function(e,t){var a=n.hooks.all[e];if(a&&a.length)for(var r,l=0;r=a[l++];)r(t)}}},a=n.Token=function(e,t,n,a,r){this.type=e,this.content=t,this.alias=n,this.matchedStr=a||null,this.greedy=!!r};if(a.stringify=function(e,t,r){if("string"==typeof e)return e;if("Array"===n.util.type(e))return e.map(function(n){return a.stringify(n,t,e)}).join("");var l={type:e.type,content:a.stringify(e.content,t,r),tag:"span",classes:["token",e.type],attributes:{},language:t,parent:r};if("comment"==l.type&&(l.attributes.spellcheck="true"),e.alias){var i="Array"===n.util.type(e.alias)?e.alias:[e.alias];Array.prototype.push.apply(l.classes,i)}n.hooks.run("wrap",l);var o="";for(var s in l.attributes)o+=(o?" ":"")+s+'="'+(l.attributes[s]||"")+'"';return"<"+l.tag+' class="'+l.classes.join(" ")+'" '+o+">"+l.content+""},!_self.document)return _self.addEventListener?(_self.addEventListener("message",function(e){var t=JSON.parse(e.data),a=t.language,r=t.code,l=t.immediateClose;_self.postMessage(n.highlight(r,n.languages[a],a)),l&&_self.close()},!1),_self.Prism):_self.Prism;var r=document.currentScript||[].slice.call(document.getElementsByTagName("script")).pop();return r&&(n.filename=r.src,document.addEventListener&&!r.hasAttribute("data-manual")&&("loading"!==document.readyState?requestAnimationFrame(n.highlightAll,0):document.addEventListener("DOMContentLoaded",n.highlightAll))),_self.Prism}();"undefined"!=typeof module&&module.exports&&(module.exports=Prism),"undefined"!=typeof global&&(global.Prism=Prism); \ No newline at end of file +var _self="undefined"!=typeof window?window:"undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope?self:{},Prism=function(){var e=/\blang(?:uage)?-(\w+)\b/i,t=0,n=_self.Prism={util:{encode:function(e){return e instanceof a?new a(e.type,n.util.encode(e.content),e.alias):"Array"===n.util.type(e)?e.map(n.util.encode):e.replace(/&/g,"&").replace(/e.length)break e;if(!(v instanceof a)){u.lastIndex=0;var b=u.exec(v),k=1;if(!b&&h&&m!=r.length-1){if(u.lastIndex=y,b=u.exec(e),!b)break;for(var w=b.index+(g?b[1].length:0),_=b.index+b[0].length,S=m,P=y,A=r.length;A>S&&_>P;++S)P+=(r[S].matchedStr||r[S]).length,w>=P&&(++m,y=P);if(r[m]instanceof a||r[S-1].greedy)continue;k=S-m,v=e.slice(y,P),b.index-=y}if(b){g&&(f=b[1].length);var w=b.index+f,b=b[0].slice(f),_=w+b.length,x=v.slice(0,w),O=v.slice(_),j=[m,k];x&&j.push(x);var N=new a(i,c?n.tokenize(b,c):b,d,b,h);j.push(N),O&&j.push(O),Array.prototype.splice.apply(r,j)}}}}}return r},hooks:{all:{},add:function(e,t){var a=n.hooks.all;a[e]=a[e]||[],a[e].push(t)},run:function(e,t){var a=n.hooks.all[e];if(a&&a.length)for(var r,l=0;r=a[l++];)r(t)}}},a=n.Token=function(e,t,n,a,r){this.type=e,this.content=t,this.alias=n,this.matchedStr=a||null,this.greedy=!!r};if(a.stringify=function(e,t,r){if("string"==typeof e)return e;if("Array"===n.util.type(e))return e.map(function(n){return a.stringify(n,t,e)}).join("");var l={type:e.type,content:a.stringify(e.content,t,r),tag:"span",classes:["token",e.type],attributes:{},language:t,parent:r};if("comment"==l.type&&(l.attributes.spellcheck="true"),e.alias){var i="Array"===n.util.type(e.alias)?e.alias:[e.alias];Array.prototype.push.apply(l.classes,i)}n.hooks.run("wrap",l);var o="";for(var s in l.attributes)o+=(o?" ":"")+s+'="'+(l.attributes[s]||"")+'"';return"<"+l.tag+' class="'+l.classes.join(" ")+'" '+o+">"+l.content+""},!_self.document)return _self.addEventListener?(_self.addEventListener("message",function(e){var t=JSON.parse(e.data),a=t.language,r=t.code,l=t.immediateClose;_self.postMessage(n.highlight(r,n.languages[a],a)),l&&_self.close()},!1),_self.Prism):_self.Prism;var r=document.currentScript||[].slice.call(document.getElementsByTagName("script")).pop();return r&&(n.filename=r.src,document.addEventListener&&!r.hasAttribute("data-manual")&&("loading"!==document.readyState?requestAnimationFrame(n.highlightAll,0):document.addEventListener("DOMContentLoaded",n.highlightAll))),_self.Prism}();"undefined"!=typeof module&&module.exports&&(module.exports=Prism),"undefined"!=typeof global&&(global.Prism=Prism); \ No newline at end of file diff --git a/prism.js b/prism.js index 3a3c7f71db..dfa4983d21 100644 --- a/prism.js +++ b/prism.js @@ -287,7 +287,8 @@ var _ = _self.Prism = { if (greedy && !pattern.pattern.global) { // Without the global flag, lastIndex won't work - pattern.pattern = RegExp(pattern.pattern.source, pattern.pattern.flags + "g"); + var flags = pattern.pattern.toString().match(/[imuy]*$/)[0]; + pattern.pattern = RegExp(pattern.pattern.source, flags + "g"); } pattern = pattern.pattern || pattern;