(toParse, settings)
| 15915 | * Parses an expression using a Parser, then returns the parsed result. |
| 15916 | */ |
| 15917 | const parseTree = function parseTree(toParse, settings) { |
| 15918 | if (!(typeof toParse === 'string' || toParse instanceof String)) { |
| 15919 | throw new TypeError('KaTeX can only parse string typed expression'); |
| 15920 | } |
| 15921 | |
| 15922 | const parser = new Parser(toParse, settings); // Blank out any \df@tag to avoid spurious "Duplicate \tag" errors |
| 15923 | |
| 15924 | delete parser.gullet.macros.current["\\df@tag"]; |
| 15925 | let tree = parser.parse(); // If the input used \tag, it will set the \df@tag macro to the tag. |
| 15926 | // In this case, we separately parse the tag and wrap the tree. |
| 15927 | |
| 15928 | if (parser.gullet.macros.get("\\df@tag")) { |
| 15929 | if (!settings.displayMode) { |
| 15930 | throw new ParseError("\\tag works only in display equations"); |
| 15931 | } |
| 15932 | |
| 15933 | parser.gullet.feed("\\df@tag"); |
| 15934 | tree = [{ |
| 15935 | type: "tag", |
| 15936 | mode: "text", |
| 15937 | body: tree, |
| 15938 | tag: parser.parse() |
| 15939 | }]; |
| 15940 | } |
| 15941 | |
| 15942 | return tree; |
| 15943 | }; |
| 15944 | |
| 15945 | /* eslint no-console:0 */ |
| 15946 |
no test coverage detected