Expose a new .__parse() method for generating a parse tree from a math expression.
This commit is contained in:
parent
1f90b36518
commit
b9eb8c74e0
14
katex.js
14
katex.js
|
@ -52,8 +52,22 @@ var renderToString = function(expression, options) {
|
||||||
return buildTree(tree, expression, settings).toMarkup();
|
return buildTree(tree, expression, settings).toMarkup();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse an expression and return the parse tree.
|
||||||
|
*/
|
||||||
|
var generateParseTree = function(expression, options) {
|
||||||
|
var settings = new Settings(options);
|
||||||
|
return parseTree(expression, settings);
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
render: render,
|
render: render,
|
||||||
renderToString: renderToString,
|
renderToString: renderToString,
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
__parse: generateParseTree,
|
||||||
ParseError: ParseError
|
ParseError: ParseError
|
||||||
};
|
};
|
||||||
|
|
|
@ -1116,6 +1116,31 @@ describe("A markup generator", function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("A parse tree generator", function() {
|
||||||
|
it("generates a tree", function() {
|
||||||
|
var tree = katex.__parse("\\sigma^2");
|
||||||
|
expect(JSON.stringify(tree)).toEqual(JSON.stringify([
|
||||||
|
{
|
||||||
|
"type": "supsub",
|
||||||
|
"value": {
|
||||||
|
"base": {
|
||||||
|
"type": "mathord",
|
||||||
|
"value": "\\sigma",
|
||||||
|
"mode": "math"
|
||||||
|
},
|
||||||
|
"sup": {
|
||||||
|
"type": "textord",
|
||||||
|
"value": "2",
|
||||||
|
"mode": "math"
|
||||||
|
},
|
||||||
|
"sub": undefined
|
||||||
|
},
|
||||||
|
"mode": "math"
|
||||||
|
}
|
||||||
|
]));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("An accent parser", function() {
|
describe("An accent parser", function() {
|
||||||
it("should not fail", function() {
|
it("should not fail", function() {
|
||||||
expect("\\vec{x}").toParse();
|
expect("\\vec{x}").toParse();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user