1 line
48 KiB
JSON
1 line
48 KiB
JSON
|
{"ast":null,"code":"var _self = typeof window !== 'undefined' ? window // if in browser\n: typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope ? self // if in worker\n: {} // if in node js\n;\n/**\n * Prism: Lightweight, robust, elegant syntax highlighting\n * MIT license http://www.opensource.org/licenses/mit-license.php/\n * @author Lea Verou http://lea.verou.me\n */\n\n\nvar Prism = function () {\n // Private helper vars\n var lang = /\\blang(?:uage)?-(\\w+)\\b/i;\n var uniqueId = 0;\n\n var _ = _self.Prism = {\n manual: _self.Prism && _self.Prism.manual,\n disableWorkerMessageHandler: _self.Prism && _self.Prism.disableWorkerMessageHandler,\n util: {\n encode: function encode(tokens) {\n if (tokens instanceof Token) {\n return new Token(tokens.type, _.util.encode(tokens.content), tokens.alias);\n } else if (_.util.type(tokens) === 'Array') {\n return tokens.map(_.util.encode);\n } else {\n return tokens.replace(/&/g, '&').replace(/</g, '<').replace(/\\u00a0/g, ' ');\n }\n },\n type: function type(o) {\n return Object.prototype.toString.call(o).match(/\\[object (\\w+)\\]/)[1];\n },\n objId: function objId(obj) {\n if (!obj['__id']) {\n Object.defineProperty(obj, '__id', {\n value: ++uniqueId\n });\n }\n\n return obj['__id'];\n },\n // Deep clone a language definition (e.g. to extend it)\n clone: function clone(o) {\n var type = _.util.type(o);\n\n switch (type) {\n case 'Object':\n var clone = {};\n\n for (var key in o) {\n if (o.hasOwnProperty(key)) {\n clone[key] = _.util.clone(o[key]);\n }\n }\n\n return clone;\n\n case 'Array':\n return o.map(function (v) {\n return _.util.clone(v);\n });\n }\n\n return o;\n }\n },\n languages: {\n extend: function extend(id, redef) {\n var lang = _.util.clone(_.languages[id]);\n\n for (var key in redef) {\n lang[key] = redef[key];\n }\n\n return lang;\n },\n\n /**\n * Insert a token before another token in a language literal\n * As this needs to recreate the object (we cannot actually insert before keys in object literals),\n * we cannot just provide an object, we need anobject and a key.\n * @param inside The key (or language id) of the parent\n * @param before The key to insert before. If not provided, the function appends instead.\n * @param insert Object with the key/value pairs to insert\n * @param root The object that contains `inside`. If equal to Prism.languages, it can be omitted.\n */\n insertBefore: function insertBefore(inside, before, insert, root) {\n root = root || _.languages;\n var grammar = root[inside];\n\n if (arguments.length == 2) {\n insert = arguments[1];\n\n for (var newToken in insert) {\n if (insert.hasOwnProperty(newToken)) {\n grammar[newToken] = insert[newToken];\n }\n }\n\n return grammar;\n }\n\n var ret = {};\n\n for (var token in grammar) {\n if (grammar.hasOwnProperty(token)) {\n if (token == before) {\n for (var newToken in insert) {\n if (insert.hasOwnProperty(newToken)) {\n ret[newToken] = insert[newToken];\n }\n }\n }\n\n ret[token] = grammar[token];\n }\n } // Update references in other language definitions\n\n\n _.languages.DFS(_.languages, function (key, value) {\n if (value === root[inside] && key != inside) {\n this[key] = ret;\n }\n });\n\n return root[inside] = ret;\n },\n // Traverse a language definition with Depth First Search\n DFS: function DFS(o, callback
|