Notes

syntax highlighting colors

Edit on GitHub

Jekyll
14 minutes

this file is for testing syntax highlighting theme..

  1/* **********************************************
  2     Begin prism-core.js
  3********************************************** */
  4
  5var _self = (typeof window !== 'undefined')
  6	? window   // if in browser
  7	: (
  8		(typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope)
  9		? self // if in worker
 10		: {}   // if in node js
 11	);
 12
 13/**
 14 * Prism: Lightweight, robust, elegant syntax highlighting
 15 * MIT license http://www.opensource.org/licenses/mit-license.php/
 16 * @author Lea Verou http://lea.verou.me
 17 */
 18
 19var Prism = (function(){
 20
 21// Private helper vars
 22var lang = /\blang(?:uage)?-(\w+)\b/i;
 23var uniqueId = 0;
 24
 25var _ = _self.Prism = {
 26	manual: _self.Prism && _self.Prism.manual,
 27	util: {
 28		encode: function (tokens) {
 29			if (tokens instanceof Token) {
 30				return new Token(tokens.type, _.util.encode(tokens.content), tokens.alias);
 31			} else if (_.util.type(tokens) === 'Array') {
 32				return tokens.map(_.util.encode);
 33			} else {
 34				return tokens.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/\u00a0/g, ' ');
 35			}
 36		},
 37
 38		type: function (o) {
 39			return Object.prototype.toString.call(o).match(/\[object (\w+)\]/)[1];
 40		},
 41
 42		objId: function (obj) {
 43			if (!obj['__id']) {
 44				Object.defineProperty(obj, '__id', { value: ++uniqueId });
 45			}
 46			return obj['__id'];
 47		},
 48
 49		// Deep clone a language definition (e.g. to extend it)
 50		clone: function (o) {
 51			var type = _.util.type(o);
 52
 53			switch (type) {
 54				case 'Object':
 55					var clone = {};
 56
 57					for (var key in o) {
 58						if (o.hasOwnProperty(key)) {
 59							clone[key] = _.util.clone(o[key]);
 60						}
 61					}
 62
 63					return clone;
 64
 65				case 'Array':
 66					// Check for existence for IE8
 67					return o.map && o.map(function(v) { return _.util.clone(v); });
 68			}
 69
 70			return o;
 71		}
 72	},
 73
 74	languages: {
 75		extend: function (id, redef) {
 76			var lang = _.util.clone(_.languages[id]);
 77
 78			for (var key in redef) {
 79				lang[key] = redef[key];
 80			}
 81
 82			return lang;
 83		},
 84
 85		/**
 86		 * Insert a token before another token in a language literal
 87		 * As this needs to recreate the object (we cannot actually insert before keys in object literals),
 88		 * we cannot just provide an object, we need anobject and a key.
 89		 * @param inside The key (or language id) of the parent
 90		 * @param before The key to insert before. If not provided, the function appends instead.
 91		 * @param insert Object with the key/value pairs to insert
 92		 * @param root The object that contains `inside`. If equal to Prism.languages, it can be omitted.
 93		 */
 94		insertBefore: function (inside, before, insert, root) {
 95			root = root || _.languages;
 96			var grammar = root[inside];
 97
 98			if (arguments.length == 2) {
 99				insert = arguments[1];
100
101				for (var newToken in insert) {
102					if (insert.hasOwnProperty(newToken)) {
103						grammar[newToken] = insert[newToken];
104					}
105				}
106
107				return grammar;
108			}
109
110			var ret = {};
111
112			for (var token in grammar) {
113
114				if (grammar.hasOwnProperty(token)) {
115
116					if (token == before) {
117
118						for (var newToken in insert) {
119
120							if (insert.hasOwnProperty(newToken)) {
121								ret[newToken] = insert[newToken];
122							}
123						}
124					}
125
126					ret[token] = grammar[token];
127				}
128			}
129
130			// Update references in other language definitions
131			_.languages.DFS(_.languages, function(key, value) {
132				if (value === root[inside] && key != inside) {
133					this[key] = ret;
134				}
135			});
136
137			return root[inside] = ret;
138		},
139
140		// Traverse a language definition with Depth First Search
141		DFS: function(o, callback, type, visited) {
142			visited = visited || {};
143			for (var i in o) {
144				if (o.hasOwnProperty(i)) {
145					callback.call(o, i, o[i], type || i);
146
147					if (_.util.type(o[i]) === 'Object' && !visited[_.util.objId(o[i])]) {
148						visited[_.util.objId(o[i])] = true;
149						_.languages.DFS(o[i], callback, null, visited);
150					}
151					else if (_.util.type(o[i]) === 'Array' && !visited[_.util.objId(o[i])]) {
152						visited[_.util.objId(o[i])] = true;
153						_.languages.DFS(o[i], callback, i, visited);
154					}
155				}
156			}
157		}
158	},
159	plugins: {},
160
161	highlightAll: function(async, callback) {
162		var env = {
163			callback: callback,
164			selector: 'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'
165		};
166
167		_.hooks.run("before-highlightall", env);
168
169		var elements = env.elements || document.querySelectorAll(env.selector);
170
171		for (var i=0, element; element = elements[i++];) {
172			_.highlightElement(element, async === true, env.callback);
173		}
174	},
175
176	highlightElement: function(element, async, callback) {
177		// Find language
178		var language, grammar, parent = element;
179
180		while (parent && !lang.test(parent.className)) {
181			parent = parent.parentNode;
182		}
183
184		if (parent) {
185			language = (parent.className.match(lang) || [,''])[1].toLowerCase();
186			grammar = _.languages[language];
187		}
188
189		// Set language on the element, if not present
190		element.className = element.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;
191
192		// Set language on the parent, for styling
193		parent = element.parentNode;
194
195		if (/pre/i.test(parent.nodeName)) {
196			parent.className = parent.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;
197		}
198
199		var code = element.textContent;
200
201		var env = {
202			element: element,
203			language: language,
204			grammar: grammar,
205			code: code
206		};
207
208		_.hooks.run('before-sanity-check', env);
209
210		if (!env.code || !env.grammar) {
211			if (env.code) {
212				env.element.textContent = env.code;
213			}
214			_.hooks.run('complete', env);
215			return;
216		}
217
218		_.hooks.run('before-highlight', env);
219
220		if (async && _self.Worker) {
221			var worker = new Worker(_.filename);
222
223			worker.onmessage = function(evt) {
224				env.highlightedCode = evt.data;
225
226				_.hooks.run('before-insert', env);
227
228				env.element.innerHTML = env.highlightedCode;
229
230				callback && callback.call(env.element);
231				_.hooks.run('after-highlight', env);
232				_.hooks.run('complete', env);
233			};
234
235			worker.postMessage(JSON.stringify({
236				language: env.language,
237				code: env.code,
238				immediateClose: true
239			}));
240		}
241		else {
242			env.highlightedCode = _.highlight(env.code, env.grammar, env.language);
243
244			_.hooks.run('before-insert', env);
245
246			env.element.innerHTML = env.highlightedCode;
247
248			callback && callback.call(element);
249
250			_.hooks.run('after-highlight', env);
251			_.hooks.run('complete', env);
252		}
253	},
254
255	highlight: function (text, grammar, language) {
256		var tokens = _.tokenize(text, grammar);
257		return Token.stringify(_.util.encode(tokens), language);
258	},
259
260	tokenize: function(text, grammar, language) {
261		var Token = _.Token;
262
263		var strarr = [text];
264
265		var rest = grammar.rest;
266
267		if (rest) {
268			for (var token in rest) {
269				grammar[token] = rest[token];
270			}
271
272			delete grammar.rest;
273		}
274
275		tokenloop: for (var token in grammar) {
276			if(!grammar.hasOwnProperty(token) || !grammar[token]) {
277				continue;
278			}
279
280			var patterns = grammar[token];
281			patterns = (_.util.type(patterns) === "Array") ? patterns : [patterns];
282
283			for (var j = 0; j < patterns.length; ++j) {
284				var pattern = patterns[j],
285					inside = pattern.inside,
286					lookbehind = !!pattern.lookbehind,
287					greedy = !!pattern.greedy,
288					lookbehindLength = 0,
289					alias = pattern.alias;
290
291				if (greedy && !pattern.pattern.global) {
292					// Without the global flag, lastIndex won't work
293					var flags = pattern.pattern.toString().match(/[imuy]*$/)[0];
294					pattern.pattern = RegExp(pattern.pattern.source, flags + "g");
295				}
296
297				pattern = pattern.pattern || pattern;
298
299				// Don’t cache length as it changes during the loop
300				for (var i=0, pos = 0; i<strarr.length; pos += strarr[i].length, ++i) {
301
302					var str = strarr[i];
303
304					if (strarr.length > text.length) {
305						// Something went terribly wrong, ABORT, ABORT!
306						break tokenloop;
307					}
308
309					if (str instanceof Token) {
310						continue;
311					}
312
313					pattern.lastIndex = 0;
314
315					var match = pattern.exec(str),
316					    delNum = 1;
317
318					// Greedy patterns can override/remove up to two previously matched tokens
319					if (!match && greedy && i != strarr.length - 1) {
320						pattern.lastIndex = pos;
321						match = pattern.exec(text);
322						if (!match) {
323							break;
324						}
325
326						var from = match.index + (lookbehind ? match[1].length : 0),
327						    to = match.index + match[0].length,
328						    k = i,
329						    p = pos;
330
331						for (var len = strarr.length; k < len && p < to; ++k) {
332							p += strarr[k].length;
333							// Move the index i to the element in strarr that is closest to from
334							if (from >= p) {
335								++i;
336								pos = p;
337							}
338						}
339
340						/*
341						 * If strarr[i] is a Token, then the match starts inside another Token, which is invalid
342						 * If strarr[k - 1] is greedy we are in conflict with another greedy pattern
343						 */
344						if (strarr[i] instanceof Token || strarr[k - 1].greedy) {
345							continue;
346						}
347
348						// Number of tokens to delete and replace with the new match
349						delNum = k - i;
350						str = text.slice(pos, p);
351						match.index -= pos;
352					}
353
354					if (!match) {
355						continue;
356					}
357
358					if(lookbehind) {
359						lookbehindLength = match[1].length;
360					}
361
362					var from = match.index + lookbehindLength,
363					    match = match[0].slice(lookbehindLength),
364					    to = from + match.length,
365					    before = str.slice(0, from),
366					    after = str.slice(to);
367
368					var args = [i, delNum];
369
370					if (before) {
371						args.push(before);
372					}
373
374					var wrapped = new Token(token, inside? _.tokenize(match, inside) : match, alias, match, greedy);
375
376					args.push(wrapped);
377
378					if (after) {
379						args.push(after);
380					}
381
382					Array.prototype.splice.apply(strarr, args);
383				}
384			}
385		}
386
387		return strarr;
388	},
389
390	hooks: {
391		all: {},
392
393		add: function (name, callback) {
394			var hooks = _.hooks.all;
395
396			hooks[name] = hooks[name] || [];
397
398			hooks[name].push(callback);
399		},
400
401		run: function (name, env) {
402			var callbacks = _.hooks.all[name];
403
404			if (!callbacks || !callbacks.length) {
405				return;
406			}
407
408			for (var i=0, callback; callback = callbacks[i++];) {
409				callback(env);
410			}
411		}
412	}
413};
414
415var Token = _.Token = function(type, content, alias, matchedStr, greedy) {
416	this.type = type;
417	this.content = content;
418	this.alias = alias;
419	// Copy of the full string this token was created from
420	this.length = (matchedStr || "").length|0;
421	this.greedy = !!greedy;
422};
423
424Token.stringify = function(o, language, parent) {
425	if (typeof o == 'string') {
426		return o;
427	}
428
429	if (_.util.type(o) === 'Array') {
430		return o.map(function(element) {
431			return Token.stringify(element, language, o);
432		}).join('');
433	}
434
435	var env = {
436		type: o.type,
437		content: Token.stringify(o.content, language, parent),
438		tag: 'span',
439		classes: ['token', o.type],
440		attributes: {},
441		language: language,
442		parent: parent
443	};
444
445	if (env.type == 'comment') {
446		env.attributes['spellcheck'] = 'true';
447	}
448
449	if (o.alias) {
450		var aliases = _.util.type(o.alias) === 'Array' ? o.alias : [o.alias];
451		Array.prototype.push.apply(env.classes, aliases);
452	}
453
454	_.hooks.run('wrap', env);
455
456	var attributes = Object.keys(env.attributes).map(function(name) {
457		return name + '="' + (env.attributes[name] || '').replace(/"/g, '&quot;') + '"';
458	}).join(' ');
459
460	return '<' + env.tag + ' class="' + env.classes.join(' ') + '"' + (attributes ? ' ' + attributes : '') + '>' + env.content + '</' + env.tag + '>';
461
462};
463
464if (!_self.document) {
465	if (!_self.addEventListener) {
466		// in Node.js
467		return _self.Prism;
468	}
469 	// In worker
470	_self.addEventListener('message', function(evt) {
471		var message = JSON.parse(evt.data),
472		    lang = message.language,
473		    code = message.code,
474		    immediateClose = message.immediateClose;
475
476		_self.postMessage(_.highlight(code, _.languages[lang], lang));
477		if (immediateClose) {
478			_self.close();
479		}
480	}, false);
481
482	return _self.Prism;
483}
484
485//Get current script and highlight
486var script = document.currentScript || [].slice.call(document.getElementsByTagName("script")).pop();
487
488if (script) {
489	_.filename = script.src;
490
491	if (document.addEventListener && !_.manual && !script.hasAttribute('data-manual')) {
492		if(document.readyState !== "loading") {
493			if (window.requestAnimationFrame) {
494				window.requestAnimationFrame(_.highlightAll);
495			} else {
496				window.setTimeout(_.highlightAll, 16);
497			}
498		}
499		else {
500			document.addEventListener('DOMContentLoaded', _.highlightAll);
501		}
502	}
503}
504
505return _self.Prism;
506
507})();
508
509if (typeof module !== 'undefined' && module.exports) {
510	module.exports = Prism;
511}
512
513// hack for components to work correctly in node.js
514if (typeof global !== 'undefined') {
515	global.Prism = Prism;
516}
517
518
519/* **********************************************
520     Begin prism-markup.js
521********************************************** */
522
523Prism.languages.markup = {
524	'comment': /<!--[\w\W]*?-->/,
525	'prolog': /<\?[\w\W]+?\?>/,
526	'doctype': /<!DOCTYPE[\w\W]+?>/i,
527	'cdata': /<!\[CDATA\[[\w\W]*?]]>/i,
528	'tag': {
529		pattern: /<\/?(?!\d)[^\s>\/=$<]+(?:\s+[^\s>\/=]+(?:=(?:("|')(?:\\\1|\\?(?!\1)[\w\W])*\1|[^\s'">=]+))?)*\s*\/?>/i,
530		inside: {
531			'tag': {
532				pattern: /^<\/?[^\s>\/]+/i,
533				inside: {
534					'punctuation': /^<\/?/,
535					'namespace': /^[^\s>\/:]+:/
536				}
537			},
538			'attr-value': {
539				pattern: /=(?:('|")[\w\W]*?(\1)|[^\s>]+)/i,
540				inside: {
541					'punctuation': /[=>"']/
542				}
543			},
544			'punctuation': /\/?>/,
545			'attr-name': {
546				pattern: /[^\s>\/]+/,
547				inside: {
548					'namespace': /^[^\s>\/:]+:/
549				}
550			}
551
552		}
553	},
554	'entity': /&#?[\da-z]{1,8};/i
555};
556
557// Plugin to make entity title show the real entity, idea by Roman Komarov
558Prism.hooks.add('wrap', function(env) {
559
560	if (env.type === 'entity') {
561		env.attributes['title'] = env.content.replace(/&amp;/, '&');
562	}
563});
564
565Prism.languages.xml = Prism.languages.markup;
566Prism.languages.html = Prism.languages.markup;
567Prism.languages.mathml = Prism.languages.markup;
568Prism.languages.svg = Prism.languages.markup;
569
570
571/* **********************************************
572     Begin prism-css.js
573********************************************** */
574
575Prism.languages.css = {
576	'comment': /\/\*[\w\W]*?\*\//,
577	'atrule': {
578		pattern: /@[\w-]+?.*?(;|(?=\s*\{))/i,
579		inside: {
580			'rule': /@[\w-]+/
581			// See rest below
582		}
583	},
584	'url': /url\((?:(["'])(\\(?:\r\n|[\w\W])|(?!\1)[^\\\r\n])*\1|.*?)\)/i,
585	'selector': /[^\{\}\s][^\{\};]*?(?=\s*\{)/,
586	'string': {
587		pattern: /("|')(\\(?:\r\n|[\w\W])|(?!\1)[^\\\r\n])*\1/,
588		greedy: true
589	},
590	'property': /(\b|\B)[\w-]+(?=\s*:)/i,
591	'important': /\B!important\b/i,
592	'function': /[-a-z0-9]+(?=\()/i,
593	'punctuation': /[(){};:]/
594};
595
596Prism.languages.css['atrule'].inside.rest = Prism.util.clone(Prism.languages.css);
597
598if (Prism.languages.markup) {
599	Prism.languages.insertBefore('markup', 'tag', {
600		'style': {
601			pattern: /(<style[\w\W]*?>)[\w\W]*?(?=<\/style>)/i,
602			lookbehind: true,
603			inside: Prism.languages.css,
604			alias: 'language-css'
605		}
606	});
607	
608	Prism.languages.insertBefore('inside', 'attr-value', {
609		'style-attr': {
610			pattern: /\s*style=("|').*?\1/i,
611			inside: {
612				'attr-name': {
613					pattern: /^\s*style/i,
614					inside: Prism.languages.markup.tag.inside
615				},
616				'punctuation': /^\s*=\s*['"]|['"]\s*$/,
617				'attr-value': {
618					pattern: /.+/i,
619					inside: Prism.languages.css
620				}
621			},
622			alias: 'language-css'
623		}
624	}, Prism.languages.markup.tag);
625}
626
627/* **********************************************
628     Begin prism-clike.js
629********************************************** */
630
631Prism.languages.clike = {
632	'comment': [
633		{
634			pattern: /(^|[^\\])\/\*[\w\W]*?\*\//,
635			lookbehind: true
636		},
637		{
638			pattern: /(^|[^\\:])\/\/.*/,
639			lookbehind: true
640		}
641	],
642	'string': {
643		pattern: /(["'])(\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
644		greedy: true
645	},
646	'class-name': {
647		pattern: /((?:\b(?:class|interface|extends|implements|trait|instanceof|new)\s+)|(?:catch\s+\())[a-z0-9_\.\\]+/i,
648		lookbehind: true,
649		inside: {
650			punctuation: /(\.|\\)/
651		}
652	},
653	'keyword': /\b(if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/,
654	'boolean': /\b(true|false)\b/,
655	'function': /[a-z0-9_]+(?=\()/i,
656	'number': /\b-?(?:0x[\da-f]+|\d*\.?\d+(?:e[+-]?\d+)?)\b/i,
657	'operator': /--?|\+\+?|!=?=?|<=?|>=?|==?=?|&&?|\|\|?|\?|\*|\/|~|\^|%/,
658	'punctuation': /[{}[\];(),.:]/
659};
660
661
662/* **********************************************
663     Begin prism-javascript.js
664********************************************** */
665
666Prism.languages.javascript = Prism.languages.extend('clike', {
667	'keyword': /\b(as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|var|void|while|with|yield)\b/,
668	'number': /\b-?(0x[\dA-Fa-f]+|0b[01]+|0o[0-7]+|\d*\.?\d+([Ee][+-]?\d+)?|NaN|Infinity)\b/,
669	// Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444)
670	'function': /[_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*(?=\()/i,
671	'operator': /--?|\+\+?|!=?=?|<=?|>=?|==?=?|&&?|\|\|?|\?|\*\*?|\/|~|\^|%|\.{3}/
672});
673
674Prism.languages.insertBefore('javascript', 'keyword', {
675	'regex': {
676		pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\\\r\n])+\/[gimyu]{0,5}(?=\s*($|[\r\n,.;})]))/,
677		lookbehind: true,
678		greedy: true
679	}
680});
681
682Prism.languages.insertBefore('javascript', 'string', {
683	'template-string': {
684		pattern: /`(?:\\\\|\\?[^\\])*?`/,
685		greedy: true,
686		inside: {
687			'interpolation': {
688				pattern: /\$\{[^}]+\}/,
689				inside: {
690					'interpolation-punctuation': {
691						pattern: /^\$\{|\}$/,
692						alias: 'punctuation'
693					},
694					rest: Prism.languages.javascript
695				}
696			},
697			'string': /[\s\S]+/
698		}
699	}
700});
701
702if (Prism.languages.markup) {
703	Prism.languages.insertBefore('markup', 'tag', {
704		'script': {
705			pattern: /(<script[\w\W]*?>)[\w\W]*?(?=<\/script>)/i,
706			lookbehind: true,
707			inside: Prism.languages.javascript,
708			alias: 'language-javascript'
709		}
710	});
711}
712
713Prism.languages.js = Prism.languages.javascript;
714
715/* **********************************************
716     Begin prism-file-highlight.js
717********************************************** */
718
719(function () {
720	if (typeof self === 'undefined' || !self.Prism || !self.document || !document.querySelector) {
721		return;
722	}
723
724	self.Prism.fileHighlight = function() {
725
726		var Extensions = {
727			'js': 'javascript',
728			'py': 'python',
729			'rb': 'ruby',
730			'ps1': 'powershell',
731			'psm1': 'powershell',
732			'sh': 'bash',
733			'bat': 'batch',
734			'h': 'c',
735			'tex': 'latex'
736		};
737
738		if(Array.prototype.forEach) { // Check to prevent error in IE8
739			Array.prototype.slice.call(document.querySelectorAll('pre[data-src]')).forEach(function (pre) {
740				var src = pre.getAttribute('data-src');
741
742				var language, parent = pre;
743				var lang = /\blang(?:uage)?-(?!\*)(\w+)\b/i;
744				while (parent && !lang.test(parent.className)) {
745					parent = parent.parentNode;
746				}
747
748				if (parent) {
749					language = (pre.className.match(lang) || [, ''])[1];
750				}
751
752				if (!language) {
753					var extension = (src.match(/\.(\w+)$/) || [, ''])[1];
754					language = Extensions[extension] || extension;
755				}
756
757				var code = document.createElement('code');
758				code.className = 'language-' + language;
759
760				pre.textContent = '';
761
762				code.textContent = 'Loading…';
763
764				pre.appendChild(code);
765
766				var xhr = new XMLHttpRequest();
767
768				xhr.open('GET', src, true);
769
770				xhr.onreadystatechange = function () {
771					if (xhr.readyState == 4) {
772
773						if (xhr.status < 400 && xhr.responseText) {
774							code.textContent = xhr.responseText;
775
776							Prism.highlightElement(code);
777						}
778						else if (xhr.status >= 400) {
779							code.textContent = '✖ Error ' + xhr.status + ' while fetching file: ' + xhr.statusText;
780						}
781						else {
782							code.textContent = '✖ Error: File does not exist or is empty';
783						}
784					}
785				};
786
787				xhr.send(null);
788			});
789		}
790
791	};
792
793	document.addEventListener('DOMContentLoaded', self.Prism.fileHighlight);
794
795})();