update components
This commit is contained in:
parent
3f0cecbf02
commit
06ade66d61
881 changed files with 676 additions and 47086 deletions
|
@ -89,19 +89,19 @@ var _ = _self.Prism = {
|
|||
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) {
|
||||
|
@ -121,7 +121,7 @@ var _ = _self.Prism = {
|
|||
ret[token] = grammar[token];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Update references in other language definitions
|
||||
_.languages.DFS(_.languages, function(key, value) {
|
||||
if (value === root[inside] && key != inside) {
|
||||
|
@ -152,12 +152,19 @@ var _ = _self.Prism = {
|
|||
}
|
||||
},
|
||||
plugins: {},
|
||||
|
||||
|
||||
highlightAll: function(async, callback) {
|
||||
var elements = document.querySelectorAll('code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code');
|
||||
var env = {
|
||||
callback: callback,
|
||||
selector: 'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'
|
||||
};
|
||||
|
||||
_.hooks.run("before-highlightall", env);
|
||||
|
||||
var elements = env.elements || document.querySelectorAll(env.selector);
|
||||
|
||||
for (var i=0, element; element = elements[i++];) {
|
||||
_.highlightElement(element, async === true, callback);
|
||||
_.highlightElement(element, async === true, env.callback);
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -193,7 +200,9 @@ var _ = _self.Prism = {
|
|||
code: code
|
||||
};
|
||||
|
||||
if (!code || !grammar) {
|
||||
_.hooks.run('before-sanity-check', env);
|
||||
|
||||
if (!env.code || !env.grammar) {
|
||||
_.hooks.run('complete', env);
|
||||
return;
|
||||
}
|
||||
|
@ -267,6 +276,7 @@ var _ = _self.Prism = {
|
|||
var pattern = patterns[j],
|
||||
inside = pattern.inside,
|
||||
lookbehind = !!pattern.lookbehind,
|
||||
greedy = !!pattern.greedy,
|
||||
lookbehindLength = 0,
|
||||
alias = pattern.alias;
|
||||
|
||||
|
@ -287,36 +297,76 @@ var _ = _self.Prism = {
|
|||
|
||||
pattern.lastIndex = 0;
|
||||
|
||||
var match = pattern.exec(str);
|
||||
var match = pattern.exec(str),
|
||||
delNum = 1;
|
||||
|
||||
if (match) {
|
||||
if(lookbehind) {
|
||||
lookbehindLength = match[1].length;
|
||||
// Greedy patterns can override/remove up to two previously matched tokens
|
||||
if (!match && greedy && i != strarr.length - 1) {
|
||||
// Reconstruct the original text using the next two tokens
|
||||
var nextToken = strarr[i + 1].matchedStr || strarr[i + 1],
|
||||
combStr = str + nextToken;
|
||||
|
||||
if (i < strarr.length - 2) {
|
||||
combStr += strarr[i + 2].matchedStr || strarr[i + 2];
|
||||
}
|
||||
|
||||
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);
|
||||
// Try the pattern again on the reconstructed text
|
||||
pattern.lastIndex = 0;
|
||||
match = pattern.exec(combStr);
|
||||
if (!match) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var wrapped = new Token(token, inside? _.tokenize(match, inside) : match, alias);
|
||||
|
||||
args.push(wrapped);
|
||||
|
||||
if (after) {
|
||||
args.push(after);
|
||||
var from = match.index + (lookbehind ? match[1].length : 0);
|
||||
// To be a valid candidate, the new match has to start inside of str
|
||||
if (from >= str.length) {
|
||||
continue;
|
||||
}
|
||||
var to = match.index + match[0].length,
|
||||
len = str.length + nextToken.length;
|
||||
|
||||
Array.prototype.splice.apply(strarr, args);
|
||||
// Number of tokens to delete and replace with the new match
|
||||
delNum = 3;
|
||||
|
||||
if (to <= len) {
|
||||
if (strarr[i + 1].greedy) {
|
||||
continue;
|
||||
}
|
||||
delNum = 2;
|
||||
combStr = combStr.slice(0, len);
|
||||
}
|
||||
str = combStr;
|
||||
}
|
||||
|
||||
if (!match) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(lookbehind) {
|
||||
lookbehindLength = match[1].length;
|
||||
}
|
||||
|
||||
var from = match.index + lookbehindLength,
|
||||
match = match[0].slice(lookbehindLength),
|
||||
to = from + match.length,
|
||||
before = str.slice(0, from),
|
||||
after = str.slice(to);
|
||||
|
||||
var args = [i, delNum];
|
||||
|
||||
if (before) {
|
||||
args.push(before);
|
||||
}
|
||||
|
||||
var wrapped = new Token(token, inside? _.tokenize(match, inside) : match, alias, match, greedy);
|
||||
|
||||
args.push(wrapped);
|
||||
|
||||
if (after) {
|
||||
args.push(after);
|
||||
}
|
||||
|
||||
Array.prototype.splice.apply(strarr, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -349,10 +399,13 @@ var _ = _self.Prism = {
|
|||
}
|
||||
};
|
||||
|
||||
var Token = _.Token = function(type, content, alias) {
|
||||
var Token = _.Token = function(type, content, alias, matchedStr, greedy) {
|
||||
this.type = type;
|
||||
this.content = content;
|
||||
this.alias = alias;
|
||||
// Copy of the full string this token was created from
|
||||
this.matchedStr = matchedStr || null;
|
||||
this.greedy = !!greedy;
|
||||
};
|
||||
|
||||
Token.stringify = function(o, language, parent) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue