(function(){ // private helper vars var lang = /\blang(?:uage)?-(?!\*)(\w+)\b/i; var _ = self.prism = { util: { type: function (o) { return object.prototype.tostring.call(o).match(/\[object (\w+)\]/)[1]; }, // deep clone a language definition (e.g. to extend it) clone: function (o) { var type = _.util.type(o); switch (type) { case 'object': var clone = {}; for (var key in o) { if (o.hasownproperty(key)) { clone[key] = _.util.clone(o[key]); } } return clone; case 'array': return o.slice(); } return o; } }, languages: { extend: function (id, redef) { var lang = _.util.clone(_.languages[id]); for (var key in redef) { lang[key] = redef[key]; } return lang; }, // insert a token before another token in a language literal insertbefore: function (inside, before, insert, root) { root = root || _.languages; var grammar = root[inside]; 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]; } } return root[inside] = ret; }, // traverse a language definition with depth first search dfs: function(o, callback) { for (var i in o) { callback.call(o, i, o[i]); if (_.util.type(o) === 'object') { _.languages.dfs(o[i], callback); } } } }, highlightall: function(async, callback) { var elements = document.queryselectorall('code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'); for (var i=0, element; element = elements[i++];) { _.highlightelement(element, async === true, callback); } }, highlightelement: function(element, async, callback) { // find language var language, grammar, parent = element; while (parent && !lang.test(parent.classname)) { parent = parent.parentnode; } if (parent) { language = (parent.classname.match(lang) || [,''])[1]; grammar = _.languages[language]; } if (!grammar) { return; } // set language on the element, if not present element.classname = element.classname.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language; // set language on the parent, for styling parent = element.parentnode; if (/pre/i.test(parent.nodename)) { parent.classname = parent.classname.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language; } var code = element.textcontent; if(!code) { return; } code = code.replace(/&/g, '&').replace(/ text.length) { // something went terribly wrong, abort, abort! break tokenloop; } if (str instanceof token) { continue; } pattern.lastindex = 0; var match = pattern.exec(str); if (match) { if(lookbehind) { lookbehindlength = match[1].length; } var from = match.index - 1 + lookbehindlength, match = match[0].slice(lookbehindlength), len = match.length, to = from + len, before = str.slice(0, from + 1), after = str.slice(to + 1); var args = [i, 1]; if (before) { args.push(before); } var wrapped = new token(token, inside? _.tokenize(match, inside) : match); args.push(wrapped); if (after) { args.push(after); } array.prototype.splice.apply(strarr, args); } } } return strarr; }, hooks: { all: {}, add: function (name, callback) { var hooks = _.hooks.all; hooks[name] = hooks[name] || []; hooks[name].push(callback); }, run: function (name, env) { var callbacks = _.hooks.all[name]; if (!callbacks || !callbacks.length) { return; } for (var i=0, callback; callback = callbacks[i++];) { callback(env); } } } }; var token = _.token = function(type, content) { this.type = type; this.content = content; }; token.stringify = function(o, language, parent) { if (typeof o == 'string') { return o; } if (object.prototype.tostring.call(o) == '[object array]') { return o.map(function(element) { return token.stringify(element, language, o); }).join(''); } var env = { type: o.type, content: token.stringify(o.content, language, parent), tag: 'span', classes: ['token', o.type], attributes: {}, language: language, parent: parent }; if (env.type == 'comment') { env.attributes['spellcheck'] = 'true'; } _.hooks.run('wrap', env); var attributes = ''; for (var name in env.attributes) { attributes += name + '="' + (env.attributes[name] || '') + '"'; } return '<' + env.tag + ' class="' + env.classes.join(' ') + '" ' + attributes + '>' + env.content + ''; }; if (!self.document) { // in worker self.addeventlistener('message', function(evt) { var message = json.parse(evt.data), lang = message.language, code = message.code; self.postmessage(json.stringify(_.tokenize(code, _.languages[lang]))); self.close(); }, false); return; } // get current script and highlight var script = document.getelementsbytagname('script'); script = script[script.length - 1]; if (script) { _.filename = script.src; if (document.addeventlistener && !script.hasattribute('data-manual')) { document.addeventlistener('domcontentloaded', _.highlightall); } } })(); /* ********************************************** begin prism-markup.js ********************************************** */ prism.languages.markup = { 'comment': /<!--[\w\w]*?-->/g, 'prolog': /<\?.+?\?>/, 'doctype': /<!doctype.+?>/, 'cdata': /<!\[cdata\[[\w\w]*?]]>/i, 'tag': { pattern: /<\/?[\w:-]+\s*(?:\s+[\w:-]+(?:=(?:("|')(\\?[\w\w])*?\1|\w+))?\s*)*\/?>/gi, inside: { 'tag': { pattern: /^<\/?[\w:-]+/i, inside: { 'punctuation': /^<\/?/, 'namespace': /^[\w-]+?:/ } }, 'attr-value': { pattern: /=(?:('|")[\w\w]*?(\1)|[^\s>]+)/gi, inside: { 'punctuation': /=|>|"/g } }, 'punctuation': /\/?>/g, 'attr-name': { pattern: /[\w:-]+/g, inside: { 'namespace': /^[\w-]+?:/ } } } }, 'entity': /&#?[\da-z]{1,8};/gi }; // plugin to make entity title show the real entity, idea by roman komarov prism.hooks.add('wrap', function(env) { if (env.type === 'entity') { env.attributes['title'] = env.content.replace(/&/, '&'); } }); /* ********************************************** begin prism-css.js ********************************************** */ prism.languages.css = { 'comment': /\/\*[\w\w]*?\*\//g, 'atrule': { pattern: /@[\w-]+?.*?(;|(?=\s*{))/gi, inside: { 'punctuation': /[;:]/g } }, 'url': /url\((["']?).*?\1\)/gi, 'selector': /[^\{\}\s][^\{\};]*(?=\s*\{)/g, 'property': /(\b|\b)[\w-]+(?=\s*:)/ig, 'string': /("|')(\\?.)*?\1/g, 'important': /\b!important\b/gi, 'ignore': /&(lt|gt|amp);/gi, 'punctuation': /[\{\};:]/g }; if (prism.languages.markup) { prism.languages.insertbefore('markup', 'tag', { 'style': { pattern: /(<|<)style[\w\w]*?(>|>)[\w\w]*?(<|<)\/style(>|>)/ig, inside: { 'tag': { pattern: /(<|<)style[\w\w]*?(>|>)|(<|<)\/style(>|>)/ig, inside: prism.languages.markup.tag.inside }, rest: prism.languages.css } } }); } /* ********************************************** begin prism-clike.js ********************************************** */ prism.languages.clike = { 'comment': { pattern: /(^|[^\\])(\/\*[\w\w]*?\*\/|(^|[^:])\/\/.*?(\r?\n|$))/g, lookbehind: true }, 'string': /("|')(\\?.)*?\1/g, 'class-name': { pattern: /((?:class|interface|extends|implements|trait|instanceof|new)\s+)[a-z0-9_\.\\]+/ig, lookbehind: true, inside: { punctuation: /(\.|\\)/ } }, 'keyword': /\b(if|else|while|do|for|return|in|instanceof|function|new|try|catch|finally|null|break|continue)\b/g, 'boolean': /\b(true|false)\b/g, 'function': { pattern: /[a-z0-9_]+\(/ig, inside: { punctuation: /\(/ } }, 'number': /\b-?(0x[\da-fa-f]+|\d*\.?\d+([ee]-?\d+)?)\b/g, 'operator': /[-+]{1,2}|!|=?<|=?>|={1,2}|(&){1,2}|\|?\||\?|\*|\/|\~|\^|\%/g, 'ignore': /&(lt|gt|amp);/gi, 'punctuation': /[{}[\];(),.:]/g }; /* ********************************************** begin prism-javascript.js ********************************************** */ prism.languages.javascript = prism.languages.extend('clike', { 'keyword': /\b(var|let|if|else|while|do|for|return|in|instanceof|function|new|with|typeof|try|catch|finally|null|break|continue)\b/g, 'number': /\b-?(0x[\da-fa-f]+|\d*\.?\d+([ee]-?\d+)?|nan|-?infinity)\b/g }); prism.languages.insertbefore('javascript', 'keyword', { 'regex': { pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\r\n])+\/[gim]{0,3}(?=\s*($|[\r\n,.;})]))/g, lookbehind: true } }); if (prism.languages.markup) { prism.languages.insertbefore('markup', 'tag', { 'script': { pattern: /(<|<)script[\w\w]*?(>|>)[\w\w]*?(<|<)\/script(>|>)/ig, inside: { 'tag': { pattern: /(<|<)script[\w\w]*?(>|>)|(<|<)\/script(>|>)/ig, inside: prism.languages.markup.tag.inside }, rest: prism.languages.javascript } } }); } /* ********************************************** begin prism-file-highlight.js ********************************************** */ (function(){ if (!self.prism || !self.document || !document.queryselector) { return; } var extensions = { 'js': 'javascript', 'html': 'markup', 'svg': 'markup' }; array.prototype.slice.call(document.queryselectorall('pre[data-src]')).foreach(function(pre) { var src = pre.getattribute('data-src'); var extension = (src.match(/\.(\w+)$/) || [,''])[1]; var language = extensions[extension] || extension; var code = document.createelement('code'); code.classname = 'language-' + language; pre.textcontent = ''; code.textcontent = 'loading…'; pre.appendchild(code); var xhr = new xmlhttprequest(); xhr.open('get', src, true); xhr.onreadystatechange = function() { if (xhr.readystate == 4) { if (xhr.status < 400 && xhr.responsetext) { code.textcontent = xhr.responsetext; prism.highlightelement(code); } else if (xhr.status >= 400) { code.textcontent = '✖ error ' + xhr.status + ' while fetching file: ' + xhr.statustext; } else { code.textcontent = '✖ error: file does not exist or is empty'; } } }; xhr.send(null); }); })();