mirror of
https://github.com/explosion/spaCy.git
synced 2025-01-15 12:06:25 +03:00
1693 lines
50 KiB
JavaScript
1693 lines
50 KiB
JavaScript
|
/* http://prismjs.com/download.html?themes=prism-okaidia&languages=markup+css+clike+javascript+bash+c+cpp+css-extras+git+haml+jade+latex+makefile+markdown+php+php-extras+powershell+python+ruby+sass+scss+sql+wiki */
|
|||
|
var _self = (typeof window !== 'undefined')
|
|||
|
? window // if in browser
|
|||
|
: (
|
|||
|
(typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope)
|
|||
|
? self // if in worker
|
|||
|
: {} // if in node js
|
|||
|
);
|
|||
|
|
|||
|
/**
|
|||
|
* Prism: Lightweight, robust, elegant syntax highlighting
|
|||
|
* MIT license http://www.opensource.org/licenses/mit-license.php/
|
|||
|
* @author Lea Verou http://lea.verou.me
|
|||
|
*/
|
|||
|
|
|||
|
var Prism = (function(){
|
|||
|
|
|||
|
// Private helper vars
|
|||
|
var lang = /\blang(?:uage)?-(?!\*)(\w+)\b/i;
|
|||
|
|
|||
|
var _ = _self.Prism = {
|
|||
|
util: {
|
|||
|
encode: function (tokens) {
|
|||
|
if (tokens instanceof Token) {
|
|||
|
return new Token(tokens.type, _.util.encode(tokens.content), tokens.alias);
|
|||
|
} else if (_.util.type(tokens) === 'Array') {
|
|||
|
return tokens.map(_.util.encode);
|
|||
|
} else {
|
|||
|
return tokens.replace(/&/g, '&').replace(/</g, '<').replace(/\u00a0/g, ' ');
|
|||
|
}
|
|||
|
},
|
|||
|
|
|||
|
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':
|
|||
|
// Check for existence for IE8
|
|||
|
return o.map && o.map(function(v) { return _.util.clone(v); });
|
|||
|
}
|
|||
|
|
|||
|
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
|
|||
|
* As this needs to recreate the object (we cannot actually insert before keys in object literals),
|
|||
|
* we cannot just provide an object, we need anobject and a key.
|
|||
|
* @param inside The key (or language id) of the parent
|
|||
|
* @param before The key to insert before. If not provided, the function appends instead.
|
|||
|
* @param insert Object with the key/value pairs to insert
|
|||
|
* @param root The object that contains `inside`. If equal to Prism.languages, it can be omitted.
|
|||
|
*/
|
|||
|
insertBefore: function (inside, before, insert, root) {
|
|||
|
root = root || _.languages;
|
|||
|
var grammar = root[inside];
|
|||
|
|
|||
|
if (arguments.length == 2) {
|
|||
|
insert = arguments[1];
|
|||
|
|
|||
|
for (var newToken in insert) {
|
|||
|
if (insert.hasOwnProperty(newToken)) {
|
|||
|
grammar[newToken] = insert[newToken];
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return grammar;
|
|||
|
}
|
|||
|
|
|||
|
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];
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// Update references in other language definitions
|
|||
|
_.languages.DFS(_.languages, function(key, value) {
|
|||
|
if (value === root[inside] && key != inside) {
|
|||
|
this[key] = ret;
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
return root[inside] = ret;
|
|||
|
},
|
|||
|
|
|||
|
// Traverse a language definition with Depth First Search
|
|||
|
DFS: function(o, callback, type) {
|
|||
|
for (var i in o) {
|
|||
|
if (o.hasOwnProperty(i)) {
|
|||
|
callback.call(o, i, o[i], type || i);
|
|||
|
|
|||
|
if (_.util.type(o[i]) === 'Object') {
|
|||
|
_.languages.DFS(o[i], callback);
|
|||
|
}
|
|||
|
else if (_.util.type(o[i]) === 'Array') {
|
|||
|
_.languages.DFS(o[i], callback, i);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
},
|
|||
|
|
|||
|
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];
|
|||
|
}
|
|||
|
|
|||
|
// 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;
|
|||
|
|
|||
|
var env = {
|
|||
|
element: element,
|
|||
|
language: language,
|
|||
|
grammar: grammar,
|
|||
|
code: code
|
|||
|
};
|
|||
|
|
|||
|
if(code) {
|
|||
|
env.code = code.replace(/^(?:\r?\n|\r)/, '');
|
|||
|
}
|
|||
|
|
|||
|
if (!code || !grammar) {
|
|||
|
_.hooks.run('complete', env);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
_.hooks.run('before-highlight', env);
|
|||
|
|
|||
|
if (async && _self.Worker) {
|
|||
|
var worker = new Worker(_.filename);
|
|||
|
|
|||
|
worker.onmessage = function(evt) {
|
|||
|
env.highlightedCode = Token.stringify(JSON.parse(evt.data), language);
|
|||
|
|
|||
|
_.hooks.run('before-insert', env);
|
|||
|
|
|||
|
env.element.innerHTML = env.highlightedCode;
|
|||
|
|
|||
|
callback && callback.call(env.element);
|
|||
|
_.hooks.run('after-highlight', env);
|
|||
|
_.hooks.run('complete', env);
|
|||
|
};
|
|||
|
|
|||
|
worker.postMessage(JSON.stringify({
|
|||
|
language: env.language,
|
|||
|
code: env.code
|
|||
|
}));
|
|||
|
}
|
|||
|
else {
|
|||
|
env.highlightedCode = _.highlight(env.code, env.grammar, env.language);
|
|||
|
|
|||
|
_.hooks.run('before-insert', env);
|
|||
|
|
|||
|
env.element.innerHTML = env.highlightedCode;
|
|||
|
|
|||
|
callback && callback.call(element);
|
|||
|
|
|||
|
_.hooks.run('after-highlight', env);
|
|||
|
_.hooks.run('complete', env);
|
|||
|
}
|
|||
|
},
|
|||
|
|
|||
|
highlight: function (text, grammar, language) {
|
|||
|
var tokens = _.tokenize(text, grammar);
|
|||
|
return Token.stringify(_.util.encode(tokens), language);
|
|||
|
},
|
|||
|
|
|||
|
tokenize: function(text, grammar, language) {
|
|||
|
var Token = _.Token;
|
|||
|
|
|||
|
var strarr = [text];
|
|||
|
|
|||
|
var rest = grammar.rest;
|
|||
|
|
|||
|
if (rest) {
|
|||
|
for (var token in rest) {
|
|||
|
grammar[token] = rest[token];
|
|||
|
}
|
|||
|
|
|||
|
delete grammar.rest;
|
|||
|
}
|
|||
|
|
|||
|
tokenloop: for (var token in grammar) {
|
|||
|
if(!grammar.hasOwnProperty(token) || !grammar[token]) {
|
|||
|
continue;
|
|||
|
}
|
|||
|
|
|||
|
var patterns = grammar[token];
|
|||
|
patterns = (_.util.type(patterns) === "Array") ? patterns : [patterns];
|
|||
|
|
|||
|
for (var j = 0; j < patterns.length; ++j) {
|
|||
|
var pattern = patterns[j],
|
|||
|
inside = pattern.inside,
|
|||
|
lookbehind = !!pattern.lookbehind,
|
|||
|
lookbehindLength = 0,
|
|||
|
alias = pattern.alias;
|
|||
|
|
|||
|
pattern = pattern.pattern || pattern;
|
|||
|
|
|||
|
for (var i=0; i<strarr.length; i++) { // Don’t cache length as it changes during the loop
|
|||
|
|
|||
|
var str = strarr[i];
|
|||
|
|
|||
|
if (strarr.length > 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, alias);
|
|||
|
|
|||
|
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, alias) {
|
|||
|
this.type = type;
|
|||
|
this.content = content;
|
|||
|
this.alias = alias;
|
|||
|
};
|
|||
|
|
|||
|
Token.stringify = function(o, language, parent) {
|
|||
|
if (typeof o == 'string') {
|
|||
|
return o;
|
|||
|
}
|
|||
|
|
|||
|
if (_.util.type(o) === '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';
|
|||
|
}
|
|||
|
|
|||
|
if (o.alias) {
|
|||
|
var aliases = _.util.type(o.alias) === 'Array' ? o.alias : [o.alias];
|
|||
|
Array.prototype.push.apply(env.classes, aliases);
|
|||
|
}
|
|||
|
|
|||
|
_.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 + '</' + env.tag + '>';
|
|||
|
|
|||
|
};
|
|||
|
|
|||
|
if (!_self.document) {
|
|||
|
if (!_self.addEventListener) {
|
|||
|
// in Node.js
|
|||
|
return _self.Prism;
|
|||
|
}
|
|||
|
// In worker
|
|||
|
_self.addEventListener('message', function(evt) {
|
|||
|
var message = JSON.parse(evt.data),
|
|||
|
lang = message.language,
|
|||
|
code = message.code;
|
|||
|
|
|||
|
_self.postMessage(JSON.stringify(_.util.encode(_.tokenize(code, _.languages[lang]))));
|
|||
|
_self.close();
|
|||
|
}, false);
|
|||
|
|
|||
|
return _self.Prism;
|
|||
|
}
|
|||
|
|
|||
|
// 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);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return _self.Prism;
|
|||
|
|
|||
|
})();
|
|||
|
|
|||
|
if (typeof module !== 'undefined' && module.exports) {
|
|||
|
module.exports = Prism;
|
|||
|
}
|
|||
|
;
|
|||
|
Prism.languages.markup = {
|
|||
|
'comment': /<!--[\w\W]*?-->/,
|
|||
|
'prolog': /<\?[\w\W]+?\?>/,
|
|||
|
'doctype': /<!DOCTYPE[\w\W]+?>/,
|
|||
|
'cdata': /<!\[CDATA\[[\w\W]*?]]>/i,
|
|||
|
'tag': {
|
|||
|
pattern: /<\/?[^\s>\/]+(?:\s+[^\s>\/=]+(?:=(?:("|')(?:\\\1|\\?(?!\1)[\w\W])*\1|[^\s'">=]+))?)*\s*\/?>/i,
|
|||
|
inside: {
|
|||
|
'tag': {
|
|||
|
pattern: /^<\/?[^\s>\/]+/i,
|
|||
|
inside: {
|
|||
|
'punctuation': /^<\/?/,
|
|||
|
'namespace': /^[^\s>\/:]+:/
|
|||
|
}
|
|||
|
},
|
|||
|
'attr-value': {
|
|||
|
pattern: /=(?:('|")[\w\W]*?(\1)|[^\s>]+)/i,
|
|||
|
inside: {
|
|||
|
'punctuation': /[=>"']/
|
|||
|
}
|
|||
|
},
|
|||
|
'punctuation': /\/?>/,
|
|||
|
'attr-name': {
|
|||
|
pattern: /[^\s>\/]+/,
|
|||
|
inside: {
|
|||
|
'namespace': /^[^\s>\/:]+:/
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
},
|
|||
|
'entity': /&#?[\da-z]{1,8};/i
|
|||
|
};
|
|||
|
|
|||
|
// 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(/&/, '&');
|
|||
|
}
|
|||
|
});
|
|||
|
;
|
|||
|
Prism.languages.css = {
|
|||
|
'comment': /\/\*[\w\W]*?\*\//,
|
|||
|
'atrule': {
|
|||
|
pattern: /@[\w-]+?.*?(;|(?=\s*\{))/i,
|
|||
|
inside: {
|
|||
|
'rule': /@[\w-]+/
|
|||
|
// See rest below
|
|||
|
}
|
|||
|
},
|
|||
|
'url': /url\((?:(["'])(\\(?:\r\n|[\w\W])|(?!\1)[^\\\r\n])*\1|.*?)\)/i,
|
|||
|
'selector': /[^\{\}\s][^\{\};]*?(?=\s*\{)/,
|
|||
|
'string': /("|')(\\(?:\r\n|[\w\W])|(?!\1)[^\\\r\n])*\1/,
|
|||
|
'property': /(\b|\B)[\w-]+(?=\s*:)/i,
|
|||
|
'important': /\B!important\b/i,
|
|||
|
'function': /[-a-z0-9]+(?=\()/i,
|
|||
|
'punctuation': /[(){};:]/
|
|||
|
};
|
|||
|
|
|||
|
Prism.languages.css['atrule'].inside.rest = Prism.util.clone(Prism.languages.css);
|
|||
|
|
|||
|
if (Prism.languages.markup) {
|
|||
|
Prism.languages.insertBefore('markup', 'tag', {
|
|||
|
'style': {
|
|||
|
pattern: /<style[\w\W]*?>[\w\W]*?<\/style>/i,
|
|||
|
inside: {
|
|||
|
'tag': {
|
|||
|
pattern: /<style[\w\W]*?>|<\/style>/i,
|
|||
|
inside: Prism.languages.markup.tag.inside
|
|||
|
},
|
|||
|
rest: Prism.languages.css
|
|||
|
},
|
|||
|
alias: 'language-css'
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
Prism.languages.insertBefore('inside', 'attr-value', {
|
|||
|
'style-attr': {
|
|||
|
pattern: /\s*style=("|').*?\1/i,
|
|||
|
inside: {
|
|||
|
'attr-name': {
|
|||
|
pattern: /^\s*style/i,
|
|||
|
inside: Prism.languages.markup.tag.inside
|
|||
|
},
|
|||
|
'punctuation': /^\s*=\s*['"]|['"]\s*$/,
|
|||
|
'attr-value': {
|
|||
|
pattern: /.+/i,
|
|||
|
inside: Prism.languages.css
|
|||
|
}
|
|||
|
},
|
|||
|
alias: 'language-css'
|
|||
|
}
|
|||
|
}, Prism.languages.markup.tag);
|
|||
|
};
|
|||
|
Prism.languages.clike = {
|
|||
|
'comment': [
|
|||
|
{
|
|||
|
pattern: /(^|[^\\])\/\*[\w\W]*?\*\//,
|
|||
|
lookbehind: true
|
|||
|
},
|
|||
|
{
|
|||
|
pattern: /(^|[^\\:])\/\/.*/,
|
|||
|
lookbehind: true
|
|||
|
}
|
|||
|
],
|
|||
|
'string': /("|')(\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
|
|||
|
'class-name': {
|
|||
|
pattern: /((?:(?:class|interface|extends|implements|trait|instanceof|new)\s+)|(?:catch\s+\())[a-z0-9_\.\\]+/i,
|
|||
|
lookbehind: true,
|
|||
|
inside: {
|
|||
|
punctuation: /(\.|\\)/
|
|||
|
}
|
|||
|
},
|
|||
|
'keyword': /\b(if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/,
|
|||
|
'boolean': /\b(true|false)\b/,
|
|||
|
'function': /[a-z0-9_]+(?=\()/i,
|
|||
|
'number': /\b-?(0x[\dA-Fa-f]+|\d*\.?\d+([Ee]-?\d+)?)\b/,
|
|||
|
'operator': /[-+]{1,2}|!|<=?|>=?|={1,3}|&{1,2}|\|?\||\?|\*|\/|~|\^|%/,
|
|||
|
'punctuation': /[{}[\];(),.:]/
|
|||
|
};
|
|||
|
;
|
|||
|
Prism.languages.javascript = Prism.languages.extend('clike', {
|
|||
|
'keyword': /\b(as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|false|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|true|try|typeof|var|void|while|with|yield)\b/,
|
|||
|
'number': /\b-?(0x[\dA-Fa-f]+|0b[01]+|0o[0-7]+|\d*\.?\d+([Ee][+-]?\d+)?|NaN|Infinity)\b/,
|
|||
|
'function': /(?!\d)[a-z0-9_$]+(?=\()/i
|
|||
|
});
|
|||
|
|
|||
|
Prism.languages.insertBefore('javascript', 'keyword', {
|
|||
|
'regex': {
|
|||
|
pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\\\r\n])+\/[gimyu]{0,5}(?=\s*($|[\r\n,.;})]))/,
|
|||
|
lookbehind: true
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
Prism.languages.insertBefore('javascript', 'class-name', {
|
|||
|
'template-string': {
|
|||
|
pattern: /`(?:\\`|\\?[^`])*`/,
|
|||
|
inside: {
|
|||
|
'interpolation': {
|
|||
|
pattern: /\$\{[^}]+\}/,
|
|||
|
inside: {
|
|||
|
'interpolation-punctuation': {
|
|||
|
pattern: /^\$\{|\}$/,
|
|||
|
alias: 'punctuation'
|
|||
|
},
|
|||
|
rest: Prism.languages.javascript
|
|||
|
}
|
|||
|
},
|
|||
|
'string': /[\s\S]+/
|
|||
|
}
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
if (Prism.languages.markup) {
|
|||
|
Prism.languages.insertBefore('markup', 'tag', {
|
|||
|
'script': {
|
|||
|
pattern: /<script[\w\W]*?>[\w\W]*?<\/script>/i,
|
|||
|
inside: {
|
|||
|
'tag': {
|
|||
|
pattern: /<script[\w\W]*?>|<\/script>/i,
|
|||
|
inside: Prism.languages.markup.tag.inside
|
|||
|
},
|
|||
|
rest: Prism.languages.javascript
|
|||
|
},
|
|||
|
alias: 'language-javascript'
|
|||
|
}
|
|||
|
});
|
|||
|
}
|
|||
|
;
|
|||
|
Prism.languages.bash = Prism.languages.extend('clike', {
|
|||
|
'comment': {
|
|||
|
pattern: /(^|[^"{\\])#.*/,
|
|||
|
lookbehind: true
|
|||
|
},
|
|||
|
'string': {
|
|||
|
//allow multiline string
|
|||
|
pattern: /("|')(\\?[\s\S])*?\1/,
|
|||
|
inside: {
|
|||
|
//'property' class reused for bash variables
|
|||
|
'property': /\$([a-zA-Z0-9_#\?\-\*!@]+|\{[^\}]+\})/
|
|||
|
}
|
|||
|
},
|
|||
|
// Redefined to prevent highlighting of numbers in filenames
|
|||
|
'number': {
|
|||
|
pattern: /([^\w\.])-?(0x[\dA-Fa-f]+|\d*\.?\d+([Ee]-?\d+)?)\b/,
|
|||
|
lookbehind: true
|
|||
|
},
|
|||
|
// Originally based on http://ss64.com/bash/
|
|||
|
'function': /\b(?:alias|apropos|apt-get|aptitude|aspell|awk|basename|bash|bc|bg|builtin|bzip2|cal|cat|cd|cfdisk|chgrp|chmod|chown|chroot|chkconfig|cksum|clear|cmp|comm|command|cp|cron|crontab|csplit|cut|date|dc|dd|ddrescue|df|diff|diff3|dig|dir|dircolors|dirname|dirs|dmesg|du|egrep|eject|enable|env|ethtool|eval|exec|expand|expect|export|expr|fdformat|fdisk|fg|fgrep|file|find|fmt|fold|format|free|fsck|ftp|fuser|gawk|getopts|git|grep|groupadd|groupdel|groupmod|groups|gzip|hash|head|help|hg|history|hostname|htop|iconv|id|ifconfig|ifdown|ifup|import|install|jobs|join|kill|killall|less|link|ln|locate|logname|logout|look|lpc|lpr|lprint|lprintd|lprintq|lprm|ls|lsof|make|man|mkdir|mkfifo|mkisofs|mknod|more|most|mount|mtools|mtr|mv|mmv|nano|netstat|nice|nl|nohup|notify-send|nslookup|open|op|passwd|paste|pathchk|ping|pkill|popd|pr|printcap|printenv|printf|ps|pushd|pv|pwd|quota|quotacheck|quotactl|ram|rar|rcp|read|readarray|readonly|reboot|rename|renice|remsync|rev|rm|rmdir|rsync|screen|scp|sdiff|sed|seq|service|sftp|shift|shopt|shutdown|sleep|slocate|sort|source|split|ssh|stat|strace|su|sudo|sum|suspend|sync|tail|tar|tee|test|time|timeout|times|touch|top|traceroute|trap|tr|tsort|tty|type|ulimit|umask|umount|unalias|uname|unexpand|uniq|units|unrar|unshar|uptime|useradd|userdel|usermod|users|uuencode|uudecode|v|vdir|vi|vmstat|wait|watch|wc|wget|whereis|which|who|whoami|write|xargs|xdg-open|yes|zip)\b/,
|
|||
|
'keyword': /\b(if|then|else|elif|fi|for|break|continue|while|in|case|function|select|do|done|until|echo|exit|return|set|declare)\b/
|
|||
|
});
|
|||
|
|
|||
|
Prism.languages.insertBefore('bash', 'keyword', {
|
|||
|
//'property' class reused for bash variables
|
|||
|
'property': /\$([a-zA-Z0-9_#\?\-\*!@]+|\{[^}]+\})/
|
|||
|
});
|
|||
|
Prism.languages.insertBefore('bash', 'comment', {
|
|||
|
//shebang must be before comment, 'important' class from css reused
|
|||
|
'important': /^#!\s*\/bin\/bash|^#!\s*\/bin\/sh/
|
|||
|
});
|
|||
|
;
|
|||
|
Prism.languages.c = Prism.languages.extend('clike', {
|
|||
|
'keyword': /\b(asm|typeof|inline|auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|int|long|register|return|short|signed|sizeof|static|struct|switch|typedef|union|unsigned|void|volatile|while)\b/,
|
|||
|
'operator': /\-[>-]?|\+\+?|!=?|<<?=?|>>?=?|==?|&&?|\|?\||[~^%?*\/]/
|
|||
|
});
|
|||
|
|
|||
|
Prism.languages.insertBefore('c', 'string', {
|
|||
|
'macro': {
|
|||
|
// allow for multiline macro definitions
|
|||
|
// spaces after the # character compile fine with gcc
|
|||
|
pattern: /(^\s*)#\s*[a-z]+([^\r\n\\]|\\.|\\(?:\r\n?|\n))*/im,
|
|||
|
lookbehind: true,
|
|||
|
alias: 'property',
|
|||
|
inside: {
|
|||
|
// highlight the path of the include statement as a string
|
|||
|
'string': {
|
|||
|
pattern: /(#\s*include\s*)(<.+?>|("|')(\\?.)+?\3)/,
|
|||
|
lookbehind: true
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
delete Prism.languages.c['class-name'];
|
|||
|
delete Prism.languages.c['boolean'];;
|
|||
|
Prism.languages.cpp = Prism.languages.extend('c', {
|
|||
|
'keyword': /\b(alignas|alignof|asm|auto|bool|break|case|catch|char|char16_t|char32_t|class|compl|const|constexpr|const_cast|continue|decltype|default|delete|do|double|dynamic_cast|else|enum|explicit|export|extern|float|for|friend|goto|if|inline|int|long|mutable|namespace|new|noexcept|nullptr|operator|private|protected|public|register|reinterpret_cast|return|short|signed|sizeof|static|static_assert|static_cast|struct|switch|template|this|thread_local|throw|try|typedef|typeid|typename|union|unsigned|using|virtual|void|volatile|wchar_t|while)\b/,
|
|||
|
'boolean': /\b(true|false)\b/,
|
|||
|
'operator': /[-+]{1,2}|!=?|<{1,2}=?|>{1,2}=?|\->|:{1,2}|={1,2}|\^|~|%|&{1,2}|\|?\||\?|\*|\/|\b(and|and_eq|bitand|bitor|not|not_eq|or|or_eq|xor|xor_eq)\b/
|
|||
|
});
|
|||
|
|
|||
|
Prism.languages.insertBefore('cpp', 'keyword', {
|
|||
|
'class-name': {
|
|||
|
pattern: /(class\s+)[a-z0-9_]+/i,
|
|||
|
lookbehind: true
|
|||
|
}
|
|||
|
});;
|
|||
|
Prism.languages.css.selector = {
|
|||
|
pattern: /[^\{\}\s][^\{\}]*(?=\s*\{)/,
|
|||
|
inside: {
|
|||
|
'pseudo-element': /:(?:after|before|first-letter|first-line|selection)|::[-\w]+/,
|
|||
|
'pseudo-class': /:[-\w]+(?:\(.*\))?/,
|
|||
|
'class': /\.[-:\.\w]+/,
|
|||
|
'id': /#[-:\.\w]+/
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
Prism.languages.insertBefore('css', 'function', {
|
|||
|
'hexcode': /#[\da-f]{3,6}/i,
|
|||
|
'entity': /\\[\da-f]{1,8}/i,
|
|||
|
'number': /[\d%\.]+/
|
|||
|
});;
|
|||
|
Prism.languages.git = {
|
|||
|
/*
|
|||
|
* A simple one line comment like in a git status command
|
|||
|
* For instance:
|
|||
|
* $ git status
|
|||
|
* # On branch infinite-scroll
|
|||
|
* # Your branch and 'origin/sharedBranches/frontendTeam/infinite-scroll' have diverged,
|
|||
|
* # and have 1 and 2 different commits each, respectively.
|
|||
|
* nothing to commit (working directory clean)
|
|||
|
*/
|
|||
|
'comment': /^#.*$/m,
|
|||
|
|
|||
|
/*
|
|||
|
* a string (double and simple quote)
|
|||
|
*/
|
|||
|
'string': /("|')(\\?.)*?\1/m,
|
|||
|
|
|||
|
/*
|
|||
|
* a git command. It starts with a random prompt finishing by a $, then "git" then some other parameters
|
|||
|
* For instance:
|
|||
|
* $ git add file.txt
|
|||
|
*/
|
|||
|
'command': {
|
|||
|
pattern: /^.*\$ git .*$/m,
|
|||
|
inside: {
|
|||
|
/*
|
|||
|
* A git command can contain a parameter starting by a single or a double dash followed by a string
|
|||
|
* For instance:
|
|||
|
* $ git diff --cached
|
|||
|
* $ git log -p
|
|||
|
*/
|
|||
|
'parameter': /\s(--|-)\w+/m
|
|||
|
}
|
|||
|
},
|
|||
|
|
|||
|
/*
|
|||
|
* Coordinates displayed in a git diff command
|
|||
|
* For instance:
|
|||
|
* $ git diff
|
|||
|
* diff --git file.txt file.txt
|
|||
|
* index 6214953..1d54a52 100644
|
|||
|
* --- file.txt
|
|||
|
* +++ file.txt
|
|||
|
* @@ -1 +1,2 @@
|
|||
|
* -Here's my tetx file
|
|||
|
* +Here's my text file
|
|||
|
* +And this is the second line
|
|||
|
*/
|
|||
|
'coord': /^@@.*@@$/m,
|
|||
|
|
|||
|
/*
|
|||
|
* Regexp to match the changed lines in a git diff output. Check the example above.
|
|||
|
*/
|
|||
|
'deleted': /^-(?!-).+$/m,
|
|||
|
'inserted': /^\+(?!\+).+$/m,
|
|||
|
|
|||
|
/*
|
|||
|
* Match a "commit [SHA1]" line in a git log output.
|
|||
|
* For instance:
|
|||
|
* $ git log
|
|||
|
* commit a11a14ef7e26f2ca62d4b35eac455ce636d0dc09
|
|||
|
* Author: lgiraudel
|
|||
|
* Date: Mon Feb 17 11:18:34 2014 +0100
|
|||
|
*
|
|||
|
* Add of a new line
|
|||
|
*/
|
|||
|
'commit_sha1': /^commit \w{40}$/m
|
|||
|
};
|
|||
|
;
|
|||
|
/* TODO
|
|||
|
Handle multiline code after tag
|
|||
|
%foo= some |
|
|||
|
multiline |
|
|||
|
code |
|
|||
|
*/
|
|||
|
|
|||
|
(function(Prism) {
|
|||
|
|
|||
|
Prism.languages.haml = {
|
|||
|
// Multiline stuff should appear before the rest
|
|||
|
|
|||
|
'multiline-comment': [
|
|||
|
{
|
|||
|
pattern: /((?:^|\n)([\t ]*))\/.*(\n\2[\t ]+.+)*/,
|
|||
|
lookbehind: true,
|
|||
|
alias: 'comment'
|
|||
|
},
|
|||
|
{
|
|||
|
pattern: /((?:^|\n)([\t ]*))-#.*(\n\2[\t ]+.+)*/,
|
|||
|
lookbehind: true,
|
|||
|
alias: 'comment'
|
|||
|
}
|
|||
|
],
|
|||
|
|
|||
|
'multiline-code': [
|
|||
|
{
|
|||
|
pattern: /((?:^|\n)([\t ]*)(?:[~-]|[&!]?=)).*,[\t ]*(\n\2[\t ]+.*,[\t ]*)*(\n\2[\t ]+.+)/,
|
|||
|
lookbehind: true,
|
|||
|
inside: {
|
|||
|
rest: Prism.languages.ruby
|
|||
|
}
|
|||
|
},
|
|||
|
{
|
|||
|
pattern: /((?:^|\n)([\t ]*)(?:[~-]|[&!]?=)).*\|[\t ]*(\n\2[\t ]+.*\|[\t ]*)*/,
|
|||
|
lookbehind: true,
|
|||
|
inside: {
|
|||
|
rest: Prism.languages.ruby
|
|||
|
}
|
|||
|
}
|
|||
|
],
|
|||
|
|
|||
|
// See at the end of the file for known filters
|
|||
|
'filter': {
|
|||
|
pattern: /((?:^|\n)([\t ]*)):[\w-]+(\n(?:\2[\t ]+.+|\s*?(?=\n)))+/,
|
|||
|
lookbehind: true,
|
|||
|
inside: {
|
|||
|
'filter-name': {
|
|||
|
pattern: /^:[\w-]+/,
|
|||
|
alias: 'variable'
|
|||
|
}
|
|||
|
}
|
|||
|
},
|
|||
|
|
|||
|
'markup': {
|
|||
|
pattern: /((?:^|\n)[\t ]*)<.+/,
|
|||
|
lookbehind: true,
|
|||
|
inside: {
|
|||
|
rest: Prism.languages.markup
|
|||
|
}
|
|||
|
},
|
|||
|
'doctype': {
|
|||
|
pattern: /((?:^|\n)[\t ]*)!!!(?: .+)?/,
|
|||
|
lookbehind: true
|
|||
|
},
|
|||
|
'tag': {
|
|||
|
// Allows for one nested group of braces
|
|||
|
pattern: /((?:^|\n)[\t ]*)[%.#][\w\-#.]*[\w\-](?:\([^)]+\)|\{(?:\{[^}]+\}|[^}])+\}|\[[^\]]+\])*[\/<>]*/,
|
|||
|
lookbehind: true,
|
|||
|
inside: {
|
|||
|
'attributes': [
|
|||
|
{
|
|||
|
// Lookbehind tries to prevent interpolations for breaking it all
|
|||
|
// Allows for one nested group of braces
|
|||
|
pattern: /(^|[^#])\{(?:\{[^}]+\}|[^}])+\}/,
|
|||
|
lookbehind: true,
|
|||
|
inside: {
|
|||
|
rest: Prism.languages.ruby
|
|||
|
}
|
|||
|
},
|
|||
|
{
|
|||
|
pattern: /\([^)]+\)/,
|
|||
|
inside: {
|
|||
|
'attr-value': {
|
|||
|
pattern: /(=\s*)(?:"(?:\\?.)*?"|[^)\s]+)/,
|
|||
|
lookbehind: true
|
|||
|
},
|
|||
|
'attr-name': /[\w:-]+(?=\s*!?=|\s*[,)])/,
|
|||
|
'punctuation': /[=(),]/
|
|||
|
}
|
|||
|
},
|
|||
|
{
|
|||
|
pattern: /\[[^\]]+\]/,
|
|||
|
inside: {
|
|||
|
rest: Prism.languages.ruby
|
|||
|
}
|
|||
|
}
|
|||
|
],
|
|||
|
'punctuation': /[<>]/
|
|||
|
}
|
|||
|
},
|
|||
|
'code': {
|
|||
|
pattern: /((?:^|\n)[\t ]*(?:[~-]|[&!]?=)).+/,
|
|||
|
lookbehind: true,
|
|||
|
inside: {
|
|||
|
rest: Prism.languages.ruby
|
|||
|
}
|
|||
|
},
|
|||
|
// Interpolations in plain text
|
|||
|
'interpolation': {
|
|||
|
pattern: /#\{[^}]+\}/,
|
|||
|
inside: {
|
|||
|
'delimiter': {
|
|||
|
pattern: /^#\{|\}$/,
|
|||
|
alias: 'punctuation'
|
|||
|
},
|
|||
|
rest: Prism.languages.ruby
|
|||
|
}
|
|||
|
},
|
|||
|
'punctuation': {
|
|||
|
pattern: /((?:^|\n)[\t ]*)[~=\-&!]/,
|
|||
|
lookbehind: true
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
var filter_pattern = '((?:^|\\n)([\\t ]*)):{{filter_name}}(\\n(?:\\2[\\t ]+.+|\\s*?(?=\\n)))+';
|
|||
|
|
|||
|
// Non exhaustive list of available filters and associated languages
|
|||
|
var filters = [
|
|||
|
'css',
|
|||
|
{filter:'coffee',language:'coffeescript'},
|
|||
|
'erb',
|
|||
|
'javascript',
|
|||
|
'less',
|
|||
|
'markdown',
|
|||
|
'ruby',
|
|||
|
'scss',
|
|||
|
'textile'
|
|||
|
];
|
|||
|
var all_filters = {};
|
|||
|
for (var i = 0, l = filters.length; i < l; i++) {
|
|||
|
var filter = filters[i];
|
|||
|
filter = typeof filter === 'string' ? {filter: filter, language: filter} : filter;
|
|||
|
if (Prism.languages[filter.language]) {
|
|||
|
all_filters['filter-' + filter.filter] = {
|
|||
|
pattern: RegExp(filter_pattern.replace('{{filter_name}}', filter.filter)),
|
|||
|
lookbehind: true,
|
|||
|
inside: {
|
|||
|
'filter-name': {
|
|||
|
pattern: /^:[\w-]+/,
|
|||
|
alias: 'variable'
|
|||
|
},
|
|||
|
rest: Prism.languages[filter.language]
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
Prism.languages.insertBefore('haml', 'filter', all_filters);
|
|||
|
|
|||
|
}(Prism));;
|
|||
|
(function(Prism) {
|
|||
|
Prism.languages.jade = {
|
|||
|
|
|||
|
// Multiline stuff should appear before the rest
|
|||
|
|
|||
|
'multiline-comment': {
|
|||
|
pattern: /((?:^|\n)([\t ]*))\/\/.*(\n\2[\t ]+.+)*/,
|
|||
|
lookbehind: true,
|
|||
|
alias: 'comment'
|
|||
|
},
|
|||
|
|
|||
|
// All the tag-related part is in lookbehind
|
|||
|
// so that it can be highlighted by the "tag" pattern
|
|||
|
'multiline-script': {
|
|||
|
pattern: /((?:^|\n)([\t ]*)script\b.*\.[\t ]*)(\n(?:\2[\t ]+.+|\s*?(?=\n)))+/,
|
|||
|
lookbehind: true,
|
|||
|
inside: {
|
|||
|
rest: Prism.languages.javascript
|
|||
|
}
|
|||
|
},
|
|||
|
|
|||
|
// See at the end of the file for known filters
|
|||
|
'filter': {
|
|||
|
pattern: /((?:^|\n)([\t ]*)):.+(\n(?:\2[\t ]+.+|\s*?(?=\n)))+/,
|
|||
|
lookbehind: true,
|
|||
|
inside: {
|
|||
|
'filter-name': {
|
|||
|
pattern: /^:[\w-]+/,
|
|||
|
alias: 'variable'
|
|||
|
}
|
|||
|
}
|
|||
|
},
|
|||
|
|
|||
|
'multiline-plain-text': {
|
|||
|
pattern: /((?:^|\n)([\t ]*)[\w\-#.]+\.[\t ]*)(\n(?:\2[\t ]+.+|\s*?(?=\n)))+/,
|
|||
|
lookbehind: true
|
|||
|
},
|
|||
|
'markup': {
|
|||
|
pattern: /((?:^|\n)[\t ]*)<.+/,
|
|||
|
lookbehind: true,
|
|||
|
inside: {
|
|||
|
rest: Prism.languages.markup
|
|||
|
}
|
|||
|
},
|
|||
|
'comment': {
|
|||
|
pattern: /((?:^|\n)[\t ]*)\/\/.+/,
|
|||
|
lookbehind: true
|
|||
|
},
|
|||
|
'doctype': {
|
|||
|
pattern: /((?:^|\n)[\t ]*)doctype(?: .+)?/,
|
|||
|
lookbehind: true
|
|||
|
},
|
|||
|
|
|||
|
// This handle all conditional and loop keywords
|
|||
|
'flow-control': {
|
|||
|
pattern: /((?:^|\n)[\t ]*)(?:if|unless|else|case|when|default|each|while)(?: .+)?/,
|
|||
|
lookbehind: true,
|
|||
|
inside: {
|
|||
|
'each': {
|
|||
|
pattern: /((?:^|\n)[\t ]*)each .+? in\b/,
|
|||
|
lookbehind: true,
|
|||
|
inside: {
|
|||
|
'keyword': /\b(?:each|in)\b/,
|
|||
|
'punctuation': /,/
|
|||
|
}
|
|||
|
},
|
|||
|
'branch': {
|
|||
|
pattern: /((?:^|\n)[\t ]*)(?:if|unless|else|case|when|default|while)/,
|
|||
|
lookbehind: true,
|
|||
|
alias: 'keyword'
|
|||
|
},
|
|||
|
rest: Prism.languages.javascript
|
|||
|
}
|
|||
|
},
|
|||
|
'keyword': {
|
|||
|
pattern: /((?:^|\n)[\t ]*)(?:block|extends|include|append|prepend)\b.+/,
|
|||
|
lookbehind: true
|
|||
|
},
|
|||
|
'mixin': [
|
|||
|
// Declaration
|
|||
|
{
|
|||
|
pattern: /((?:^|\n)[\t ]*)mixin .+/,
|
|||
|
lookbehind: true,
|
|||
|
inside: {
|
|||
|
'keyword': /^mixin/,
|
|||
|
'function': /\w+(?=\s*\(|\s*$)/,
|
|||
|
'punctuation': /[(),.]/
|
|||
|
}
|
|||
|
},
|
|||
|
// Usage
|
|||
|
{
|
|||
|
pattern: /((?:^|\n)[\t ]*)\+.+/,
|
|||
|
lookbehind: true,
|
|||
|
inside: {
|
|||
|
'name': {
|
|||
|
pattern: /^\+\w+/,
|
|||
|
alias: 'function'
|
|||
|
},
|
|||
|
'rest': Prism.languages.javascript
|
|||
|
}
|
|||
|
}
|
|||
|
],
|
|||
|
'script': {
|
|||
|
pattern: /((?:^|\n)[\t ]*script(?:(?:&[^(]+)?\([^)]+\))*) .+/,
|
|||
|
lookbehind: true,
|
|||
|
inside: {
|
|||
|
rest: Prism.languages.javascript
|
|||
|
}
|
|||
|
},
|
|||
|
|
|||
|
'plain-text': {
|
|||
|
pattern: /((?:^|\n)[\t ]*(?!-)[\w\-#.]*[\w\-](?:(?:&[^(]+)?\([^)]+\))*\/?[\t ]+).+/,
|
|||
|
lookbehind: true
|
|||
|
},
|
|||
|
'tag': {
|
|||
|
pattern: /((?:^|\n)[\t ]*)(?!-)[\w\-#.]*[\w\-](?:(?:&[^(]+)?\([^)]+\))*\/?:?/,
|
|||
|
lookbehind: true,
|
|||
|
inside: {
|
|||
|
'attributes': [
|
|||
|
{
|
|||
|
pattern: /&[^(]+\([^)]+\)/,
|
|||
|
inside: {
|
|||
|
rest: Prism.languages.javascript
|
|||
|
}
|
|||
|
},
|
|||
|
{
|
|||
|
pattern: /\([^)]+\)/,
|
|||
|
inside: {
|
|||
|
'attr-value': {
|
|||
|
pattern: /(=\s*)(?:\{[^}]*\}|[^,)\n]+)/,
|
|||
|
lookbehind: true,
|
|||
|
inside: {
|
|||
|
rest: Prism.languages.javascript
|
|||
|
}
|
|||
|
},
|
|||
|
'attr-name': /[\w-]+(?=\s*!?=|\s*[,)])/,
|
|||
|
'punctuation': /[!=(),]/
|
|||
|
}
|
|||
|
}
|
|||
|
],
|
|||
|
'punctuation': /[:]/
|
|||
|
}
|
|||
|
},
|
|||
|
'code': [
|
|||
|
{
|
|||
|
pattern: /((?:^|\n)[\t ]*(?:-|!?=)).+/,
|
|||
|
lookbehind: true,
|
|||
|
inside: {
|
|||
|
rest: Prism.languages.javascript
|
|||
|
}
|
|||
|
}
|
|||
|
],
|
|||
|
'punctuation': /[.\-!=|]/
|
|||
|
};
|
|||
|
|
|||
|
var filter_pattern = '((?:^|\\n)([\\t ]*)):{{filter_name}}(\\n(?:\\2[\\t ]+.+|\\s*?(?=\\n)))+';
|
|||
|
|
|||
|
// Non exhaustive list of available filters and associated languages
|
|||
|
var filters = [
|
|||
|
{filter:'atpl',language:'twig'},
|
|||
|
{filter:'coffee',language:'coffeescript'},
|
|||
|
'ejs',
|
|||
|
'handlebars',
|
|||
|
'hogan',
|
|||
|
'less',
|
|||
|
'livescript',
|
|||
|
'markdown',
|
|||
|
'mustache',
|
|||
|
'plates',
|
|||
|
{filter:'sass',language:'scss'},
|
|||
|
'stylus',
|
|||
|
'swig'
|
|||
|
|
|||
|
];
|
|||
|
var all_filters = {};
|
|||
|
for (var i = 0, l = filters.length; i < l; i++) {
|
|||
|
var filter = filters[i];
|
|||
|
filter = typeof filter === 'string' ? {filter: filter, language: filter} : filter;
|
|||
|
if (Prism.languages[filter.language]) {
|
|||
|
all_filters['filter-' + filter.filter] = {
|
|||
|
pattern: RegExp(filter_pattern.replace('{{filter_name}}', filter.filter)),
|
|||
|
lookbehind: true,
|
|||
|
inside: {
|
|||
|
'filter-name': {
|
|||
|
pattern: /^:[\w-]+/,
|
|||
|
alias: 'variable'
|
|||
|
},
|
|||
|
rest: Prism.languages[filter.language]
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
Prism.languages.insertBefore('jade', 'filter', all_filters);
|
|||
|
|
|||
|
}(Prism));;
|
|||
|
Prism.languages.latex = {
|
|||
|
'comment': /%.*?(\r?\n|$)$/m,
|
|||
|
'string': /(\$)(\\?.)*?\1/,
|
|||
|
'punctuation': /[{}]/,
|
|||
|
'selector': /\\[a-z;,:\.]*/i
|
|||
|
};;
|
|||
|
Prism.languages.makefile = {
|
|||
|
'comment': {
|
|||
|
pattern: /(^|[^\\])#(?:\\[\s\S]|.)*/,
|
|||
|
lookbehind: true
|
|||
|
},
|
|||
|
'string': /(["'])(?:\\[\s\S]|(?!\1)[^\\\r\n])*\1/,
|
|||
|
|
|||
|
// Built-in target names
|
|||
|
'builtin': /\.[A-Z][^:#=\s]+(?=\s*:(?!=))/,
|
|||
|
|
|||
|
// Targets
|
|||
|
'symbol': {
|
|||
|
pattern: /^[^:=\r\n]+(?=\s*:(?!=))/m,
|
|||
|
inside: {
|
|||
|
'variable': /\$+(?:[^(){}:#=\s]+|(?=[({]))/
|
|||
|
}
|
|||
|
},
|
|||
|
'variable': /\$+(?:[^(){}:#=\s]+|\([@*%<^+?][DF]\)|(?=[({]))/,
|
|||
|
|
|||
|
'keyword': [
|
|||
|
// Directives
|
|||
|
/\b(?:define|else|endef|endif|export|ifn?def|ifn?eq|-?include|override|private|sinclude|undefine|unexport|vpath)\b/,
|
|||
|
// Functions
|
|||
|
{
|
|||
|
pattern: /(\()(?:addsuffix|abspath|and|basename|call|dir|error|eval|file|filter(?:-out)?|findstring|firstword|flavor|foreach|guile|if|info|join|lastword|load|notdir|or|origin|patsubst|realpath|shell|sort|strip|subst|suffix|value|warning|wildcard|word(?:s|list)?)(?=[ \t])/,
|
|||
|
lookbehind: true
|
|||
|
}
|
|||
|
],
|
|||
|
'operator': /(?:::|[?:+!])?=|[|@]/,
|
|||
|
'punctuation': /[:;(){}]/
|
|||
|
};;
|
|||
|
Prism.languages.markdown = Prism.languages.extend('markup', {});
|
|||
|
Prism.languages.insertBefore('markdown', 'prolog', {
|
|||
|
'blockquote': {
|
|||
|
// > ...
|
|||
|
pattern: /(^|\n)>(?:[\t ]*>)*/,
|
|||
|
lookbehind: true,
|
|||
|
alias: 'punctuation'
|
|||
|
},
|
|||
|
'code': [
|
|||
|
{
|
|||
|
// Prefixed by 4 spaces or 1 tab
|
|||
|
pattern: /(^|\n)(?: {4}|\t).+/,
|
|||
|
lookbehind: true,
|
|||
|
alias: 'keyword'
|
|||
|
},
|
|||
|
{
|
|||
|
// `code`
|
|||
|
// ``code``
|
|||
|
pattern: /``.+?``|`[^`\n]+`/,
|
|||
|
alias: 'keyword'
|
|||
|
}
|
|||
|
],
|
|||
|
'title': [
|
|||
|
{
|
|||
|
// title 1
|
|||
|
// =======
|
|||
|
|
|||
|
// title 2
|
|||
|
// -------
|
|||
|
pattern: /\w+.*\n(?:==+|--+)/,
|
|||
|
alias: 'important',
|
|||
|
inside: {
|
|||
|
punctuation: /==+$|--+$/
|
|||
|
}
|
|||
|
},
|
|||
|
{
|
|||
|
// # title 1
|
|||
|
// ###### title 6
|
|||
|
pattern: /((?:^|\n)\s*)#+.+/,
|
|||
|
lookbehind: true,
|
|||
|
alias: 'important',
|
|||
|
inside: {
|
|||
|
punctuation: /^#+|#+$/
|
|||
|
}
|
|||
|
}
|
|||
|
],
|
|||
|
'hr': {
|
|||
|
// ***
|
|||
|
// ---
|
|||
|
// * * *
|
|||
|
// -----------
|
|||
|
pattern: /((?:^|\n)\s*)([*-])([\t ]*\2){2,}(?=\s*(?:\n|$))/,
|
|||
|
lookbehind: true,
|
|||
|
alias: 'punctuation'
|
|||
|
},
|
|||
|
'list': {
|
|||
|
// * item
|
|||
|
// + item
|
|||
|
// - item
|
|||
|
// 1. item
|
|||
|
pattern: /((?:^|\n)\s*)(?:[*+-]|\d+\.)(?=[\t ].)/,
|
|||
|
lookbehind: true,
|
|||
|
alias: 'punctuation'
|
|||
|
},
|
|||
|
'url-reference': {
|
|||
|
// [id]: http://example.com "Optional title"
|
|||
|
// [id]: http://example.com 'Optional title'
|
|||
|
// [id]: http://example.com (Optional title)
|
|||
|
// [id]: <http://example.com> "Optional title"
|
|||
|
pattern: /!?\[[^\]]+\]:[\t ]+(?:\S+|<(?:[^>]|\\>)+>)(?:[\t ]+(?:"(?:[^"]|\\")*"|'(?:[^']|\\')*'|\((?:[^)]|\\\))*\)))?/,
|
|||
|
inside: {
|
|||
|
'variable': {
|
|||
|
pattern: /^(!?\[)[^\]]+/,
|
|||
|
lookbehind: true
|
|||
|
},
|
|||
|
'string': /(?:"(?:[^"]|\\")*"|'(?:[^']|\\')*'|\((?:[^)]|\\\))*\))$/,
|
|||
|
'punctuation': /[[\]\(\)<>:]/
|
|||
|
},
|
|||
|
alias: 'url'
|
|||
|
},
|
|||
|
'bold': {
|
|||
|
// **strong**
|
|||
|
// __strong__
|
|||
|
|
|||
|
// Allow only one line break
|
|||
|
pattern: /(^|[^\\])(\*\*|__)(?:\n(?!\n)|.)+?\2/,
|
|||
|
lookbehind: true,
|
|||
|
inside: {
|
|||
|
'punctuation': /^\*\*|^__|\*\*\s*$|__\s*$/
|
|||
|
}
|
|||
|
},
|
|||
|
'italic': {
|
|||
|
// *em*
|
|||
|
// _em_
|
|||
|
|
|||
|
// Allow only one line break
|
|||
|
pattern: /(^|[^\\])(?:\*(?:\n(?!\n)|.)+?\*|_(?:\n(?!\n)|.)+?_)/,
|
|||
|
lookbehind: true,
|
|||
|
inside: {
|
|||
|
'punctuation': /^[*_]|[*_]$/
|
|||
|
}
|
|||
|
},
|
|||
|
'url': {
|
|||
|
// [example](http://example.com "Optional title")
|
|||
|
// [example] [id]
|
|||
|
pattern: /!?\[[^\]]+\](?:\([^\s)]+(?:[\t ]+"(?:[^"]|\\")*")?\)| ?\[[^\]\n]*\])/,
|
|||
|
inside: {
|
|||
|
'variable': {
|
|||
|
pattern: /(!?\[)[^\]]+(?=\]$)/,
|
|||
|
lookbehind: true
|
|||
|
},
|
|||
|
'string': {
|
|||
|
pattern: /"(?:[^"]|\\")*"(?=\)$)/
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
Prism.languages.markdown['bold'].inside['url'] = Prism.util.clone(Prism.languages.markdown['url']);
|
|||
|
Prism.languages.markdown['italic'].inside['url'] = Prism.util.clone(Prism.languages.markdown['url']);
|
|||
|
Prism.languages.markdown['bold'].inside['italic'] = Prism.util.clone(Prism.languages.markdown['italic']);
|
|||
|
Prism.languages.markdown['italic'].inside['bold'] = Prism.util.clone(Prism.languages.markdown['bold']);;
|
|||
|
/**
|
|||
|
* Original by Aaron Harun: http://aahacreative.com/2012/07/31/php-syntax-highlighting-prism/
|
|||
|
* Modified by Miles Johnson: http://milesj.me
|
|||
|
*
|
|||
|
* Supports the following:
|
|||
|
* - Extends clike syntax
|
|||
|
* - Support for PHP 5.3+ (namespaces, traits, generators, etc)
|
|||
|
* - Smarter constant and function matching
|
|||
|
*
|
|||
|
* Adds the following new token classes:
|
|||
|
* constant, delimiter, variable, function, package
|
|||
|
*/
|
|||
|
|
|||
|
Prism.languages.php = Prism.languages.extend('clike', {
|
|||
|
'keyword': /\b(and|or|xor|array|as|break|case|cfunction|class|const|continue|declare|default|die|do|else|elseif|enddeclare|endfor|endforeach|endif|endswitch|endwhile|extends|for|foreach|function|include|include_once|global|if|new|return|static|switch|use|require|require_once|var|while|abstract|interface|public|implements|private|protected|parent|throw|null|echo|print|trait|namespace|final|yield|goto|instanceof|finally|try|catch)\b/i,
|
|||
|
'constant': /\b[A-Z0-9_]{2,}\b/,
|
|||
|
'comment': {
|
|||
|
pattern: /(^|[^\\])(\/\*[\w\W]*?\*\/|(^|[^:])(\/\/).*?(\r?\n|$))/,
|
|||
|
lookbehind: true
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
// Shell-like comments are matched after strings, because they are less
|
|||
|
// common than strings containing hashes...
|
|||
|
Prism.languages.insertBefore('php', 'class-name', {
|
|||
|
'shell-comment': {
|
|||
|
pattern: /(^|[^\\])#.*?(\r?\n|$)/,
|
|||
|
lookbehind: true,
|
|||
|
alias: 'comment'
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
Prism.languages.insertBefore('php', 'keyword', {
|
|||
|
'delimiter': /(\?>|<\?php|<\?)/i,
|
|||
|
'variable': /(\$\w+)\b/i,
|
|||
|
'package': {
|
|||
|
pattern: /(\\|namespace\s+|use\s+)[\w\\]+/,
|
|||
|
lookbehind: true,
|
|||
|
inside: {
|
|||
|
punctuation: /\\/
|
|||
|
}
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
// Must be defined after the function pattern
|
|||
|
Prism.languages.insertBefore('php', 'operator', {
|
|||
|
'property': {
|
|||
|
pattern: /(->)[\w]+/,
|
|||
|
lookbehind: true
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
// Add HTML support of the markup language exists
|
|||
|
if (Prism.languages.markup) {
|
|||
|
|
|||
|
// Tokenize all inline PHP blocks that are wrapped in <?php ?>
|
|||
|
// This allows for easy PHP + markup highlighting
|
|||
|
Prism.hooks.add('before-highlight', function(env) {
|
|||
|
if (env.language !== 'php') {
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
env.tokenStack = [];
|
|||
|
|
|||
|
env.backupCode = env.code;
|
|||
|
env.code = env.code.replace(/(?:<\?php|<\?)[\w\W]*?(?:\?>)/ig, function(match) {
|
|||
|
env.tokenStack.push(match);
|
|||
|
|
|||
|
return '{{{PHP' + env.tokenStack.length + '}}}';
|
|||
|
});
|
|||
|
});
|
|||
|
|
|||
|
// Restore env.code for other plugins (e.g. line-numbers)
|
|||
|
Prism.hooks.add('before-insert', function(env) {
|
|||
|
if (env.language === 'php') {
|
|||
|
env.code = env.backupCode;
|
|||
|
delete env.backupCode;
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
// Re-insert the tokens after highlighting
|
|||
|
Prism.hooks.add('after-highlight', function(env) {
|
|||
|
if (env.language !== 'php') {
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
for (var i = 0, t; t = env.tokenStack[i]; i++) {
|
|||
|
env.highlightedCode = env.highlightedCode.replace('{{{PHP' + (i + 1) + '}}}', Prism.highlight(t, env.grammar, 'php'));
|
|||
|
}
|
|||
|
|
|||
|
env.element.innerHTML = env.highlightedCode;
|
|||
|
});
|
|||
|
|
|||
|
// Wrap tokens in classes that are missing them
|
|||
|
Prism.hooks.add('wrap', function(env) {
|
|||
|
if (env.language === 'php' && env.type === 'markup') {
|
|||
|
env.content = env.content.replace(/(\{\{\{PHP[0-9]+\}\}\})/g, "<span class=\"token php\">$1</span>");
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
// Add the rules before all others
|
|||
|
Prism.languages.insertBefore('php', 'comment', {
|
|||
|
'markup': {
|
|||
|
pattern: /<[^?]\/?(.*?)>/,
|
|||
|
inside: Prism.languages.markup
|
|||
|
},
|
|||
|
'php': /\{\{\{PHP[0-9]+\}\}\}/
|
|||
|
});
|
|||
|
}
|
|||
|
;
|
|||
|
Prism.languages.insertBefore('php', 'variable', {
|
|||
|
'this': /\$this/,
|
|||
|
'global': /\$_?(GLOBALS|SERVER|GET|POST|FILES|REQUEST|SESSION|ENV|COOKIE|HTTP_RAW_POST_DATA|argc|argv|php_errormsg|http_response_header)/,
|
|||
|
'scope': {
|
|||
|
pattern: /\b[\w\\]+::/,
|
|||
|
inside: {
|
|||
|
keyword: /(static|self|parent)/,
|
|||
|
punctuation: /(::|\\)/
|
|||
|
}
|
|||
|
}
|
|||
|
});;
|
|||
|
Prism.languages.powershell = {
|
|||
|
'comment': [
|
|||
|
{
|
|||
|
pattern: /(^|[^`])<#[\w\W]*?#>/,
|
|||
|
lookbehind: true
|
|||
|
},
|
|||
|
{
|
|||
|
pattern: /(^|[^`])#.*?(\r?\n|$)/,
|
|||
|
lookbehind: true
|
|||
|
}
|
|||
|
],
|
|||
|
'string': {
|
|||
|
pattern: /("|')(`?[\w\W])*?\1/m,
|
|||
|
inside: {}
|
|||
|
},
|
|||
|
// Matches name spaces as well as casts, attribute decorators. Force starting with letter to avoid matching array indices
|
|||
|
'namespace': /\[[a-z][\w\W]*?\]/i,
|
|||
|
'boolean': /\$(true|false)\b/i,
|
|||
|
'variable': /\$\w+\b/i,
|
|||
|
// per http://technet.microsoft.com/en-us/library/hh847744.aspx
|
|||
|
'keyword': /\b(Begin|Break|Catch|Class|Continue|Data|Define|Do|DynamicParam|Else|ElseIf|End|Exit|Filter|Finally|For|ForEach|From|Function|If|In|InlineScript|Parallel|Param|Process|Return|Sequence|Switch|Throw|Trap|Try|Until|Using|Var|While|Workflow)\b/i,
|
|||
|
// Cmdlets and aliases. Aliases should come last, otherwise "write" gets preferred over "write-host" for example
|
|||
|
// Get-Command | ?{ $_.ModuleName -match "Microsoft.PowerShell.(Util|Core|Management)" }
|
|||
|
// Get-Alias | ?{ $_.ReferencedCommand.Module.Name -match "Microsoft.PowerShell.(Util|Core|Management)" }
|
|||
|
'function': /\b(Add-(Computer|Content|History|Member|PSSnapin|Type)|Checkpoint-(Computer|Content|EventLog|History|Item|ItemProperty|Variable)|Compare-(Object)|Complete-(Transaction)|Connect-(PSSession)|ConvertFrom-(Csv|Json|StringData)|Convert-(Path)|ConvertTo-(Csv|Html|Json|Xml)|Copy-(Item|ItemProperty)|Debug-(Process)|Disable-(ComputerRestore|PSBreakpoint|PSRemoting|PSSessionConfiguration)|Disconnect-(PSSession)|Enable-(ComputerRestore|PSBreakpoint|PSRemoting|PSSessionConfiguration)|Enter-(PSSession)|Exit-(PSSession)|Export-(Alias|Clixml|Console|Csv|FormatData|ModuleMember|PSSession)|ForEach-(Object)|Format-(Custom|List|Table|Wide)|Get-(Alias|ChildItem|Command|ComputerRestorePoint|Content|ControlPanelItem|Culture|Date|Event|EventLog|EventSubscriber|FormatData|Help|History|Host|HotFix|Item|ItemProperty|Job|Location|Member|Module|Process|PSBreakpoint|PSCallStack|PSDrive|PSProvider|PSSession|PSSessionConfiguration|PSSnapin|Random|Service|TraceSource|Transaction|TypeData|UICulture|Unique|Variable|WmiObject)|Group-(Object)|Import-(Alias|Clixml|Csv|LocalizedData|Module|PSSession)|Invoke-(Command|Expression|History|Item|RestMethod|WebRequest|WmiMethod)|Join-(Path)|Limit-(EventLog)|Measure-(Command)|Measure-(Object)|Move-(Item|ItemProperty)|New-(Alias|Event|EventLog|Item|ItemProperty|Module|ModuleManifest|Object|PSDrive|PSSession|PSSessionConfigurationFile|PSSessionOption|PSTransportOption|Service|TimeSpan|Variable|WebServiceProxy)|Out-(Default|File|GridView|Host|Null|Printer|String)|Pop-(Location)|Push-(Location)|Read-(Host)|Receive-(Job)|Receive-(PSSession)|Register-(EngineEvent|ObjectEvent|PSSessionConfiguration|WmiEvent)|Remove-(Computer|Event|EventLog|Item|ItemProperty|Job|Module|PSBreakpoint|PSDrive|PSSession|PSSnapin|TypeData|Variable|WmiObject)|Rename-(Computer|Item|ItemProperty)|Reset-(ComputerMachinePassword)|Resolve-(Path)|Restart-(Computer|Service)|Restore-(Computer)|Resume-(Job|Service)|Save-(Help)|Select-(Object|String|Xml)|Send-(MailMessage)|Set-(Alias|Content|Date|Item|ItemProperty|Location|PSBreakpoint|PSDebug|PSSessionConfiguration|Service|StrictMode|TraceSource|Variable|WmiInstance)|Show-(Command|ControlPanelItem|EventLog)|Sort-(Object)|Split-(Path)|Start-(Job|Process|Service|Sleep|Transaction)|Stop-(Computer|Job|Process|Service)|Suspend-(Job|Service)|Tee-(Object)|Test-(ComputerSecureChannel|Connection|ModuleManifest|Path|PSSessionConfigurationFile)|Trace-(Command)|Unblock-(File)|Undo-(Transaction)|Unregister-(Event|PSSessionConfiguration)|Update-(FormatData)|Update-(Help|List|TypeData)|Use-(Transaction)|Wait-(Event|Job|Process)|Where-(Object)|Write-(Debug|Error|EventLog|Host|Output|Progress|Verbose|Warning)|ac|cat|cd|chdir|clc|cli|clp|clv|compare|copy|cp|cpi|cpp|cvpa|dbp|del|diff|dir|ebp|echo|epal|epcsv|epsn|erase|fc|fl|ft|fw|gal|gbp|gc|gci|gcs|gdr|gi|gl|gm|gp|gps|group|gsv|gu|gv|gwmi|iex|ii|ipal|ipcsv|ipsn|irm|iwmi|iwr|kill|lp|ls|measure|mi|mount|move|mp|mv|nal|ndr|ni|nv|ogv|popd|ps|pushd|pwd|rbp|rd|rdr|ren|ri|rm|rmdir|rni|rnp|rp|rv|rvpa|rwmi|sal|saps|sasv|sbp|sc|select|set|shcm|si|sl|sleep|sls|sort|sp|spps|spsv|start|sv|swmi|tee|trcm|type|write)\b/i,
|
|||
|
'operator': {
|
|||
|
pattern: /(\W)-(and|x?or|not|eq|ne|gt|ge|lt|le|Like|(Not)?(Like|Match|Contains|In)|Replace)\b/i,
|
|||
|
lookbehind: true
|
|||
|
},
|
|||
|
'punctuation': /[|{}[\];(),.]/
|
|||
|
};
|
|||
|
// Variable interpolation inside strings
|
|||
|
Prism.languages.powershell.string.inside.boolean = Prism.languages.powershell.boolean;
|
|||
|
Prism.languages.powershell.string.inside.variable = Prism.languages.powershell.variable;;
|
|||
|
Prism.languages.python= {
|
|||
|
'comment': {
|
|||
|
pattern: /(^|[^\\])#.*?(\r?\n|$)/,
|
|||
|
lookbehind: true
|
|||
|
},
|
|||
|
'string': /"""[\s\S]+?"""|'''[\s\S]+?'''|("|')(\\?.)*?\1/,
|
|||
|
'function' : {
|
|||
|
pattern: /((^|\s)def[ \t]+)([a-zA-Z_][a-zA-Z0-9_]*(?=\())/g,
|
|||
|
lookbehind: true
|
|||
|
},
|
|||
|
'keyword' : /\b(as|assert|async|await|break|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|pass|print|raise|return|try|while|with|yield)\b/,
|
|||
|
'boolean' : /\b(True|False)\b/,
|
|||
|
'number' : /\b-?(0[bo])?(?:(\d|0x[a-f])[\da-f]*\.?\d*|\.\d+)(?:e[+-]?\d+)?j?\b/i,
|
|||
|
'operator' : /[-+]|<=?|>=?|!|={1,2}|&{1,2}|\|?\||\?|\*|\/|@|~|\^|%|\b(or|and|not)\b/,
|
|||
|
'punctuation' : /[{}[\];(),.:]/
|
|||
|
};
|
|||
|
;
|
|||
|
/**
|
|||
|
* Original by Samuel Flores
|
|||
|
*
|
|||
|
* Adds the following new token classes:
|
|||
|
* constant, builtin, variable, symbol, regex
|
|||
|
*/
|
|||
|
Prism.languages.ruby = Prism.languages.extend('clike', {
|
|||
|
'comment': /#(?!\{[^\r\n]*?\})[^\r\n]*(\r?\n|$)/,
|
|||
|
'keyword': /\b(alias|and|BEGIN|begin|break|case|class|def|define_method|defined|do|each|else|elsif|END|end|ensure|false|for|if|in|module|new|next|nil|not|or|raise|redo|require|rescue|retry|return|self|super|then|throw|true|undef|unless|until|when|while|yield)\b/,
|
|||
|
'builtin': /\b(Array|Bignum|Binding|Class|Continuation|Dir|Exception|FalseClass|File|Stat|File|Fixnum|Fload|Hash|Integer|IO|MatchData|Method|Module|NilClass|Numeric|Object|Proc|Range|Regexp|String|Struct|TMS|Symbol|ThreadGroup|Thread|Time|TrueClass)\b/,
|
|||
|
'constant': /\b[A-Z][a-zA-Z_0-9]*[?!]?\b/
|
|||
|
});
|
|||
|
|
|||
|
Prism.languages.insertBefore('ruby', 'keyword', {
|
|||
|
'regex': {
|
|||
|
pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\r\n])+\/[gim]{0,3}(?=\s*($|[\r\n,.;})]))/,
|
|||
|
lookbehind: true
|
|||
|
},
|
|||
|
'variable': /[@$]+\b[a-zA-Z_][a-zA-Z_0-9]*[?!]?\b/,
|
|||
|
'symbol': /:\b[a-zA-Z_][a-zA-Z_0-9]*[?!]?\b/
|
|||
|
});
|
|||
|
|
|||
|
Prism.languages.ruby.string = {
|
|||
|
pattern: /("|')(#\{[^}]+\}|\\\n|\\?.)*?\1/,
|
|||
|
inside: {
|
|||
|
'interpolation': {
|
|||
|
pattern: /#\{[^}]+\}/,
|
|||
|
inside: {
|
|||
|
'delimiter': {
|
|||
|
pattern: /^#\{|\}$/,
|
|||
|
alias: 'tag'
|
|||
|
},
|
|||
|
rest: Prism.util.clone(Prism.languages.ruby)
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
};
|
|||
|
;
|
|||
|
(function(Prism) {
|
|||
|
Prism.languages.sass = Prism.languages.extend('css', {
|
|||
|
// Sass comments don't need to be closed, only indented
|
|||
|
'comment': /^([ \t]*)\/[\/*].*(?:(?:\r?\n|\r)\1[ \t]+.+)*/m
|
|||
|
});
|
|||
|
|
|||
|
Prism.languages.insertBefore('sass', 'atrule', {
|
|||
|
// We want to consume the whole line
|
|||
|
'atrule-line': {
|
|||
|
// Includes support for = and + shortcuts
|
|||
|
pattern: /^(?:[ \t]*)[@+=].+/m,
|
|||
|
inside: {
|
|||
|
'atrule': /^(?:[ \t]*)(?:@[\w-]+|[+=])/m
|
|||
|
}
|
|||
|
}
|
|||
|
});
|
|||
|
delete Prism.languages.sass.atrule;
|
|||
|
|
|||
|
|
|||
|
var variable = /((\$[-_\w]+)|(#\{\$[-_\w]+\}))/i;
|
|||
|
var operator = /[-+]{1,2}|==?|!=|\|?\||\?|\*|\/|%/;
|
|||
|
|
|||
|
Prism.languages.insertBefore('sass', 'property', {
|
|||
|
// We want to consume the whole line
|
|||
|
'variable-line': {
|
|||
|
pattern: /(^|(?:\r?\n|\r))[ \t]*\$.+/,
|
|||
|
lookbehind: true,
|
|||
|
inside: {
|
|||
|
'punctuation': /:/,
|
|||
|
'variable': variable,
|
|||
|
'operator': operator
|
|||
|
}
|
|||
|
},
|
|||
|
// We want to consume the whole line
|
|||
|
'property-line': {
|
|||
|
pattern: /(^|(?:\r?\n|\r))[ \t]*(?:[^:\s]+[ ]*:.*|:[^:\s]+.*)/i,
|
|||
|
lookbehind: true,
|
|||
|
inside: {
|
|||
|
'property': [
|
|||
|
/[^:\s]+(?=\s*:)/,
|
|||
|
{
|
|||
|
pattern: /(:)[^:\s]+/,
|
|||
|
lookbehind: true
|
|||
|
}
|
|||
|
],
|
|||
|
'punctuation': /:/,
|
|||
|
'variable': variable,
|
|||
|
'operator': operator,
|
|||
|
'important': Prism.languages.sass.important
|
|||
|
}
|
|||
|
}
|
|||
|
});
|
|||
|
delete Prism.languages.sass.property;
|
|||
|
delete Prism.languages.sass.important;
|
|||
|
|
|||
|
// Now that whole lines for other patterns are consumed,
|
|||
|
// what's left should be selectors
|
|||
|
delete Prism.languages.sass.selector;
|
|||
|
Prism.languages.insertBefore('sass', 'punctuation', {
|
|||
|
'selector': {
|
|||
|
pattern: /([ \t]*).+(?:,(?:\r?\n|\r)\1[ \t]+.+)*/,
|
|||
|
lookbehind: true
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
}(Prism));;
|
|||
|
Prism.languages.scss = Prism.languages.extend('css', {
|
|||
|
'comment': {
|
|||
|
pattern: /(^|[^\\])(\/\*[\w\W]*?\*\/|\/\/.*?(\r?\n|$))/,
|
|||
|
lookbehind: true
|
|||
|
},
|
|||
|
'atrule': {
|
|||
|
pattern: /@[\w-]+(?:\([^()]+\)|[^(])*?(?=\s+(\{|;))/i,
|
|||
|
inside: {
|
|||
|
'rule': /@[\w-]+/
|
|||
|
// See rest below
|
|||
|
}
|
|||
|
},
|
|||
|
// url, compassified
|
|||
|
'url': /([-a-z]+-)*url(?=\()/i,
|
|||
|
// CSS selector regex is not appropriate for Sass
|
|||
|
// since there can be lot more things (var, @ directive, nesting..)
|
|||
|
// a selector must start at the end of a property or after a brace (end of other rules or nesting)
|
|||
|
// it can contain some caracters that aren't used for defining rules or end of selector, & (parent selector), or interpolated variable
|
|||
|
// the end of a selector is found when there is no rules in it ( {} or {\s}) or if there is a property (because an interpolated var
|
|||
|
// can "pass" as a selector- e.g: proper#{$erty})
|
|||
|
// this one was ard to do, so please be careful if you edit this one :)
|
|||
|
'selector': {
|
|||
|
pattern: /([^@;\{\}\(\)]?([^@;\{\}\(\)]|&|#\{\$[-_\w]+\})+)(?=\s*\{(\}|\s|[^\}]+(:|\{)[^\}]+))/m,
|
|||
|
inside: {
|
|||
|
'placeholder': /%[-_\w]+/i
|
|||
|
}
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
Prism.languages.insertBefore('scss', 'atrule', {
|
|||
|
'keyword': /@(if|else if|else|for|each|while|import|extend|debug|warn|mixin|include|function|return|content)|(?=@for\s+\$[-_\w]+\s)+from/i
|
|||
|
});
|
|||
|
|
|||
|
Prism.languages.insertBefore('scss', 'property', {
|
|||
|
// var and interpolated vars
|
|||
|
'variable': /((\$[-_\w]+)|(#\{\$[-_\w]+\}))/i
|
|||
|
});
|
|||
|
|
|||
|
Prism.languages.insertBefore('scss', 'function', {
|
|||
|
'placeholder': {
|
|||
|
pattern: /%[-_\w]+/i,
|
|||
|
alias: 'selector'
|
|||
|
},
|
|||
|
'statement': /\B!(default|optional)\b/i,
|
|||
|
'boolean': /\b(true|false)\b/,
|
|||
|
'null': /\b(null)\b/,
|
|||
|
'operator': /\s+([-+]{1,2}|={1,2}|!=|\|?\||\?|\*|\/|%)\s+/
|
|||
|
});
|
|||
|
|
|||
|
Prism.languages.scss['atrule'].inside.rest = Prism.util.clone(Prism.languages.scss);;
|
|||
|
Prism.languages.sql= {
|
|||
|
'comment': {
|
|||
|
pattern: /(^|[^\\])(\/\*[\w\W]*?\*\/|((--)|(\/\/)|#).*?(\r?\n|$))/,
|
|||
|
lookbehind: true
|
|||
|
},
|
|||
|
'string' : {
|
|||
|
pattern: /(^|[^@])("|')(\\?[\s\S])*?\2/,
|
|||
|
lookbehind: true
|
|||
|
},
|
|||
|
'variable': /@[\w.$]+|@("|'|`)(\\?[\s\S])+?\1/,
|
|||
|
'function': /\b(?:COUNT|SUM|AVG|MIN|MAX|FIRST|LAST|UCASE|LCASE|MID|LEN|ROUND|NOW|FORMAT)(?=\s*\()/i, // Should we highlight user defined functions too?
|
|||
|
'keyword': /\b(?:ACTION|ADD|AFTER|ALGORITHM|ALTER|ANALYZE|APPLY|AS|ASC|AUTHORIZATION|BACKUP|BDB|BEGIN|BERKELEYDB|BIGINT|BINARY|BIT|BLOB|BOOL|BOOLEAN|BREAK|BROWSE|BTREE|BULK|BY|CALL|CASCADE|CASCADED|CASE|CHAIN|CHAR VARYING|CHARACTER VARYING|CHECK|CHECKPOINT|CLOSE|CLUSTERED|COALESCE|COLUMN|COLUMNS|COMMENT|COMMIT|COMMITTED|COMPUTE|CONNECT|CONSISTENT|CONSTRAINT|CONTAINS|CONTAINSTABLE|CONTINUE|CONVERT|CREATE|CROSS|CURRENT|CURRENT_DATE|CURRENT_TIME|CURRENT_TIMESTAMP|CURRENT_USER|CURSOR|DATA|DATABASE|DATABASES|DATETIME|DBCC|DEALLOCATE|DEC|DECIMAL|DECLARE|DEFAULT|DEFINER|DELAYED|DELETE|DENY|DESC|DESCRIBE|DETERMINISTIC|DISABLE|DISCARD|DISK|DISTINCT|DISTINCTROW|DISTRIBUTED|DO|DOUBLE|DOUBLE PRECISION|DROP|DUMMY|DUMP|DUMPFILE|DUPLICATE KEY|ELSE|ENABLE|ENCLOSED BY|END|ENGINE|ENUM|ERRLVL|ERRORS|ESCAPE|ESCAPED BY|EXCEPT|EXEC|EXECUTE|EXIT|EXPLAIN|EXTENDED|FETCH|FIELDS|FILE|FILLFACTOR|FIRST|FIXED|FLOAT|FOLLOWING|FOR|FOR EACH ROW|FORCE|FOREIGN|FREETEXT|FREETEXTTABLE|FROM|FULL|FUNCTION|GEOMETRY|GEOMETRYCOLLECTION|GLOBAL|GOTO|GRANT|GROUP|HANDLER|HASH|HAVING|HOLDLOCK|IDENTITY|IDENTITY_INSERT|IDENTITYCOL|IF|IGNORE|IMPORT|INDEX|INFILE|INNER|INNODB|INOUT|INSERT|INT|INTEGER|INTERSECT|INTO|INVOKER|ISOLATION LEVEL|JOIN|KEY|KEYS|KILL|LANGUAGE SQL|LAST|LEFT|LIMIT|LINENO|LINES|LINESTRING|LOAD|LOCAL|LOCK|LONGBLOB|LONGTEXT|MATCH|MATCHED|MEDIUMBLOB|MEDIUMINT|MEDIUMTEXT|MERGE|MIDDLEINT|MODIFIES SQL DATA|MODIFY|MULTILINESTRING|MULTIPOINT|MULTIPOLYGON|NATIONAL|NATIONAL CHAR VARYING|NATIONAL CHARACTER|NATIONAL CHARACTER VARYING|NATIONAL VARCHAR|NATURAL|NCHAR|NCHAR VARCHAR|NEXT|NO|NO SQL|NOCHECK|NOCYCLE|NONCLUSTERED|NULLIF|NUMERIC|OF|OFF|OFFSETS|ON|OPEN|OPENDATASOURCE|OPENQUERY|OPENROWSET|OPTIMIZE|OPTION|OPTIONALLY|ORDER|OUT|OUTER|OUTFILE|OVER|PARTIAL|PARTITION|PERCENT|PIVOT|PLAN|POINT|POLYGON|PRECEDING|PRECISION|PREV|PRIMARY|PRINT|PRIVILEGES|PROC|PROCEDURE|PUBLIC|PURGE|QUICK|RAISERROR|READ|READS SQL DATA|READTEXT|REAL|RECONFIGURE|REFERENCES|RELEASE|RENAME|REPEATABLE|REPLICATION|REQUIRE|RESTORE|RESTRICT|RETURN|RETURNS|REVOKE|RIGHT|ROLLBACK|ROUTINE|ROWCOUNT|ROWGUIDCOL|ROWS?|RTREE|RULE|SAVE|SAVEPOINT|SCHEMA|SELECT|SERIAL|SERIALIZABLE|SESSION|SESSION_USER|SET|SETUSER|SHARE MODE|SHOW|SHUTDOWN|SIMPLE|SMALLINT|SNAPSHOT|SOME|SONAME|START|STARTING BY|STATISTICS|STATUS|STRIPED|SYSTEM_USER|TABLE|TABLES|TABLESPACE|TEMP(?:ORARY)?|TEMPTABLE|TERMINATED BY|TEXT|TEXTSIZE|THEN|TIMESTAMP|TINYBLOB|TINYINT|TINYTEXT|TO|TOP|TRAN|TRANSACTION|TRANSACTIONS|TRIGGER|TRUNCATE|TSEQUAL|TYPE|TYPES|UNBOUNDED|UNCOMMITTED|UNDEFINED|UNION|UNPIVOT|UPDATE|UPDATETEXT|USAGE|USE|USER|USING|VALUE|VALUES|VARBINARY|VARCHAR|VARCHARACTER|VARYING|VIEW|WAITFOR|WARNINGS|WHEN|WHERE|WHILE|WITH|WITH ROLLUP|WITHIN|WORK|WRITE|WRITETEXT)\b/i,
|
|||
|
'boolean': /\b(?:TRUE|FALSE|NULL)\b/i,
|
|||
|
'number': /\b-?(0x)?\d*\.?[\da-f]+\b/,
|
|||
|
'operator': /\b(?:ALL|AND|ANY|BETWEEN|EXISTS|IN|LIKE|NOT|OR|IS|UNIQUE|CHARACTER SET|COLLATE|DIV|OFFSET|REGEXP|RLIKE|SOUNDS LIKE|XOR)\b|[-+]|!|[=<>]{1,2}|(&){1,2}|\|?\||\?|\*|\//i,
|
|||
|
'punctuation': /[;[\]()`,.]/
|
|||
|
};;
|
|||
|
Prism.languages.wiki = Prism.languages.extend('markup', {
|
|||
|
'block-comment': {
|
|||
|
pattern: /(^|[^\\])\/\*[\w\W]*?\*\//,
|
|||
|
lookbehind: true,
|
|||
|
alias: 'comment'
|
|||
|
},
|
|||
|
'heading': {
|
|||
|
pattern: /^(=+).+?\1/m,
|
|||
|
inside: {
|
|||
|
'punctuation': /^=+|=+$/,
|
|||
|
'important': /.+/
|
|||
|
}
|
|||
|
},
|
|||
|
'emphasis': {
|
|||
|
pattern: /('{2,4}).+?\1/,
|
|||
|
inside: {
|
|||
|
'bold italic': {
|
|||
|
pattern: /('''').+?(?=\1)/,
|
|||
|
lookbehind: true
|
|||
|
},
|
|||
|
'bold': {
|
|||
|
pattern: /(''').+?(?=\1)/,
|
|||
|
lookbehind: true
|
|||
|
},
|
|||
|
'italic': {
|
|||
|
pattern: /('').+?(?=\1)/,
|
|||
|
lookbehind: true
|
|||
|
},
|
|||
|
'punctuation': /^''+|''+$/
|
|||
|
}
|
|||
|
},
|
|||
|
'hr': {
|
|||
|
pattern: /^-{4,}/m,
|
|||
|
alias: 'punctuation'
|
|||
|
},
|
|||
|
'url': [
|
|||
|
/ISBN +(?:97[89][ -]?)?(?:\d[ -]?){9}[\dx]\b/i,
|
|||
|
/(?:RFC|PMID) +\d+/,
|
|||
|
/\[\[.+?\]\]/,
|
|||
|
/\[.+?\]/
|
|||
|
],
|
|||
|
'variable': [
|
|||
|
/__[A-Z]+__/,
|
|||
|
/\{{3}.+?\}{3}/,
|
|||
|
/\{\{.+?}}/
|
|||
|
],
|
|||
|
'symbol': [
|
|||
|
/^#redirect/im,
|
|||
|
/~{3,5}/
|
|||
|
],
|
|||
|
// Handle table attrs:
|
|||
|
// {|
|
|||
|
// ! style="text-align:left;"| Item
|
|||
|
// |}
|
|||
|
'table-tag': {
|
|||
|
pattern: /((?:^|[|!])[|!])[^|\r\n]+\|(?!\|)/m,
|
|||
|
lookbehind: true,
|
|||
|
inside: {
|
|||
|
'table-bar': {
|
|||
|
pattern: /\|$/,
|
|||
|
alias: 'punctuation'
|
|||
|
},
|
|||
|
rest: Prism.languages.markup['tag'].inside
|
|||
|
}
|
|||
|
},
|
|||
|
'punctuation': /^(?:\{\||\|\}|\|-|[*#:;!|])|\|\||!!/m
|
|||
|
});
|
|||
|
|
|||
|
Prism.languages.insertBefore('wiki', 'tag', {
|
|||
|
// Prevent highlighting inside <nowiki>, <source> and <pre> tags
|
|||
|
'nowiki': {
|
|||
|
pattern: /<(nowiki|pre|source)\b[\w\W]*?>[\w\W]*?<\/\1>/i,
|
|||
|
inside: {
|
|||
|
'tag': {
|
|||
|
pattern: /<(?:nowiki|pre|source)\b[\w\W]*?>|<\/(?:nowiki|pre|source)>/i,
|
|||
|
inside: Prism.languages.markup['tag'].inside
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
});
|
|||
|
;
|