Exposing the build tree. (#1017)

* Exposing the build tree.

* Warning users about internal representation.
This commit is contained in:
Ryan Randall
2017-12-10 20:03:10 -05:00
committed by Kevin Barabash
parent 46176c1d69
commit 36ca9beaa7

View File

@@ -28,12 +28,7 @@ let render = function(
options: SettingsOptions,
) {
utils.clearNode(baseNode);
const settings = new Settings(options);
const tree = parseTree(expression, settings);
const node = buildTree(tree, expression, settings).toNode();
const node = generateBuildTree(expression, options).toNode();
baseNode.appendChild(node);
};
@@ -51,7 +46,6 @@ if (typeof document !== "undefined") {
}
}
/**
* Parse and build an expression, and return the markup for that.
*/
@@ -59,10 +53,8 @@ const renderToString = function(
expression: string,
options: SettingsOptions,
): string {
const settings = new Settings(options);
const tree = parseTree(expression, settings);
return buildTree(tree, expression, settings).toMarkup();
const markup = generateBuildTree(expression, options).toMarkup();
return markup;
};
/**
@@ -77,6 +69,19 @@ const generateParseTree = function(
};
/**
* Generates and returns the katex build tree. This is used for advanced
* use cases (like rendering to custom output).
*/
const generateBuildTree = function(
expression: string,
options: SettingsOptions,
) {
const settings = new Settings(options);
const tree = parseTree(expression, settings);
return buildTree(tree, expression, settings);
};
module.exports = {
render,
renderToString,
@@ -86,5 +91,11 @@ module.exports = {
* to change. Use at your own risk.
*/
__parse: generateParseTree,
/**
* NOTE: This method is not currently recommended for public use.
* The internal tree representation is unstable and is very likely
* to change. Use at your own risk.
*/
__getBuildTree: generateBuildTree,
ParseError,
};