Add an optional settings argument to render calls

Summary:
Add the ability to pass in options to the render calls which contain information about the parse. This information is passed around to the parser and builder, which parse and render differently depending on the options. Currently, this includes an option to render the math in display mode (i.e. centered, block level, and in displaystyle).

Also added some changes to make it easier to add new data to functions (now that new data doesn't need to be copied into the ParseFuncOrArg data structure, it is looked up when it is needed) and has more sane support for the `'original'` argType (as suggested by pull request #93).

Test Plan:
 - Make sure tests and lint pass
 - Make sure huxley screenshots didn't change, and new screenshot looks correct

Reviewers: alpert

Reviewed By: alpert

Differential Revision: https://phabricator.khanacademy.org/D13810
This commit is contained in:
Emily Eisenberg
2015-02-19 15:26:57 -08:00
parent d61a04c80d
commit fd18f6979e
14 changed files with 190 additions and 144 deletions

View File

@@ -1135,9 +1135,14 @@ var buildGroup = function(group, options, prev) {
/**
* Take an entire parse tree, and build it into an appropriate set of nodes.
*/
var buildTree = function(tree) {
var buildTree = function(tree, settings) {
var startStyle = Style.TEXT;
if (settings.displayMode) {
startStyle = Style.DISPLAY;
}
// Setup the default options
var options = new Options(Style.TEXT, "size5", "");
var options = new Options(startStyle, "size5", "");
// Build the expression contained in the tree
var expression = buildExpression(tree, options);
@@ -1161,7 +1166,11 @@ var buildTree = function(tree) {
makeSpan(["katex-inner"], [topStrut, bottomStrut, body])
]);
return katexNode;
if (settings.displayMode) {
return makeSpan(["katex-display"], [katexNode]);
} else {
return katexNode;
}
};
module.exports = buildTree;