MCPcopy Index your code
hub / github.com/TruthHun/BookStack / buildExpression

Function buildExpression

static/katex/katex.mjs:6272–6345  ·  view source on GitHub ↗
(expression, options, isRealGroup, surrounding)

Source from the content-addressed store, hash-verified

6270 * consisting type of nodes that will be added to the left and right.
6271 */
6272const buildExpression = function buildExpression(expression, options, isRealGroup, surrounding) {
6273 if (surrounding === void 0) {
6274 surrounding = [null, null];
6275 }
6276
6277 // Parse expressions into `groups`.
6278 const groups = [];
6279
6280 for (let i = 0; i < expression.length; i++) {
6281 const output = buildGroup(expression[i], options);
6282
6283 if (output instanceof DocumentFragment) {
6284 const children = output.children;
6285 groups.push(...children);
6286 } else {
6287 groups.push(output);
6288 }
6289 } // If `expression` is a partial group, let the parent handle spacings
6290 // to avoid processing groups multiple times.
6291
6292
6293 if (!isRealGroup) {
6294 return groups;
6295 }
6296
6297 let glueOptions = options;
6298
6299 if (expression.length === 1) {
6300 const node = checkNodeType(expression[0], "sizing") || checkNodeType(expression[0], "styling");
6301
6302 if (!node) ; else if (node.type === "sizing") {
6303 glueOptions = options.havingSize(node.size);
6304 } else if (node.type === "styling") {
6305 glueOptions = options.havingStyle(styleMap[node.style]);
6306 }
6307 } // Dummy spans for determining spacings between surrounding atoms.
6308 // If `expression` has no atoms on the left or right, class "leftmost"
6309 // or "rightmost", respectively, is used to indicate it.
6310
6311
6312 const dummyPrev = makeSpan$1([surrounding[0] || "leftmost"], [], options);
6313 const dummyNext = makeSpan$1([surrounding[1] || "rightmost"], [], options); // TODO: These code assumes that a node's math class is the first element
6314 // of its `classes` array. A later cleanup should ensure this, for
6315 // instance by changing the signature of `makeSpan`.
6316 // Before determining what spaces to insert, perform bin cancellation.
6317 // Binary operators change to ordinary symbols in some contexts.
6318
6319 traverseNonSpaceNodes(groups, (node, prev) => {
6320 const prevType = prev.classes[0];
6321 const type = node.classes[0];
6322
6323 if (prevType === "mbin" && utils.contains(binRightCanceller, type)) {
6324 prev.classes[0] = "mord";
6325 } else if (type === "mbin" && utils.contains(binLeftCanceller, prevType)) {
6326 node.classes[0] = "mord";
6327 }
6328 }, {
6329 node: dummyPrev

Callers 7

buildHTMLFunction · 0.85
htmlBuilder$1Function · 0.85
katex.mjsFile · 0.85
htmlBuilder$4Function · 0.85
htmlBuilder$8Function · 0.85
htmlBuilderFunction · 0.85
sizingGroupFunction · 0.85

Calls 7

buildGroupFunction · 0.85
havingSizeMethod · 0.80
havingStyleMethod · 0.80
checkNodeTypeFunction · 0.70
traverseNonSpaceNodesFunction · 0.70
getTypeOfDomTreeFunction · 0.70
hasClassMethod · 0.45

Tested by

no test coverage detected