MCPcopy Create free account
hub / github.com/TruthHun/BookStack / handleInfixNodes

Method handleInfixNodes

static/katex/katex.mjs:15024–15079  ·  view source on GitHub ↗

* Rewrites infix operators such as \over with corresponding commands such * as \frac. * * There can only be one infix operator per group. If there's more than one * then the expression is ambiguous. This can be resolved by adding {}.

(body)

Source from the content-addressed store, hash-verified

15022
15023
15024 handleInfixNodes(body) {
15025 let overIndex = -1;
15026 let funcName;
15027
15028 for (let i = 0; i < body.length; i++) {
15029 const node = checkNodeType(body[i], "infix");
15030
15031 if (node) {
15032 if (overIndex !== -1) {
15033 throw new ParseError("only one infix operator per group", node.token);
15034 }
15035
15036 overIndex = i;
15037 funcName = node.replaceWith;
15038 }
15039 }
15040
15041 if (overIndex !== -1 && funcName) {
15042 let numerNode;
15043 let denomNode;
15044 const numerBody = body.slice(0, overIndex);
15045 const denomBody = body.slice(overIndex + 1);
15046
15047 if (numerBody.length === 1 && numerBody[0].type === "ordgroup") {
15048 numerNode = numerBody[0];
15049 } else {
15050 numerNode = {
15051 type: "ordgroup",
15052 mode: this.mode,
15053 body: numerBody
15054 };
15055 }
15056
15057 if (denomBody.length === 1 && denomBody[0].type === "ordgroup") {
15058 denomNode = denomBody[0];
15059 } else {
15060 denomNode = {
15061 type: "ordgroup",
15062 mode: this.mode,
15063 body: denomBody
15064 };
15065 }
15066
15067 let node;
15068
15069 if (funcName === "\\\\abovefrac") {
15070 node = this.callFunction(funcName, [numerNode, body[overIndex], denomNode], []);
15071 } else {
15072 node = this.callFunction(funcName, [numerNode, denomNode], []);
15073 }
15074
15075 return [node];
15076 } else {
15077 return body;
15078 }
15079 } // The greediness of a superscript or subscript
15080
15081

Callers 3

parseExpressionMethod · 0.95
katex.jsFile · 0.80
katex.min.jsFile · 0.80

Calls 2

callFunctionMethod · 0.95
checkNodeTypeFunction · 0.70

Tested by

no test coverage detected