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

Function buildHTML

static/katex/katex.mjs:6504–6584  ·  view source on GitHub ↗

* Take an entire parse tree, and build it into an appropriate set of HTML * nodes.

(tree, options)

Source from the content-addressed store, hash-verified

6502
6503
6504function buildHTML(tree, options) {
6505 // Strip off outer tag wrapper for processing below.
6506 let tag = null;
6507
6508 if (tree.length === 1 && tree[0].type === "tag") {
6509 tag = tree[0].tag;
6510 tree = tree[0].body;
6511 } // Build the expression contained in the tree
6512
6513
6514 const expression = buildExpression(tree, options, true);
6515 const children = []; // Create one base node for each chunk between potential line breaks.
6516 // The TeXBook [p.173] says "A formula will be broken only after a
6517 // relation symbol like $=$ or $<$ or $\rightarrow$, or after a binary
6518 // operation symbol like $+$ or $-$ or $\times$, where the relation or
6519 // binary operation is on the ``outer level'' of the formula (i.e., not
6520 // enclosed in {...} and not part of an \over construction)."
6521
6522 let parts = [];
6523
6524 for (let i = 0; i < expression.length; i++) {
6525 parts.push(expression[i]);
6526
6527 if (expression[i].hasClass("mbin") || expression[i].hasClass("mrel") || expression[i].hasClass("allowbreak")) {
6528 // Put any post-operator glue on same line as operator.
6529 // Watch for \nobreak along the way, and stop at \newline.
6530 let nobreak = false;
6531
6532 while (i < expression.length - 1 && expression[i + 1].hasClass("mspace") && !expression[i + 1].hasClass("newline")) {
6533 i++;
6534 parts.push(expression[i]);
6535
6536 if (expression[i].hasClass("nobreak")) {
6537 nobreak = true;
6538 }
6539 } // Don't allow break if \nobreak among the post-operator glue.
6540
6541
6542 if (!nobreak) {
6543 children.push(buildHTMLUnbreakable(parts, options));
6544 parts = [];
6545 }
6546 } else if (expression[i].hasClass("newline")) {
6547 // Write the line except the newline
6548 parts.pop();
6549
6550 if (parts.length > 0) {
6551 children.push(buildHTMLUnbreakable(parts, options));
6552 parts = [];
6553 } // Put the newline at the top level
6554
6555
6556 children.push(expression[i]);
6557 }
6558 }
6559
6560 if (parts.length > 0) {
6561 children.push(buildHTMLUnbreakable(parts, options));

Callers 2

buildTreeFunction · 0.70
buildHTMLTreeFunction · 0.70

Calls 4

buildExpressionFunction · 0.85
buildHTMLUnbreakableFunction · 0.70
hasClassMethod · 0.45
setAttributeMethod · 0.45

Tested by

no test coverage detected