diff --git a/components/prism-core.js b/components/prism-core.js index c68962b277..cd4805d6e6 100644 --- a/components/prism-core.js +++ b/components/prism-core.js @@ -12,13 +12,13 @@ var _self = (typeof window !== 'undefined') * @author Lea Verou http://lea.verou.me */ -var Prism = (function(){ +var Prism = (function (_self){ // Private helper vars var lang = /\blang(?:uage)?-([\w-]+)\b/i; var uniqueId = 0; -var _ = _self.Prism = { +var _ = { manual: _self.Prism && _self.Prism.manual, disableWorkerMessageHandler: _self.Prism && _self.Prism.disableWorkerMessageHandler, util: { @@ -278,8 +278,6 @@ var _ = _self.Prism = { }, matchGrammar: function (text, strarr, grammar, index, startPos, oneshot, target) { - var Token = _.Token; - for (var token in grammar) { if(!grammar.hasOwnProperty(token) || !grammar[token]) { continue; @@ -445,17 +443,21 @@ var _ = _self.Prism = { callback(env); } } - } + }, + + Token: Token }; -var Token = _.Token = function(type, content, alias, matchedStr, greedy) { +_self.Prism = _; + +function Token(type, content, alias, matchedStr, greedy) { this.type = type; this.content = content; this.alias = alias; // Copy of the full string this token was created from this.length = (matchedStr || "").length|0; this.greedy = !!greedy; -}; +} Token.stringify = function(o, language, parent) { if (typeof o == 'string') { @@ -496,7 +498,7 @@ Token.stringify = function(o, language, parent) { if (!_self.document) { if (!_self.addEventListener) { // in Node.js - return _self.Prism; + return _; } if (!_.disableWorkerMessageHandler) { @@ -514,7 +516,7 @@ if (!_self.document) { }, false); } - return _self.Prism; + return _; } //Get current script and highlight @@ -537,9 +539,9 @@ if (script) { } } -return _self.Prism; +return _; -})(); +})(_self); if (typeof module !== 'undefined' && module.exports) { module.exports = Prism; diff --git a/components/prism-core.min.js b/components/prism-core.min.js index 6e073465a8..b7ce314ab2 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,a=_self.Prism={manual:_self.Prism&&_self.Prism.manual,disableWorkerMessageHandler:_self.Prism&&_self.Prism.disableWorkerMessageHandler,util:{encode:function(e){return e instanceof n?new n(e.type,a.util.encode(e.content),e.alias):"Array"===a.util.type(e)?e.map(a.util.encode):e.replace(/&/g,"&").replace(/e.length)return;if(!(w instanceof s)){if(m&&k!=t.length-1){f.lastIndex=b;var _=f.exec(e);if(!_)break;for(var P=_.index+(d?_[1].length:0),A=_.index+_[0].length,O=k,x=b,N=t.length;N>O&&(A>x||!t[O].type&&!t[O-1].greedy);++O)x+=t[O].length,P>=x&&(++k,b=x);if(t[k]instanceof s)continue;j=O-k,w=e.slice(b,x),_.index-=b}else{f.lastIndex=0;var _=f.exec(w),j=1}if(_){d&&(p=_[1]?_[1].length:0);var P=_.index+p,_=_[0].slice(p),A=P+_.length,S=w.slice(0,P),E=w.slice(A),C=[k,j];S&&(++k,b+=S.length,C.push(S));var M=new s(u,h?a.tokenize(_,h):_,y,_,m);if(C.push(M),E&&C.push(E),Array.prototype.splice.apply(t,C),1!=j&&a.matchGrammar(e,t,n,k,b,!0,u),l)break}else if(l)break}}}}},tokenize:function(e,t){var n=[e],r=t.rest;if(r){for(var i in r)t[i]=r[i];delete t.rest}return a.matchGrammar(e,n,t,0,0,!1),n},hooks:{all:{},add:function(e,t){var n=a.hooks.all;n[e]=n[e]||[],n[e].push(t)},run:function(e,t){var n=a.hooks.all[e];if(n&&n.length)for(var r,i=0;r=n[i++];)r(t)}}},n=a.Token=function(e,t,a,n,r){this.type=e,this.content=t,this.alias=a,this.length=0|(n||"").length,this.greedy=!!r};if(n.stringify=function(e,t,r){if("string"==typeof e)return e;if("Array"===a.util.type(e))return e.map(function(a){return n.stringify(a,t,e)}).join("");var i={type:e.type,content:n.stringify(e.content,t,r),tag:"span",classes:["token",e.type],attributes:{},language:t,parent:r};if(e.alias){var l="Array"===a.util.type(e.alias)?e.alias:[e.alias];Array.prototype.push.apply(i.classes,l)}a.hooks.run("wrap",i);var o=Object.keys(i.attributes).map(function(e){return e+'="'+(i.attributes[e]||"").replace(/"/g,""")+'"'}).join(" ");return"<"+i.tag+' class="'+i.classes.join(" ")+'"'+(o?" "+o:"")+">"+i.content+""},!_self.document)return _self.addEventListener?(a.disableWorkerMessageHandler||_self.addEventListener("message",function(e){var t=JSON.parse(e.data),n=t.language,r=t.code,i=t.immediateClose;_self.postMessage(a.highlight(r,a.languages[n],n)),i&&_self.close()},!1),_self.Prism):_self.Prism;var r=document.currentScript||[].slice.call(document.getElementsByTagName("script")).pop();return r&&(a.filename=r.src,a.manual||r.hasAttribute("data-manual")||("loading"!==document.readyState?window.requestAnimationFrame?window.requestAnimationFrame(a.highlightAll):window.setTimeout(a.highlightAll,16):document.addEventListener("DOMContentLoaded",a.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(e){function t(e,t,a,n,r){this.type=e,this.content=t,this.alias=a,this.length=0|(n||"").length,this.greedy=!!r}var a=/\blang(?:uage)?-([\w-]+)\b/i,n=0,r={manual:e.Prism&&e.Prism.manual,disableWorkerMessageHandler:e.Prism&&e.Prism.disableWorkerMessageHandler,util:{encode:function(e){return e instanceof t?new t(e.type,r.util.encode(e.content),e.alias):"Array"===r.util.type(e)?e.map(r.util.encode):e.replace(/&/g,"&").replace(/e.length)return;if(!(w instanceof t)){if(p&&k!=a.length-1){h.lastIndex=b;var A=h.exec(e);if(!A)break;for(var P=A.index+(f?A[1].length:0),O=A.index+A[0].length,x=k,N=b,j=a.length;j>x&&(O>N||!a[x].type&&!a[x-1].greedy);++x)N+=a[x].length,P>=N&&(++k,b=N);if(a[k]instanceof t)continue;S=x-k,w=e.slice(b,N),A.index-=b}else{h.lastIndex=0;var A=h.exec(w),S=1}if(A){f&&(m=A[1]?A[1].length:0);var P=A.index+m,A=A[0].slice(m),O=P+A.length,E=w.slice(0,P),_=w.slice(O),C=[k,S];E&&(++k,b+=E.length,C.push(E));var M=new t(u,d?r.tokenize(A,d):A,y,A,p);if(C.push(M),_&&C.push(_),Array.prototype.splice.apply(a,C),1!=S&&r.matchGrammar(e,a,n,k,b,!0,u),o)break}else if(o)break}}}}},tokenize:function(e,t){var a=[e],n=t.rest;if(n){for(var i in n)t[i]=n[i];delete t.rest}return r.matchGrammar(e,a,t,0,0,!1),a},hooks:{all:{},add:function(e,t){var a=r.hooks.all;a[e]=a[e]||[],a[e].push(t)},run:function(e,t){var a=r.hooks.all[e];if(a&&a.length)for(var n,i=0;n=a[i++];)n(t)}},Token:t};if(e.Prism=r,t.stringify=function(e,a,n){if("string"==typeof e)return e;if("Array"===r.util.type(e))return e.map(function(n){return t.stringify(n,a,e)}).join("");var i={type:e.type,content:t.stringify(e.content,a,n),tag:"span",classes:["token",e.type],attributes:{},language:a,parent:n};if(e.alias){var l="Array"===r.util.type(e.alias)?e.alias:[e.alias];Array.prototype.push.apply(i.classes,l)}r.hooks.run("wrap",i);var o=Object.keys(i.attributes).map(function(e){return e+'="'+(i.attributes[e]||"").replace(/"/g,""")+'"'}).join(" ");return"<"+i.tag+' class="'+i.classes.join(" ")+'"'+(o?" "+o:"")+">"+i.content+""},!e.document)return e.addEventListener?(r.disableWorkerMessageHandler||e.addEventListener("message",function(t){var a=JSON.parse(t.data),n=a.language,i=a.code,l=a.immediateClose;e.postMessage(r.highlight(i,r.languages[n],n)),l&&e.close()},!1),r):r;var i=document.currentScript||[].slice.call(document.getElementsByTagName("script")).pop();return i&&(r.filename=i.src,r.manual||i.hasAttribute("data-manual")||("loading"!==document.readyState?window.requestAnimationFrame?window.requestAnimationFrame(r.highlightAll):window.setTimeout(r.highlightAll,16):document.addEventListener("DOMContentLoaded",r.highlightAll))),r}(_self);"undefined"!=typeof module&&module.exports&&(module.exports=Prism),"undefined"!=typeof global&&(global.Prism=Prism); \ No newline at end of file diff --git a/components/prism-sas.min.js b/components/prism-sas.min.js index b6ea705c9a..e89383b616 100644 --- a/components/prism-sas.min.js +++ b/components/prism-sas.min.js @@ -1 +1 @@ -Prism.languages.sas={datalines:{pattern:/^\s*(?:(?:data)?lines|cards);[\s\S]+?(?:\r?\n|\r);/im,alias:"string",inside:{keyword:{pattern:/^(\s*)(?:(?:data)?lines|cards)/i,lookbehind:!0},punctuation:/;/}},comment:[{pattern:/(^\s*|;\s*)\*.*;/m,lookbehind:!0},/\/\*[\s\S]+?\*\//],datetime:{pattern:/'[^']+'(?:dt?|t)\b/i,alias:"number"},string:{pattern:/(["'])(?:\1\1|(?!\1)[\s\S])*\1/,greedy:!0},keyword:/\b(?:data|else|format|if|input|proc\s\w+|quit|run|then|libname|set|output|options)\b/i,number:/\b(?:[\da-f]+x|\d+(?:\.\d+)?(?:e[+-]?\d+)?)/i,operator:/\*\*?|\|\|?|!!?|¦¦?|<[>=]?|>[<=]?|[-+\/=&]|[~¬^]=?|\b(?:eq|ne|gt|lt|ge|le|in|not)\b/i,punctuation:/[$%@.(){}\[\];,\\]/}; +Prism.languages.sas={datalines:{pattern:/^\s*(?:(?:data)?lines|cards);[\s\S]+?(?:\r?\n|\r);/im,alias:"string",inside:{keyword:{pattern:/^(\s*)(?:(?:data)?lines|cards)/i,lookbehind:!0},punctuation:/;/}},comment:[{pattern:/(^\s*|;\s*)\*.*;/m,lookbehind:!0},/\/\*[\s\S]+?\*\//],datetime:{pattern:/'[^']+'(?:dt?|t)\b/i,alias:"number"},string:{pattern:/(["'])(?:\1\1|(?!\1)[\s\S])*\1/,greedy:!0},keyword:/\b(?:data|else|format|if|input|proc\s\w+|quit|run|then|libname|set|output|options)\b/i,number:/\b(?:[\da-f]+x|\d+(?:\.\d+)?(?:e[+-]?\d+)?)/i,operator:/\*\*?|\|\|?|!!?|¦¦?|<[>=]?|>[<=]?|[-+\/=&]|[~¬^]=?|\b(?:eq|ne|gt|lt|ge|le|in|not)\b/i,punctuation:/[$%@.(){}\[\];,\\]/}; \ No newline at end of file diff --git a/prism.js b/prism.js index 220fc30524..c638806b56 100644 --- a/prism.js +++ b/prism.js @@ -17,13 +17,13 @@ var _self = (typeof window !== 'undefined') * @author Lea Verou http://lea.verou.me */ -var Prism = (function(){ +var Prism = (function (_self){ // Private helper vars var lang = /\blang(?:uage)?-([\w-]+)\b/i; var uniqueId = 0; -var _ = _self.Prism = { +var _ = { manual: _self.Prism && _self.Prism.manual, disableWorkerMessageHandler: _self.Prism && _self.Prism.disableWorkerMessageHandler, util: { @@ -283,8 +283,6 @@ var _ = _self.Prism = { }, matchGrammar: function (text, strarr, grammar, index, startPos, oneshot, target) { - var Token = _.Token; - for (var token in grammar) { if(!grammar.hasOwnProperty(token) || !grammar[token]) { continue; @@ -450,17 +448,21 @@ var _ = _self.Prism = { callback(env); } } - } + }, + + Token: Token }; -var Token = _.Token = function(type, content, alias, matchedStr, greedy) { +_self.Prism = _; + +function Token(type, content, alias, matchedStr, greedy) { this.type = type; this.content = content; this.alias = alias; // Copy of the full string this token was created from this.length = (matchedStr || "").length|0; this.greedy = !!greedy; -}; +} Token.stringify = function(o, language, parent) { if (typeof o == 'string') { @@ -501,7 +503,7 @@ Token.stringify = function(o, language, parent) { if (!_self.document) { if (!_self.addEventListener) { // in Node.js - return _self.Prism; + return _; } if (!_.disableWorkerMessageHandler) { @@ -519,7 +521,7 @@ if (!_self.document) { }, false); } - return _self.Prism; + return _; } //Get current script and highlight @@ -542,9 +544,9 @@ if (script) { } } -return _self.Prism; +return _; -})(); +})(_self); if (typeof module !== 'undefined' && module.exports) { module.exports = Prism;