mirror of
https://github.com/Xcnte/Code-Prettify-for-typecho.git
synced 2024-12-21 20:30:22 +08:00
5 lines
61 KiB
JavaScript
5 lines
61 KiB
JavaScript
|
/* PrismJS 1.14.0
|
||
|
http://prismjs.com/download.html#themes=prism-okaidia&languages=markup+css+clike+javascript+apacheconf+c+aspnet+bash+cpp+csharp+coffeescript+markup-templating+git+java+less+markdown+nginx+php+sql+python+smarty&plugins=line-numbers+toolbar+show-language+copy-to-clipboard
|
||
|
Modified by Copterfly
|
||
|
*/
|
||
|
var _self=(typeof window!=='undefined')?window:((typeof WorkerGlobalScope!=='undefined'&&self instanceof WorkerGlobalScope)?self:{});var Prism=(function(){var lang=/\blang(?:uage)?-([\w-]+)\b/i;var uniqueId=0;var _=_self.Prism={manual:_self.Prism&&_self.Prism.manual,disableWorkerMessageHandler:_self.Prism&&_self.Prism.disableWorkerMessageHandler,util:{encode:function(tokens){if(tokens instanceof Token){return new Token(tokens.type,_.util.encode(tokens.content),tokens.alias)}else if(_.util.type(tokens)==='Array'){return tokens.map(_.util.encode)}else{return tokens.replace(/&/g,'&').replace(/</g,'<').replace(/\u00a0/g,' ')}},type:function(o){return Object.prototype.toString.call(o).match(/\[object (\w+)\]/)[1]},objId:function(obj){if(!obj['__id']){Object.defineProperty(obj,'__id',{value:++uniqueId})}return obj['__id']},clone:function(o,visited){var type=_.util.type(o);visited=visited||{};switch(type){case'Object':if(visited[_.util.objId(o)]){return visited[_.util.objId(o)]}var clone={};visited[_.util.objId(o)]=clone;for(var key in o){if(o.hasOwnProperty(key)){clone[key]=_.util.clone(o[key],visited)}}return clone;case'Array':if(visited[_.util.objId(o)]){return visited[_.util.objId(o)]}var clone=[];visited[_.util.objId(o)]=clone;o.forEach(function(v,i){clone[i]=_.util.clone(v,visited)});return clone}return o}},languages:{extend:function(id,redef){var lang=_.util.clone(_.languages[id]);for(var key in redef){lang[key]=redef[key]}return lang},insertBefore:function(inside,before,insert,root){root=root||_.languages;var grammar=root[inside];if(arguments.length==2){insert=arguments[1];for(var newToken in insert){if(insert.hasOwnProperty(newToken)){grammar[newToken]=insert[newToken]}}return grammar}var ret={};for(var token in grammar){if(grammar.hasOwnProperty(token)){if(token==before){for(var newToken in insert){if(insert.hasOwnProperty(newToken)){ret[newToken]=insert[newToken]}}}ret[token]=grammar[token]}}_.languages.DFS(_.languages,function(key,value){if(value===root[inside]&&key!=inside){this[key]=ret}});return root[inside]=ret},DFS:function(o,callback,type,visited){visited=visited||{};for(var i in o){if(o.hasOwnProperty(i)){callback.call(o,i,o[i],type||i);if(_.util.type(o[i])==='Object'&&!visited[_.util.objId(o[i])]){visited[_.util.objId(o[i])]=true;_.languages.DFS(o[i],callback,null,visited)}else if(_.util.type(o[i])==='Array'&&!visited[_.util.objId(o[i])]){visited[_.util.objId(o[i])]=true;_.languages.DFS(o[i],callback,i,visited)}}}}},plugins:{},highlightAll:function(async,callback){_.highlightAllUnder(document,async,callback)},highlightAllUnder:function(container,async,callback){var env={callback:callback,selector:'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'};_.hooks.run("before-highlightall",env);var elements=env.elements||container.querySelectorAll(env.selector);for(var i=0,element;element=elements[i++];){_.highlightElement(element,async===true,env.callback)}},highlightElement:function(element,async,callback){var language,grammar,parent=element;while(parent&&!lang.test(parent.className)){parent=parent.parentNode}if(parent){language=(parent.className.match(lang)||[,''])[1].toLowerCase();grammar=_.languages[language]}element.className=element.className.replace(lang,'').replace(/\s+/g,' ')+' language-'+language;if(element.parentNode){parent=element.parentNode;if(/pre/i.test(parent.nodeName)){parent.className=parent.className.replace(lang,'').replace(/\s+/g,' ')+' language-'+language}}var code=element.textContent;var env={element:element,language:language,grammar:grammar,code:code};_.hooks.run('before-sanity-check',env);if(!env.code||!env.grammar){if(env.code){_.hooks.run('before-highlight',env);env.element.textContent=env.code;_.hooks.run('after-highlight',env)}_.hooks.run('complete',env);return}_.hooks.run('before-highlight',env);if(async&&_self.Worker){var worker=new Worker(_.filename);worker.onmessage=function(evt){env.highlightedCode=evt.data;_.hooks.run('before-insert',env);env.element.innerHTML=env.highlightedCode;callback&&callback.call(env.element);_.hooks.r
|