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

@@ -7,6 +7,7 @@
*/
var ParseError = require("./src/ParseError");
var Settings = require("./src/Settings");
var buildTree = require("./src/buildTree");
var parseTree = require("./src/parseTree");
@@ -16,11 +17,13 @@ var utils = require("./src/utils");
* Parse and build an expression, and place that expression in the DOM node
* given.
*/
var render = function(toParse, baseNode) {
var render = function(toParse, baseNode, options) {
utils.clearNode(baseNode);
var tree = parseTree(toParse);
var node = buildTree(tree).toNode();
var settings = new Settings(options);
var tree = parseTree(toParse, settings);
var node = buildTree(tree, settings).toNode();
baseNode.appendChild(node);
};
@@ -42,9 +45,11 @@ if (typeof document !== "undefined") {
/**
* Parse and build an expression, and return the markup for that.
*/
var renderToString = function(toParse) {
var tree = parseTree(toParse);
return buildTree(tree).toMarkup();
var renderToString = function(toParse, options) {
var settings = new Settings(options);
var tree = parseTree(toParse, settings);
return buildTree(tree, settings).toMarkup();
};
module.exports = {