-
Notifications
You must be signed in to change notification settings - Fork 0
/
syntax-chroma.min.js
1 lines (1 loc) · 4.38 KB
/
syntax-chroma.min.js
1
!function(e){"use strict";function t(e){var t,r,i,c,o,l,p,d,f,u,g,h=e.getAttribute("data-lang")||"txt",m=e.getAttribute("data-code-wrapper"),w=e.innerHTML,y=w.search(/\S/),S=!1,b="<ol>",v=0,x=/([\w-]*:)|([^">][^<][-\w\s]*;)/gi,_=/(\[.*\])/gi,k={};if(y%2==1&&y--,String.prototype.trim||(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")}),w=w.trim(),"undefined"!=typeof h&&h!==!1&&"undefined"!=typeof m&&m!==!1&&1==m){switch(h){case"JS":t='<script type="text/javascript">',r="</script>";break;case"CSS":t='<style type="text/css">',r="</style>",k={css_decl_str:x,css_attr_sel:_};break;case"PHP":t="<?php ",r="?>"}w=t+"\n"+w+"\n"+r}if(h){for(w=n(h,w,k),"HTML"==h&&(w=s(w),w=w.replace(/(<([^>]+)>)/gi,"<span class='html-tag'>$1</span>")),g=w.split("\n");v<g.length;v++)i=" ".repeat(l),c=g[v].replace(/\t/g,i).trim(),o=g[v].search(/\S/),l=0,o-y>0&&(l=o-y),("JS"==h||"PHP"==h||"CSS"==h)&&(p='<span class="comment">',d="</span>",S?-1!=c.indexOf("*/")?(c=p+c+d,S=!1):c=p+c+d:-1!=c.indexOf("/*")&&-1!=c.indexOf("*/")?(f=c.indexOf("/*"),u=g[v].indexOf("*/")+l+2,c=a(p,c,f)+d,S=!1):-1!=c.indexOf("/*")&&-1==c.indexOf("*/")?(c='<span class="comment">'+c+"</span>",S=!0):-1!=c.indexOf("//")&&(f=c.indexOf("//"),c=a(p,c,f),S=!1)),b+=l>0?'<li><span class="line">'+" ".repeat(l)+c+"</span></li>":'<li><span class="line">'+c+"</span></li>",l=0;b+="</ol>",e.innerHTML=b}}function n(t,n,s){if(("JS"==t||"PHP"==t||"CSS"==t)&&e.diction.lang[t]){var a=n,r=e.diction.lang[t].keywords.join("|"),i=new RegExp("("+r+")","gi"),c=a.replace(i,"<span class='keyword'>$1</span>"),o=e.diction.lang[t].methods.join("|"),l=new RegExp("("+o+")","gi"),c=c.replace(l,"<span class='method'>$1</span>"),p=e.diction.lang[t].reserved.join("|"),d=new RegExp("("+p+")","gi"),c=c.replace(d,"<span class='reserved'>$1</span>");"CSS"==t&&(c=c.replace(s.css_decl_str,"<span class='css-dec'>$1</span><span class='css-vals'>$2</span>"),c=c.replace(s.css_attr_sel,"<span class='css-attr-sel'>$1</span>"))}return c||n}function s(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function a(e,t,n){var s=[t.slice(0,n),e,t.slice(n)].join("");return s}e.title="Syntax Chroma Library",e.version="0.5",e.codeTags="code",e.indentSpaces=4,e.diction={lang:{JS:{keywords:["\\<(script)|</(script)","function","return","array","\\%","\\-","\\+","\\=","\\!","\\|","error","void","catch","throw","delete","try","do ","instanceof","console"],methods:["prototype","break","typeof","window","for"," in ","while","continue","if","else if","else","with","switch","case","join","slice","new ","finally","\\$","this","object","var ","window","document","default","abstract","enum","short","boolean","export","interface","static","byte","extends","super","char","final","native","synchronized","class ","package","throws","const","goto","private","transient","debugger","implements","protected","volatile","double","import","public","undefined","false","true","\\d"],reserved:["alert","eval","location","open\\(\\w*\\S*\\)","focus","math","outerHeight","blur","name","parent","boolean","history","navigator","parseFloat","date","image","number","regExp","document","isNaN","object","status","escapeW","encodeURIW","length","onLoad","string",'\\"(.*?)\\"']},CSS:{keywords:["\\<(style)|/(style)","\\.\\w*[^\\.*\\s\\{]"],methods:["\\#\\w*[^.s<]"],reserved:['\\"(.*?)\\"']},PHP:{keywords:["__halt_compiler","__construct","abstract","and","array"," as\\W","break","callable","case","catch","class","clone","const","continue","declare","default","die","do","echo","empty","enddeclare","endfor","endforeach","endswitch","endwhile","eval","exit","extends","final","foreach","for\\W","global","goto","implements","include","include_once","instanceof","insteadof","interface","isset","list","namespace","new","or\\W","print","private","protected","public","require\\W","require_once","return","static","switch","throw","trait","try","unset","use\\W","var ","while","xor"],methods:["\\<\\?php","\\?\\>","\\$\\w*","function","var_dump","trim","split","define","assert","file","count","if","else","elseif","endif"],reserved:['\\"(.*?)\\"',"true","false"]}}},String.prototype.repeat=function(e){return e=e||1,Array(e+1).join(this)},document.addEventListener("DOMContentLoaded",function(){for(var n=0,s=document.querySelectorAll(e.codeTags),a=s.length;a>n;n+=1)t(s[n])})}(window.SChroma=window.SChroma||{});