MCPcopy
hub / github.com/KaTeX/KaTeX / parseTree

Function parseTree

src/parseTree.ts:11–44  ·  view source on GitHub ↗
(
    toParse: string | InstanceType<typeof String>,
    settings: Settings,
)

Source from the content-addressed store, hash-verified

9 * Parses an expression using a Parser, then returns the parsed result.
10 */
11const parseTree = function(
12 toParse: string | InstanceType<typeof String>,
13 settings: Settings,
14): AnyParseNode[] {
15 if (!(typeof toParse === 'string' || toParse instanceof String)) {
16 throw new TypeError('KaTeX can only parse string typed expression');
17 }
18 const parser = new Parser(toParse as string, settings);
19
20 // Blank out any \df@tag to avoid spurious "Duplicate \tag" errors
21 delete parser.gullet.macros.current["\\df@tag"];
22
23 let tree = parser.parse();
24
25 // Prevent a color definition from persisting between calls to katex.render().
26 delete parser.gullet.macros.current["\\current@color"];
27 delete parser.gullet.macros.current["\\color"];
28
29 // If the input used \tag, it will set the \df@tag macro to the tag.
30 // In this case, we separately parse the tag and wrap the tree.
31 if (parser.gullet.macros.get("\\df@tag")) {
32 if (!settings.displayMode) {
33 throw new ParseError("\\tag works only in display equations");
34 }
35 tree = [{
36 type: "tag",
37 mode: "text",
38 body: tree,
39 tag: parser.subparse([new Token("\\df@tag")]),
40 }];
41 }
42
43 return tree;
44};
45
46export default parseTree;

Callers 5

generateParseTreeFunction · 0.85
renderToDomTreeFunction · 0.85
renderToHTMLTreeFunction · 0.85
getMathMLFunction · 0.85
getParsedFunction · 0.85

Calls 3

parseMethod · 0.95
subparseMethod · 0.95
getMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…