From 360600caa8e3366d28905fc5b8156273d5149428 Mon Sep 17 00:00:00 2001 From: Rainner Lins Date: Fri, 3 Jun 2016 15:32:43 -0400 Subject: [PATCH] Rebuilt Syntaxy JS minified file --- dist/js/syntaxy.min.js | 838 +---------------------------------------- 1 file changed, 2 insertions(+), 836 deletions(-) diff --git a/dist/js/syntaxy.min.js b/dist/js/syntaxy.min.js index c6f0d55..153fd71 100644 --- a/dist/js/syntaxy.min.js +++ b/dist/js/syntaxy.min.js @@ -1,842 +1,8 @@ /*! - * @Date: Compiled Thu Jun 02 2016 13:03:16 GMT-0400 (Eastern Daylight Time). + * @Date: Compiled Fri Jun 03 2016 15:31:05 GMT-0400 (Eastern Daylight Time). * @Description: Syntaxy is a small and flexible syntax highlighter for the web. * @Author: Rainner Lins (rainnerlins@gmail.com) * @Version: 1.0.0 * @License: MIT */ -/** - * Syntaxy JS. - * A flexible syntax highlighter for web pages. - * - * @author Rainner Lins - * @github https://github.com/rainner/syntaxy-js - * @license MIT - */ -(function( factory ) -{ - if( typeof define === 'function' && define.amd ){ - define( [], factory ); - } - else if( typeof exports === 'object' ){ - module.exports = factory; - } - else if( window ){ - window.Syntaxy = factory( window.jQuery || null ); - } - -})(function( jQuery ) -{ - /** - * String trimming polyfills - */ - if( typeof String.prototype.ltrim !== 'function' ) - { - String.prototype.ltrim = function(){ - return this.replace( /^[\s\uFEFF\xA0]+/g, '' ); - }; - } - if( typeof String.prototype.rtrim !== 'function' ) - { - String.prototype.rtrim = function(){ - return this.replace( /[\s\uFEFF\xA0]+$/g, '' ); - }; - } - if( typeof String.prototype.trim !== 'function' ) - { - String.prototype.trim = function(){ - return this.replace( /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '' ); - }; - } - - /** - * Use Syntaxy with jQuery, if available - */ - if( jQuery && jQuery.fn && !jQuery.fn.syntaxy ) - { - jQuery.fn.syntaxy = function( options ) - { - return this.each( function() - { - var syntaxy = new Syntaxy( this, options ); - syntaxy.render(); - }); - }; - } - - /** - * Syntaxy class - * @param {Object} target : Code container element - * @param {Object} options : Custom options - */ - var Syntaxy = function( target, options ) - { - this.target = null; - this.reglist = {}; - this.code = ''; - this.error = ''; - this.options = { - tagOpen : '«', // special tag open delimeter - tagSplit : '≈', // special tag split delimeter - tagClose : '»', // special tag close delimeter - tagName : 'span', // final markup tag name - classPrefix : 'stx-', // syntaxy css class prefix - codeTitle : 'Source code', // title to show on code box header - codeType : '', // default syntax type to be used - minHeight : '100px', // min height of syntax scroll container - maxHeight : '600px', // max height of syntax scroll container - isInline : false, // if rendering inline code containers - wordWrap : false, // wrap long lines - startLine : 1, // line to statrt counting from - debugLines : '', // comma separated line numbers to debug (flash) - }; - this.setTarget( target ); - this.setOptions( options ); - this.factory(); - }; - - /** - * Syntaxy prototype - * @type {Object} - */ - Syntaxy.prototype = { - constructor: Syntaxy, - - /** - * Set target element - * @param {Object} target : DOM element - * @return {Object} : Self - */ - setTarget: function( target ) - { - if( typeof target === 'object' ) - { - this.target = target; - this.setCode( target.innerHTML || '' ); - this.setOptions({ - // options from tag attributes - codeTitle : this.toString( target.getAttribute( 'data-title' ), this.options.codeTitle ).trim(), - codeType : this.toString( target.getAttribute( 'data-type' ), this.options.codeType ).trim(), - minHeight : this.toString( target.getAttribute( 'data-min-height' ), this.options.minHeight ).trim(), - maxHeight : this.toString( target.getAttribute( 'data-max-height' ), this.options.maxHeight ).trim(), - isInline : this.toBoolean( target.getAttribute( 'data-inline' ), this.options.isInline ), - wordWrap : this.toBoolean( target.getAttribute( 'data-wrap' ), this.options.wordWrap ), - startLine : this.toNumeric( target.getAttribute( 'data-start' ), this.options.startLine ), - debugLines : this.toString( target.getAttribute( 'data-debug' ), this.options.debugLines ).trim(), - }); - } - return this; - }, - - /** - * Merge custom options - * @param {Object} options : Options object literal - * @return {Object} : Self - */ - setOptions: function( options ) - { - if( typeof options === 'object' ) - { - for( var key in options ) - { - if( options.hasOwnProperty( key ) ) - { - this.options[ key ] = options[ key ]; - } - } - } - return this; - }, - - /** - * Set and filter source code - * @param {String} code : Code to be highlighted - * @return {Object} : Self - */ - setCode: function( code ) - { - this.code = ( ( typeof code === 'string' ) ? code : '' ) - .replace( /&/g, '&' ) - .replace( /</g, '<' ) - .replace( />/g, '>' ) - .replace( / |\u00a0/gi, '\s' ) - .replace( /\t/g, "\s\s\s\s" ) - .replace( /[\r]+/g, '' ) - .replace( /^[\n]+/, '' ) - .replace( /[\s\t\n\uFEFF\xA0]+$/, '' ); - return this; - }, - - /** - * Processes the code to be highlighted and builds final HTML tags - * @return {String} : Processed code, original code, or fallback message. - */ - processCode: function() - { - this.error = ''; - var code = ''; - - if( !this.code ) - { - this.error = 'This container does not have any code to be highlighted.'; - code = '// No code available.'; // fallback - } - else if( !this.options.codeType ) - { - this.error = 'The syntax type for this container has not been specified.'; - code = this.getCode( true ); // unprocessed - } - else if( !this.hasFilter( this.options.codeType ) ) - { - this.error = 'The syntax type specified ('+ this.options.codeType +') could not be found.'; - code = this.getCode( true ); // unprocessed - } - else // try to process filters and catch any errors - { - try - { - code = this - .applyFilter( this.options.codeType, this.code ) - .replace( /' ) - .replace( new RegExp( this.options.tagOpen+'([A-Z]+)'+this.options.tagSplit, 'g' ), function( m, clss ){ - return '<'+this.options.tagName+' class="'+this.toClass( clss )+'">'; - }.bind( this ) ); - } - catch( e ) - { - var ename = String( e.name || 'ScriptError' ), - einfo = String( e.description || e.message || 'There has been a script error' ), - efile = String( e.file || e.fileName || 'n/a' ), - eline = String( e.line || e.number || e.lineNumber || 'n/a' ); - - this.error = ename +': '+ einfo +' - on file ('+ efile +'), line '+ eline +'.'; - code = this.getCode( true ); // unprocessed - } - } - return code; - }, - - /** - * Returns the original added source code - * @return {String} code : Original code string - */ - getCode: function( esc ) - { - if( esc === true ) - { - return this.code.replace( / 0 ) return line.replace( new RegExp( '^\\s{'+outdent+'}' ), '' ); - return line; - }, - - /** - * Resolve CSS class name for a single line - * @param {Number} num : Line number - * @param {Array} debug : List of line numbers in an array - * @return {String} : Class name - */ - lineClass: function( num, debug ) - { - var tone = ( num % 2 ) ? 'lighter' : 'darker', - clss = ( debug.indexOf( String( num ) ) !== -1 ) ? 'flash' : tone; - return this.options.classPrefix + clss; - }, - - /** - * Toggles a class name for an element - * @param {Object} el : Target element - * @param {String} clss : Class name to toggle - * @return {Object} : Self - */ - toggleClass: function( el, clss ) - { - if( typeof el === 'object' && typeof clss === 'string' ) - { - if( el.classList && el.classList.toggle ) - { - el.classList.toggle( clss ); - } - else if( Array.prototype.indexOf ) - { - var list = String( el.className || "" ).trim().replace( /\s+/g, " " ).split( " " ), - index = list.indexOf( clss ); - - if( index >= 0 ){ list.splice( index, 1 ); } - else{ list.push( clss ); } - el.className = list.join( " " ); - } - } - return this; - }, - - /** - * Render final highlighted code - * return {Object} : Self - */ - render: function() - { - if( this.target ) - { - // try to process/highlight the code - var code = this.processCode(), - c = this.toClass.bind( this ); - - // reset target container - this.target.style['margin'] = '0'; - this.target.style['padding'] = '0'; - this.target.style['border'] = '0'; - this.target.style['text-align'] = 'left'; - - // if showing highlighted code inline - if( this.options.isInline === true ) - { - this.target.style['display'] = 'inline-block'; - this.target.innerHTML = '' + code + ''; - } - else // or, if rendering a pre-style code container - { - var leftSpaces = code.search( /\S|$/ ) || 0, - singleLines = code.split( "\n" ), - totalLines = 0, - numLines = singleLines.length, - debugLines = this.options.debugLines.split( "," ), - startLine = this.options.startLine, - wrapClass = this.options.wordWrap ? 'wordwrap' : 'nowrap', - heightStyle = '', - errorText = '', - lineRows = ''; - - // build each individual line - for( var i=0; i < numLines; i++ ) - { - var lineCode = this.lineOutdent( singleLines[ i ], leftSpaces ), - lineClass = this.lineClass( startLine, debugLines ); - - lineRows += '' + - '
' + - '
' + lineCode + '
' + - '
'; - - startLine++; - totalLines++; - } - - // resolve height restrictions for code scroller - if( this.options.minHeight ) heightStyle += 'min-height: '+ this.options.minHeight + '; '; - if( this.options.maxHeight ) heightStyle += 'max-height: '+ this.options.maxHeight + '; '; - if( this.error ) errorText = '!!!'; - - // add markup to container - this.target.style['display'] = 'block'; - this.target.innerHTML = '' + - '
' + - '
' + - '
'+ this.options.codeTitle +'
' + - '
' + - ' ' + - ' ' + - '' + totalLines + ' '+ ( totalLines === 1 ? 'line' : 'lines' ) +'' + - '
' + - '
' + - '
' + - lineRows + - '
' + - '
'; - - // bind error btn - if( this.error ) - { - this.target.querySelector( '.'+c('error-btn') ).addEventListener( 'click', function( e ){ - alert( this.error ); - }.bind( this ) ); - } - // bind toggle btn - this.target.querySelector( '.'+c('toggle-btn') ).addEventListener( 'click', function( e ){ - var scroller = this.target.querySelector( '.'+c('scroller') ); - this.toggleClass( scroller, c('nonums') ); - }.bind( this ) ); - } - } - }, - - /** - * Factory default list of regex filters to use for highlighting code - * @return void - */ - factory: function() - { - this.reglist = { - - // syntax doctype tags - doctypes: function( code ) - { - code = code.replace( /()/g, this.wrapClass( 'doctype', '$1' ) ); // DOCTYPE - code = code.replace( /(<\?xml[\w\W]+?>)/g, this.wrapClass( 'doctype', '$1' ) ); // xml - code = code.replace( /(<(\?|\%)(php|\=)?)/gi, this.wrapClass( 'doctype', '$1' ) ); // )/g, this.wrapClass( 'doctype', '$1' ) ); // ?>, %> - code = code.replace( /(\#\!\/.*)/g, this.wrapClass( 'doctype', '$1' ) ); // #!/... - return code; - }, - - // constants and other common globals - constants: function( code ) - { - code = code.replace( /(?=.*[A-Z])(\$?(\b(?![\d\#\'\"]+)([A-Z0-9\_]{2,})\b))(?![\:\'\"\(])/g, this.wrapClass( 'global', '$1' ) ); // constants - code = code.replace( /(?=.*[\w]+)([\_]{2}[\w]+)/g, this.wrapClass( 'global', '$1' ) ); // __constants, reserved - return code; - }, - - // full camelcase class names - classes: function( code ) - { - code = code.replace( /(?=.*[a-z])\b(([A-Z]+[a-z0-9]+)+)/g, this.wrapClass( 'class', '$1' ) ); - return code; - }, - - // named functions - functions: function( code ) - { - code = code.replace( /(^|\b[\w\-\!\*]+)(\s*\()/g, this.wrapClass( 'function', '$1' ) +'$2' ); - return code; - }, - - // numbers and hexadecimal values - numbers: function( code ) - { - code = code.replace( /([^\w\-]+)([+-]?(\.?\d)+)(?![\w\'\"])/g, '$1'+ this.wrapClass( 'numeric', '$2') ); - code = code.replace( /(0x[a-fA-F0-9]+)/g, this.wrapClass( 'numeric', '$1' ) ); - return code; - }, - - // common operator symbols in combination - operators: function( code ) - { - code = code.replace( /([\&|\*|\+|\-|\.|\:|\/]{1}\=)(?![\n])/g, this.wrapClass( 'operator', '$1' ) ); // assign *=, += - code = code.replace( /([\<|\>|\!|\=]{1}[\=]{1,2})(?![\n])/g, this.wrapClass( 'operator', '$1' ) ); // compare ==, >=, !== - code = code.replace( /([\<|\>|\+|\-]{2,3})(?![\n])/g, this.wrapClass( 'operator', '$1' ) ); // modify ++, --, >> - code = code.replace( /([\&|\|]{2})(?![\n])/g, this.wrapClass( 'operator', '$1' ) ); // and/or &&, || - code = code.replace( /(([\-|\=]{1}>)|(<[\-|\=]{1}))(?![\n])/g, this.wrapClass( 'operator', '$1' ) ); // arrows ->, <- - code = code.replace( /([\s]+)\B([\<|\>|\&|\=|\%|\?|\:|\*|\+|\-|\^|\~|\/|\|]{1})(?=[\s]+)/g, '$1'+ this.wrapClass( 'operator', '$2' ) ); // single - return code; - }, - - // reserved keywords for most languages - keywords: function( code ) - { - var clss, words = "" + - "var,let,const,static,public,private,protected,function,abstract,interface,return,yield,declare,then,if,else(if)?,els?if," + - "foreach,while,switch,throws?,catch,finally,try,do,as,in,true,false,null,void,class,package,extends?,implements?,namespace," + - "use,new,imports?,exports?,includes?(_once)?,requires?(_once)?,define,ifndef,with,super,from,continue,break,delete,case," + - "global,instanceof,typeof,typedef,NaN,window,document,screen,top,module,goto,volatile,transient,char,parent,def,del,for," + - "fi,except,is,exit,auto,not,or,xor,and,pass,print_?(f|r)?,echo,raise,enum,register,union,endif,endfor,endforeach,endwhile," + - "lambda,long,int,float,double,bool,boolean,short,unsigned,signed,undefined,string,number,any,constructor,self,this,async,await," + - "byte,checked,decimal,delegate,descending,dynamic,event,fixed,group,implicit,internal,into,lock,object,out,override,orderby," + - "params,partial,readonly,ref,sbyte,sealed,stackalloc,select,uint,ulong,extern,inline,sizeof,struct,debugger,eval,get,set," + - "Infinity,caller,die,dump,last,local,my,next,no,our,redo,sub,undef,unless,until,wantarray,all,extends,isnt,final,exposing," + - "loop,of,off,on,throw,when,yes,exec,nonlocal,done,esac,using,assert,arguments,base,by,template,default,native,end"; - - words.split( "," ).forEach( function( word ){ - clss = 'keyword'; - clss = ( /^(import|export|include|require|use|using|from|define|ifndef)/.test( word ) ) ? 'import' : clss; - clss = ( /^(instanceof|typeof|typedef|and|xor|or|is|in|as)$/.test( word ) ) ? 'operator' : clss; - clss = ( /^(window|document|screen|module|global|arguments|parent|self|this)$/.test( word ) ) ? 'class' : clss; - code = code.replace( new RegExp( "(^|[^\\.|\\>|\\-|\\/])([\\$|\\#]?\\b("+word+")\\b)(?![\\=|\\(|\\:])", 'g' ), function( m, m1, m2 ){ - return m1 + this.wrapClass( clss, m2, true ); - }.bind( this ) ); - }.bind( this ) ); - return code; - }, - - // object keys - keys: function( code ) - { - code = code.replace( /([\w\-]+)(([\s]+)?\:)(?=[\s]+)/g, this.wrapClass( 'key', '$1' )+'$2' ) - return code; - }, - - // markup syntax tags - tags: function( code ) - { - return code.replace( /(<[^\!\?\%\#\=]\/?[^>]*>)/gi, function( m, tag ){ - var clss = 'tag'; - clss = ( /^<\/?(style|link|script)/i.test( tag ) ) ? 'hook' : clss; - clss = ( /^<\/?(table|thead|tbody|tfoot|th|tr|td|tf|dd|dt|dl|colgroup|col|caption)/i.test( tag ) ) ? 'table' : clss; - clss = ( /^<\/?(form|fieldset|legend|label|optgroup|option|select|input|textarea|button|datalist|keygen|meter|output)/i.test( tag ) ) ? 'form' : clss; - clss = ( /^<\/?(img|canvas|audio|video|source|track|svg)/i.test( tag ) ) ? 'media' : clss; - clss = ( /^<\/?(i?frame|object|embed)/i.test( tag ) ) ? 'embed' : clss; - return this.wrapClass( clss, tag, true, true ); - }.bind( this ) ); - }, - - // comment blocks and single-line comments - comments: function( code ) - { - // multi-line comments - code = code.replace( /(\/\*[\s\S]*?\*\/)/g, function( m, cmt ){ - return this.wrapClass( 'comment', cmt, true, true ); - }.bind( this ) ); - - // parse slash based single-line commnets without matching urls (http://...) - code = code.replace( /(^|[^\:])(\/\/.*)/g, function( m, left, cmt ){ - return left + this.wrapClass( 'comment', cmt, true ); - }.bind( this ) ); - - // parse dash and pound based single-line commnets, but only if followed by a space - code = code.replace( /((\#+[\ ]+.*)|(\#+[\n]+))/g, function( m, cmt ){ - return this.wrapClass( 'comment', cmt, true ); - }.bind( this ) ); - - return code; - }, - - // string blocks - strings: function( code ) - { - code = code.replace( /([\'|\"|\`]{3}[\s\S]*?[\'|\"|\`]{3})/g, function( m, str ){ - return this.wrapClass( 'string', str, true, true ); // multiline blocks - }.bind( this ) ); - - code = code.replace( /((?:\'[^\'\n\\]*(?:\\.[^\'\n\\]*)*\'))/g, function( m, str ){ - return this.wrapClass( 'string', str, true ); // 'single quotes' - }.bind( this ) ); - - code = code.replace( /((?:\"[^\"\n\\]*(?:\\.[^\"\n\\]*)*\"))/g, function( m, str ){ - return this.wrapClass( 'string', str, true ); // "double quotes" - }.bind( this ) ); - - code = code.replace( /((?:\`[^\`\n\\]*(?:\\.[^\`\n\\]*)*\`))/g, function( m, str ){ - return this.wrapClass( 'string', str, true ); // `backticks` - }.bind( this ) ); - - return code; - }, - - // markup-like syntax - markup: function( code ) - { - code = code.replace( /(]*>)([^<]*)(<\/style>)/g, function( m, open, code, close ){ - return open + this.applyFilter( 'style', code ) + close; // nested css - }.bind( this ) ); - - code = code.replace( /(?!.*src\=)(]*>)([^<]*)(<\/script>)/g, function( m, open, code, close ){ - return open + this.applyFilter( 'default', code ) + close; // nested js - }.bind( this ) ); - - code = code.replace( /(<\?php|<\?=?|<\%\=?)([\w\W]+?)(\?>|\%>)/g, function( m, open, code, close ){ - return open + this.applyFilter( 'default', code ) + close; // nested php - }.bind( this ) ); - - code = code.replace( /()/g, function( m, cmt ){ - return this.wrapClass( 'comment', cmt, true, true ); // multi-line comments - }.bind( this ) ); - - code = code.replace( /()/g, function( m, cmt ){ - return this.wrapClass( 'comment', cmt, true, true ); // multi-line cdata - }.bind( this ) ); - - code = this.applyFilter( 'doctypes', code ); - code = this.applyFilter( 'tags', code ); - code = this.applyFilter( 'strings', code ); - return code; - }, - - // css, less, sass, syntax - style: function( code ) - { - code = code.replace( /([^\{\}\s\;][^\{\}\;]*?)(?=\s*\{)/gi, function( m, sl ){ - return this.wrapClass( 'keyword', sl, false, true ); // multi-line selectors - }.bind( this ) ); - - code = code.replace( /(\@[\w\-]+)/g, this.wrapClass( 'import', '$1' ) ); - code = code.replace( /([\(|\:]\s*)(\#[a-fA-F0-9]+)/g, '$1'+ this.wrapClass( 'value', '$2' ) ); // hex color - code = code.replace( /([\(|\:]\s*)([\w\s\-]+)(?=[\;\s\n])/g, '$1'+ this.wrapClass( 'value', '$2' ) ); // common value - code = code.replace( /(\$[\w\-]+)(?=[\;\,\s\n])/g, this.wrapClass( 'global', '$1' ) ); // variables - code = code.replace( /(\![a-z]+)(?=[\;\s\n])/gi, this.wrapClass( 'important', '$1' ) ); // important - code = code.replace( /([^\w\#])([\+\-]?((\.?\d+)+)(%|em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|px|deg|grad|rad|turn|s|ms|Hz|kHz|dpi|dpcm|dppx)?)/g, '$1'+ this.wrapClass( 'numeric', '$2' ) ); - - code = this.applyFilter( 'keys', code ); - code = this.applyFilter( 'functions', code ); - code = this.applyFilter( 'strings', code ); - code = this.applyFilter( 'comments', code ); - return code; - }, - - // command-line/terminal syntax - terminal: function( code ) - { - code = code.replace( /(^|[^\:])(\/\/\s+.*)/g, function( m, left, cmt ){ - return left + this.wrapClass( 'comment', cmt, true ); - }.bind( this ) ); - - code = code.replace( /(\$|\#)(\s+)([\w\-]+)/g, function( m, user, space, prog ){ - return this.wrapClass( 'important', user ) + space + this.wrapClass( 'class', prog ); - }.bind( this ) ); - - code = this.applyFilter( 'strings', code ); - return code; - }, - - // shell script syntax - shell: function( code ) - { - code = this.applyFilter( 'constants', code ); - code = this.applyFilter( 'doctypes', code ); - code = this.applyFilter( 'functions', code ); - code = this.applyFilter( 'numbers', code ); - code = this.applyFilter( 'keywords', code ); - code = this.applyFilter( 'operators', code ); - code = this.applyFilter( 'strings', code ); - - code = code.replace( /([^\$\!\{\[\\])(\#+(?![\!]).*)/g, function( m, left, cmt ){ - return left + this.wrapClass( 'comment', cmt, true ); - }.bind( this ) ); - - return code; - }, - - // JS object literal key/value pairs syntax - object: function( code ) - { - code = this.applyFilter( 'constants', code ); - code = this.applyFilter( 'classes', code ); - code = this.applyFilter( 'functions', code ); - code = this.applyFilter( 'numbers', code ); - code = this.applyFilter( 'keywords', code ); - code = this.applyFilter( 'keys', code ); - code = this.applyFilter( 'strings', code ); - code = this.applyFilter( 'comments', code ); - return code; - }, - - // JSON string key/value pairs syntax - json: function( code ) - { - code = this.applyFilter( 'strings', code ); - code = this.applyFilter( 'comments', code ); - return code; - }, - - // slq-like syntax highlighting - sql: function( code ) - { - code = this.applyFilter( 'constants', code ); - code = this.applyFilter( 'functions', code ); - code = this.applyFilter( 'numbers', code ); - code = this.applyFilter( 'operators', code ); - code = this.applyFilter( 'strings', code ); - code = this.applyFilter( 'comments', code ); - - code = code.replace( /(\-\-.*)/gi, function( m, cmt ){ - return this.wrapClass( 'comment', cmt, true ); - }.bind( this ) ); - - return code; - }, - - // default syntax highlighting for most languages - default: function( code ) - { - code = this.applyFilter( 'constants', code ); - code = this.applyFilter( 'doctypes', code ); - code = this.applyFilter( 'classes', code ); - code = this.applyFilter( 'functions', code ); - code = this.applyFilter( 'numbers', code ); - code = this.applyFilter( 'keywords', code ); - code = this.applyFilter( 'operators', code ); - code = this.applyFilter( 'strings', code ); - code = this.applyFilter( 'comments', code ); - return code; - }, - - // ... - }; - }, - }; - return Syntaxy; -}); - +!function(t){"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?module.exports=t:window&&(window.Syntaxy=t(window.jQuery||null))}(function(t){"function"!=typeof String.prototype.ltrim&&(String.prototype.ltrim=function(){return this.replace(/^[\s\uFEFF\xA0]+/g,"")}),"function"!=typeof String.prototype.rtrim&&(String.prototype.rtrim=function(){return this.replace(/[\s\uFEFF\xA0]+$/g,"")}),"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")}),t&&t.fn&&!t.fn.syntaxy&&(t.fn.syntaxy=function(t){return this.each(function(){var i=new e(this,t);i.render()})});var e=function(t,e){this.target=null,this.reglist={},this.code="",this.error="",this.options={tagOpen:"«",tagSplit:"≈",tagClose:"»",tagName:"span",classPrefix:"stx-",codeTitle:"Source code",codeType:"",minHeight:"100px",maxHeight:"600px",isInline:!1,wordWrap:!1,startLine:1,debugLines:""},this.setTarget(t),this.setOptions(e),this.factory()};return e.prototype={constructor:e,setTarget:function(t){return"object"==typeof t&&(this.target=t,this.setCode(t.innerHTML||""),this.setOptions({codeTitle:this.toString(t.getAttribute("data-title"),this.options.codeTitle).trim(),codeType:this.toString(t.getAttribute("data-type"),this.options.codeType).trim(),minHeight:this.toString(t.getAttribute("data-min-height"),this.options.minHeight).trim(),maxHeight:this.toString(t.getAttribute("data-max-height"),this.options.maxHeight).trim(),isInline:this.toBoolean(t.getAttribute("data-inline"),this.options.isInline),wordWrap:this.toBoolean(t.getAttribute("data-wrap"),this.options.wordWrap),startLine:this.toNumeric(t.getAttribute("data-start"),this.options.startLine),debugLines:this.toString(t.getAttribute("data-debug"),this.options.debugLines).trim()})),this},setOptions:function(t){if("object"==typeof t)for(var e in t)t.hasOwnProperty(e)&&(this.options[e]=t[e]);return this},setCode:function(t){return this.code=("string"==typeof t?t:"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/ |\u00a0/gi,"s").replace(/\t/g,"ssss").replace(/[\r]+/g,"").replace(/^[\n]+/,"").replace(/[\s\t\n\uFEFF\xA0]+$/,""),this},processCode:function(){this.error="";var t="";if(this.code)if(this.options.codeType)if(this.hasFilter(this.options.codeType))try{t=this.applyFilter(this.options.codeType,this.code).replace(/").replace(new RegExp(this.options.tagOpen+"([A-Z]+)"+this.options.tagSplit,"g"),function(t,e){return"<"+this.options.tagName+' class="'+this.toClass(e)+'">'}.bind(this))}catch(e){var i=String(e.name||"ScriptError"),s=String(e.description||e.message||"There has been a script error"),r=String(e.file||e.fileName||"n/a"),n=String(e.line||e.number||e.lineNumber||"n/a");this.error=i+": "+s+" - on file ("+r+"), line "+n+".",t=this.getCode(!0)}else this.error="The syntax type specified ("+this.options.codeType+") could not be found.",t=this.getCode(!0);else this.error="The syntax type for this container has not been specified.",t=this.getCode(!0);else this.error="This container does not have any code to be highlighted.",t="// No code available.";return t},getCode:function(t){return t===!0?this.code.replace(/0?t.replace(new RegExp("^\\s{"+e+"}"),""):t},lineClass:function(t,e){var i=t%2?"lighter":"darker",s=-1!==e.indexOf(String(t))?"flash":i;return this.options.classPrefix+s},toggleClass:function(t,e){if("object"==typeof t&&"string"==typeof e)if(t.classList&&t.classList.toggle)t.classList.toggle(e);else if(Array.prototype.indexOf){var i=String(t.className||"").trim().replace(/\s+/g," ").split(" "),s=i.indexOf(e);s>=0?i.splice(s,1):i.push(e),t.className=i.join(" ")}return this},render:function(){if(this.target){var t=this.processCode(),e=this.toClass.bind(this);if(this.target.style.margin="0",this.target.style.padding="0",this.target.style.border="0",this.target.style["text-align"]="left",this.options.isInline===!0)this.target.style.display="inline-block",this.target.innerHTML=''+t+"";else{for(var i=t.search(/\S|$/)||0,s=t.split("\n"),r=0,n=s.length,a=this.options.debugLines.split(","),o=this.options.startLine,l=this.options.wordWrap?"wordwrap":"nowrap",p="",c="",h="",u=0;n>u;u++){var g=this.lineOutdent(s[u],i),d=this.lineClass(o,a);h+='
'+g+"
",o++,r++}this.options.minHeight&&(p+="min-height: "+this.options.minHeight+"; "),this.options.maxHeight&&(p+="max-height: "+this.options.maxHeight+"; "),this.error&&(c="!!!"),this.target.style.display="block",this.target.innerHTML='
'+this.options.codeTitle+'
'+r+" "+(1===r?"line":"lines")+'
'+h+"
",this.error&&this.target.querySelector("."+e("error-btn")).addEventListener("click",function(t){alert(this.error)}.bind(this)),this.target.querySelector("."+e("toggle-btn")).addEventListener("click",function(t){var i=this.target.querySelector("."+e("scroller"));this.toggleClass(i,e("nonums"))}.bind(this))}}},factory:function(){this.reglist={doctypes:function(t){return t=t.replace(/()/g,this.wrapClass("doctype","$1")),t=t.replace(/(<\?xml[\w\W]+?>)/g,this.wrapClass("doctype","$1")),t=t.replace(/(<(\?|\%)(php|\=)?)/gi,this.wrapClass("doctype","$1")),t=t.replace(/((\%|\?)>)/g,this.wrapClass("doctype","$1")),t=t.replace(/(\#\!\/.*)/g,this.wrapClass("doctype","$1"))},constants:function(t){return t=t.replace(/(?=.*[A-Z])(\$?(\b(?![\d\#\'\"]+)([A-Z0-9\_]{2,})\b))(?![\:\'\"\(])/g,this.wrapClass("global","$1")),t=t.replace(/(?=.*[\w]+)([\_]{2}[\w]+)/g,this.wrapClass("global","$1"))},classes:function(t){return t=t.replace(/(?=.*[a-z])\b(([A-Z]+[a-z0-9]+)+)/g,this.wrapClass("class","$1"))},functions:function(t){return t=t.replace(/(^|\b[\w\-\!\*]+)(\s*\()/g,this.wrapClass("function","$1")+"$2")},numbers:function(t){return t=t.replace(/([^\w\-]+)([+-]?(\.?\d)+)(?![\w\'\"])/g,"$1"+this.wrapClass("numeric","$2")),t=t.replace(/(0x[a-fA-F0-9]+)/g,this.wrapClass("numeric","$1"))},operators:function(t){return t=t.replace(/([\&|\*|\+|\-|\.|\:|\/]{1}\=)(?![\n])/g,this.wrapClass("operator","$1")),t=t.replace(/([\<|\>|\!|\=]{1}[\=]{1,2})(?![\n])/g,this.wrapClass("operator","$1")),t=t.replace(/([\<|\>|\+|\-]{2,3})(?![\n])/g,this.wrapClass("operator","$1")),t=t.replace(/([\&|\|]{2})(?![\n])/g,this.wrapClass("operator","$1")),t=t.replace(/(([\-|\=]{1}>)|(<[\-|\=]{1}))(?![\n])/g,this.wrapClass("operator","$1")),t=t.replace(/([\s]+)\B([\<|\>|\&|\=|\%|\?|\:|\*|\+|\-|\^|\~|\/|\|]{1})(?=[\s]+)/g,"$1"+this.wrapClass("operator","$2"))},keywords:function(t){var e,i="var,let,const,static,public,private,protected,function,abstract,interface,return,yield,declare,then,if,else(if)?,els?if,foreach,while,switch,throws?,catch,finally,try,do,as,in,true,false,null,void,class,package,extends?,implements?,namespace,use,new,imports?,exports?,includes?(_once)?,requires?(_once)?,define,ifndef,with,super,from,continue,break,delete,case,global,instanceof,typeof,typedef,NaN,window,document,screen,top,module,goto,volatile,transient,char,parent,def,del,for,fi,except,is,exit,auto,not,or,xor,and,pass,print_?(f|r)?,echo,raise,enum,register,union,endif,endfor,endforeach,endwhile,lambda,long,int,float,double,bool,boolean,short,unsigned,signed,undefined,string,number,any,constructor,self,this,async,await,byte,checked,decimal,delegate,descending,dynamic,event,fixed,group,implicit,internal,into,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,select,uint,ulong,extern,inline,sizeof,struct,debugger,eval,get,set,Infinity,caller,die,dump,last,local,my,next,no,our,redo,sub,undef,unless,until,wantarray,all,extends,isnt,final,exposing,loop,of,off,on,throw,when,yes,exec,nonlocal,done,esac,using,assert,arguments,base,by,template,default,native,end";return i.split(",").forEach(function(i){e="keyword",e=/^(import|export|include|require|use|using|from|define|ifndef)/.test(i)?"import":e,e=/^(instanceof|typeof|typedef|and|xor|or|is|in|as)$/.test(i)?"operator":e,e=/^(window|document|screen|module|global|arguments|parent|self|this)$/.test(i)?"class":e,t=t.replace(new RegExp("(^|[^\\.|\\>|\\-|\\/])([\\$|\\#]?\\b("+i+")\\b)(?![\\=|\\(|\\:])","g"),function(t,i,s){return i+this.wrapClass(e,s,!0)}.bind(this))}.bind(this)),t},keys:function(t){return t=t.replace(/([\w\-]+)(([\s]+)?\:)(?=[\s]+)/g,this.wrapClass("key","$1")+"$2")},tags:function(t){return t.replace(/(<[^\!\?\%\#\=]\/?[^>]*>)/gi,function(t,e){var i="tag";return i=/^<\/?(style|link|script)/i.test(e)?"hook":i,i=/^<\/?(table|thead|tbody|tfoot|th|tr|td|tf|dd|dt|dl|colgroup|col|caption)/i.test(e)?"table":i,i=/^<\/?(form|fieldset|legend|label|optgroup|option|select|input|textarea|button|datalist|keygen|meter|output)/i.test(e)?"form":i,i=/^<\/?(img|canvas|audio|video|source|track|svg)/i.test(e)?"media":i,i=/^<\/?(i?frame|object|embed)/i.test(e)?"embed":i,this.wrapClass(i,e,!0,!0)}.bind(this))},comments:function(t){return t=t.replace(/(\/\*[\s\S]*?\*\/)/g,function(t,e){return this.wrapClass("comment",e,!0,!0)}.bind(this)),t=t.replace(/(^|[^\:])(\/\/.*)/g,function(t,e,i){return e+this.wrapClass("comment",i,!0)}.bind(this)),t=t.replace(/((\#+[\ ]+.*)|(\#+[\n]+))/g,function(t,e){return this.wrapClass("comment",e,!0)}.bind(this))},strings:function(t){return t=t.replace(/([\'|\"|\`]{3}[\s\S]*?[\'|\"|\`]{3})/g,function(t,e){return this.wrapClass("string",e,!0,!0)}.bind(this)),t=t.replace(/((?:\'[^\'\n\\]*(?:\\.[^\'\n\\]*)*\'))/g,function(t,e){return this.wrapClass("string",e,!0)}.bind(this)),t=t.replace(/((?:\"[^\"\n\\]*(?:\\.[^\"\n\\]*)*\"))/g,function(t,e){return this.wrapClass("string",e,!0)}.bind(this)),t=t.replace(/((?:\`[^\`\n\\]*(?:\\.[^\`\n\\]*)*\`))/g,function(t,e){return this.wrapClass("string",e,!0)}.bind(this))},markup:function(t){return t=t.replace(/(]*>)([^<]*)(<\/style>)/g,function(t,e,i,s){return e+this.applyFilter("style",i)+s}.bind(this)),t=t.replace(/(?!.*src\=)(]*>)([^<]*)(<\/script>)/g,function(t,e,i,s){return e+this.applyFilter("default",i)+s}.bind(this)),t=t.replace(/(<\?php|<\?=?|<\%\=?)([\w\W]+?)(\?>|\%>)/g,function(t,e,i,s){return e+this.applyFilter("default",i)+s}.bind(this)),t=t.replace(/()/g,function(t,e){return this.wrapClass("comment",e,!0,!0)}.bind(this)),t=t.replace(/()/g,function(t,e){return this.wrapClass("comment",e,!0,!0)}.bind(this)),t=this.applyFilter("doctypes",t),t=this.applyFilter("tags",t),t=this.applyFilter("strings",t)},style:function(t){return t=t.replace(/([^\{\}\s\;][^\{\}\;]*?)(?=\s*\{)/gi,function(t,e){return this.wrapClass("keyword",e,!1,!0)}.bind(this)),t=t.replace(/(\@[\w\-]+)/g,this.wrapClass("import","$1")),t=t.replace(/([\(|\:]\s*)(\#[a-fA-F0-9]+)/g,"$1"+this.wrapClass("value","$2")),t=t.replace(/([\(|\:]\s*)([\w\s\-]+)(?=[\;\s\n])/g,"$1"+this.wrapClass("value","$2")),t=t.replace(/(\$[\w\-]+)(?=[\;\,\s\n])/g,this.wrapClass("global","$1")),t=t.replace(/(\![a-z]+)(?=[\;\s\n])/gi,this.wrapClass("important","$1")),t=t.replace(/([^\w\#])([\+\-]?((\.?\d+)+)(%|em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|px|deg|grad|rad|turn|s|ms|Hz|kHz|dpi|dpcm|dppx)?)/g,"$1"+this.wrapClass("numeric","$2")),t=this.applyFilter("keys",t),t=this.applyFilter("functions",t),t=this.applyFilter("strings",t),t=this.applyFilter("comments",t)},terminal:function(t){return t=t.replace(/(^|[^\:])(\/\/\s+.*)/g,function(t,e,i){return e+this.wrapClass("comment",i,!0)}.bind(this)),t=t.replace(/(\$|\#)(\s+)([\w\-]+)/g,function(t,e,i,s){return this.wrapClass("important",e)+i+this.wrapClass("class",s)}.bind(this)),t=this.applyFilter("strings",t)},shell:function(t){return t=this.applyFilter("constants",t),t=this.applyFilter("doctypes",t),t=this.applyFilter("functions",t),t=this.applyFilter("numbers",t),t=this.applyFilter("keywords",t),t=this.applyFilter("operators",t),t=this.applyFilter("strings",t),t=t.replace(/([^\$\!\{\[\\])(\#+(?![\!]).*)/g,function(t,e,i){return e+this.wrapClass("comment",i,!0)}.bind(this))},object:function(t){return t=this.applyFilter("constants",t),t=this.applyFilter("classes",t),t=this.applyFilter("functions",t),t=this.applyFilter("numbers",t),t=this.applyFilter("keywords",t),t=this.applyFilter("keys",t),t=this.applyFilter("strings",t),t=this.applyFilter("comments",t)},json:function(t){return t=this.applyFilter("strings",t),t=this.applyFilter("comments",t)},sql:function(t){return t=this.applyFilter("constants",t),t=this.applyFilter("functions",t),t=this.applyFilter("numbers",t),t=this.applyFilter("operators",t),t=this.applyFilter("strings",t),t=this.applyFilter("comments",t),t=t.replace(/(\-\-.*)/gi,function(t,e){return this.wrapClass("comment",e,!0)}.bind(this))},"default":function(t){return t=this.applyFilter("constants",t),t=this.applyFilter("doctypes",t),t=this.applyFilter("classes",t),t=this.applyFilter("functions",t),t=this.applyFilter("numbers",t),t=this.applyFilter("keywords",t),t=this.applyFilter("operators",t),t=this.applyFilter("strings",t),t=this.applyFilter("comments",t)}}}},e}); \ No newline at end of file