Merge branch 'master' into versioning

This commit is contained in:
Frank Li 2017-08-08 11:39:23 -07:00 committed by GitHub
commit 9ddd2f5ea4
33 changed files with 702 additions and 90 deletions

View file

@ -18,6 +18,10 @@ class DocsSidebar extends React.Component {
render() {
let sidebar = this.props.metadata.sidebar;
let docsCategories = readCategories(sidebar);
const categoryName = docsCategories[this.props.metadata.language][0].name;
if (!categoryName) {
return null;
}
return (
<Container className="docsNavContainer" id="docsNav" wrapper={false}>
<SideNav

View file

@ -18,17 +18,17 @@ const React = require("react");
// Private helper vars
const lang = /\blang(?:uage)?-(?!\*)(\w+)\b/i;
const _ = (Prism = {
const Prism = {
util: {
encode(tokens) {
if (tokens instanceof Token) {
return new Token(
tokens.type,
_.util.encode(tokens.content),
Prism.util.encode(tokens.content),
tokens.alias
);
} else if (_.util.type(tokens) === "Array") {
return tokens.map(_.util.encode);
} else if (Prism.util.type(tokens) === "Array") {
return tokens.map(Prism.util.encode);
} else {
return tokens
.replace(/&/g, "&amp;")
@ -43,7 +43,7 @@ const _ = (Prism = {
// Deep clone a language definition (e.g. to extend it)
clone(o) {
const type = _.util.type(o);
const type = Prism.util.type(o);
switch (type) {
case "Object":
@ -51,7 +51,7 @@ const _ = (Prism = {
for (const key in o) {
if (o.hasOwnProperty(key)) {
clone[key] = _.util.clone(o[key]);
clone[key] = Prism.util.clone(o[key]);
}
}
@ -62,7 +62,7 @@ const _ = (Prism = {
return (
o.map &&
o.map(v => {
return _.util.clone(v);
return Prism.util.clone(v);
})
);
}
@ -73,7 +73,7 @@ const _ = (Prism = {
languages: {
extend(id, redef) {
const lang = _.util.clone(_.languages[id]);
const lang = Prism.util.clone(Prism.languages[id]);
for (const key in redef) {
lang[key] = redef[key];
@ -92,7 +92,7 @@ const _ = (Prism = {
* @param root The object that contains `inside`. If equal to Prism.languages, it can be omitted.
*/
insertBefore(inside, before, insert, root) {
root = root || _.languages;
root = root || Prism.languages;
const grammar = root[inside];
if (arguments.length == 2) {
@ -124,7 +124,7 @@ const _ = (Prism = {
}
// Update references in other language definitions
_.languages.DFS(_.languages, function(key, value) {
Prism.languages.DFS(Prism.languages, function(key, value) {
if (value === root[inside] && key != inside) {
this[key] = ret;
}
@ -139,10 +139,10 @@ const _ = (Prism = {
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);
if (Prism.util.type(o[i]) === "Object") {
Prism.languages.DFS(o[i], callback);
} else if (Prism.util.type(o[i]) === "Array") {
Prism.languages.DFS(o[i], callback, i);
}
}
}
@ -155,7 +155,7 @@ const _ = (Prism = {
);
for (let i = 0, element; (element = elements[i++]); ) {
_.highlightElement(element, async === true, callback);
Prism.highlightElement(element, async === true, callback);
}
},
@ -171,7 +171,7 @@ const _ = (Prism = {
if (parent) {
language = (parent.className.match(lang) || [, ""])[1];
grammar = _.languages[language];
grammar = Prism.languages[language];
}
// Set language on the element, if not present
@ -209,20 +209,20 @@ const _ = (Prism = {
code
};
_.hooks.run("before-highlight", env);
Prism.hooks.run("before-highlight", env);
if (async && _self.Worker) {
const worker = new Worker(_.filename);
if (async && Prismself.Worker) {
const worker = new Worker(Prism.filename);
worker.onmessage = function(evt) {
env.highlightedCode = Token.stringify(JSON.parse(evt.data), language);
_.hooks.run("before-insert", env);
Prism.hooks.run("before-insert", env);
env.element.innerHTML = env.highlightedCode;
callback && callback.call(env.element);
_.hooks.run("after-highlight", env);
Prism.hooks.run("after-highlight", env);
};
worker.postMessage(
@ -232,25 +232,25 @@ const _ = (Prism = {
})
);
} else {
env.highlightedCode = _.highlight(env.code, env.grammar, env.language);
env.highlightedCode = Prism.highlight(env.code, env.grammar, env.language);
_.hooks.run("before-insert", env);
Prism.hooks.run("before-insert", env);
env.element.innerHTML = env.highlightedCode;
callback && callback.call(element);
_.hooks.run("after-highlight", env);
Prism.hooks.run("after-highlight", env);
}
},
highlight(text, grammar, language) {
const tokens = _.tokenize(text, grammar);
return Token.stringify(_.util.encode(tokens), language);
const tokens = Prism.tokenize(text, grammar);
return Token.stringify(Prism.util.encode(tokens), language);
},
tokenize(text, grammar, language) {
const Token = _.Token;
const Token = Prism.Token;
const strarr = [text];
@ -270,7 +270,7 @@ const _ = (Prism = {
}
let patterns = grammar[token];
patterns = _.util.type(patterns) === "Array" ? patterns : [patterns];
patterns = Prism.util.type(patterns) === "Array" ? patterns : [patterns];
for (let j = 0; j < patterns.length; ++j) {
let pattern = patterns[j],
@ -319,7 +319,7 @@ const _ = (Prism = {
const wrapped = new Token(
token,
inside ? _.tokenize(match, inside) : match,
inside ? Prism.tokenize(match, inside) : match,
alias
);
@ -342,7 +342,7 @@ const _ = (Prism = {
all: {},
add(name, callback) {
const hooks = _.hooks.all;
const hooks = Prism.hooks.all;
hooks[name] = hooks[name] || [];
@ -350,7 +350,7 @@ const _ = (Prism = {
},
run(name, env) {
const callbacks = _.hooks.all[name];
const callbacks = Prism.hooks.all[name];
if (!callbacks || !callbacks.length) {
return;
@ -361,9 +361,9 @@ const _ = (Prism = {
}
}
}
});
};
const Token = (_.Token = function(type, content, alias) {
const Token = (Prism.Token = function(type, content, alias) {
this.type = type;
this.content = content;
this.alias = alias;
@ -374,7 +374,7 @@ Token.reactify = function(o, language, parent, key) {
return o;
}
if (_.util.type(o) === "Array") {
if (Prism.util.type(o) === "Array") {
return o.map((element, i) => {
return Token.reactify(element, language, o, i);
});
@ -395,11 +395,11 @@ Token.reactify = function(o, language, parent, key) {
}
if (o.alias) {
const aliases = _.util.type(o.alias) === "Array" ? o.alias : [o.alias];
const aliases = Prism.util.type(o.alias) === "Array" ? o.alias : [o.alias];
Array.prototype.push.apply(env.classes, aliases);
}
_.hooks.run("wrap", env);
Prism.hooks.run("wrap", env);
env.attributes.className = env.classes.join(" ");
@ -1100,7 +1100,7 @@ Prism.languages.yaml = {
const PrismComponent = React.createClass({
statics: {
_
Prism
},
getDefaultProps() {
return {
@ -1123,10 +1123,10 @@ const PrismComponent = React.createClass({
}
});
}
const grammar = _.languages[this.props.language];
const grammar = Prism.languages[this.props.language];
return (
<pre className={"prism language-" + this.props.language}>
{Token.reactify(_.tokenize(this.props.children, grammar))}
{Token.reactify(Prism.tokenize(this.props.children, grammar))}
{lines.map((line, ii) => {
return (
<div