You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
simple-yewu/frontend/web/js/artDialog/_doc/highlight/highlight.pack.js

5 lines
12 KiB

5 years ago
/*
Syntax highlighting with language autodetection.
http://softwaremaniacs.org/soft/highlight/
*/
var hljs=new function(){var LANGUAGES={};var selected_languages={};function escape(value){return value.replace(/&/gm,'&amp;').replace(/</gm,'&lt;').replace(/>/gm,'&gt;')};function contains(array,item){if(!array)return false;for(var i=0;i<array.length;i++)if(array[i]==item)return true;return false};function langRe(language,value,global){var mode='m'+(language.case_insensitive?'i':'')+(global?'g':'');return new RegExp(value,mode)};function findCode(pre){var node;for(var i=0;i<pre.childNodes.length;i++){node=pre.childNodes[i];if(node.nodeName=='CODE')return node;if(!(node.nodeType==3&&node.nodeValue.match(/\s+/)))return null}};function blockText(block){var result='';for(var i=0;i<block.childNodes.length;i++)if(block.childNodes[i].nodeType==3)result+=block.childNodes[i].nodeValue;else if(block.childNodes[i].nodeName=='BR')result+='\n';else result+=blockText(block.childNodes[i]);return result};function blockLanguage(block){var classes=block.className.split(/\s+/);classes=classes.concat(block.parentNode.className.split(/\s+/));for(var i=0;i<classes.length;i++){var class_=classes[i].replace(/^language-/,'');if(class_=='no-highlight'){throw'No highlight'};if(LANGUAGES[class_]){return class_}}};function nodeStream(node){var result=[];(function(node,offset){for(var i=0;i<node.childNodes.length;i++){if(node.childNodes[i].nodeType==3)offset+=node.childNodes[i].nodeValue.length;else if(node.childNodes[i].nodeName=='BR')offset+=1;else{result.push({event:'start',offset:offset,node:node.childNodes[i]});offset=arguments.callee(node.childNodes[i],offset);result.push({event:'stop',offset:offset,node:node.childNodes[i]})}};return offset})(node,0);return result};function mergeStreams(stream1,stream2,value){var processed=0;var result='';var nodeStack=[];function selectStream(){if(stream1.length&&stream2.length){if(stream1[0].offset!=stream2[0].offset)return(stream1[0].offset<stream2[0].offset)?stream1:stream2;else return(stream1[0].event=='start'&&stream2[0].event=='stop')?stream2:stream1}else{return stream1.length?stream1:stream2}};function open(node){var result='<'+node.nodeName.toLowerCase();for(var i=0;i<node.attributes.length;i++){var attribute=node.attributes[i];result+=' '+attribute.nodeName.toLowerCase();if(attribute.nodeValue!=undefined){result+='="'+escape(attribute.nodeValue)+'"'}};return result+'>'};function close(node){return'</'+node.nodeName.toLowerCase()+'>'};while(stream1.length||stream2.length){var current=selectStream().splice(0,1)[0];result+=escape(value.substr(processed,current.offset-processed));processed=current.offset;if(current.event=='start'){result+=open(current.node);nodeStack.push(current.node)}else if(current.event=='stop'){var i=nodeStack.length;do{i--;var node=nodeStack[i];result+=close(node)}while(node!=current.node);nodeStack.splice(i,1);while(i<nodeStack.length){result+=open(nodeStack[i]);i++}}};result+=value.substr(processed);return result};function highlight(language_name,value){function compileSubModes(mode,language){mode.sub_modes=[];for(var i=0;i<mode.contains.length;i++){for(var j=0;j<language.modes.length;j++){if(language.modes[j].className==mode.contains[i]){mode.sub_modes[mode.sub_modes.length]=language.modes[j]}}}};function subMode(lexem,mode){if(!mode.contains){return null};if(!mode.sub_modes){compileSubModes(mode,language)};for(var i=0;i<mode.sub_modes.length;i++){if(mode.sub_modes[i].beginRe.test(lexem)){return mode.sub_modes[i]}};return null};function endOfMode(mode_index,lexem){if(modes[mode_index].end&&modes[mode_index].endRe.test(lexem))return 1;if(modes[mode_index].endsWithParent){var level=endOfMode(mode_index-1,lexem);return level?level+1:0};return 0};function isIllegal(lexem,mode){return mode.illegalRe&&mode.illegalRe.test(lexem)};function compileTerminators(mode,language){var terminators=[];function addTerminator(re){if(!contains(terminators,re)){terminators[terminators.length]=re}};if(mode.contains)for(var i=0;i<language.modes.length;i++){if(contains(mode.contains,language.modes[i].className)){addTerminator(language.modes[i].begin)}};var index=modes.length-1;do{if(modes[index].end){ad