* Takes a full parse tree and settings and builds a MathML representation of * it. In particular, we put the elements from building the parse tree into a * tag so we can also include that TeX source as an annotation. * * Note that we actually return a domTree element with a ` `
(tree, texExpression, options)
| 7049 | */ |
| 7050 | |
| 7051 | function buildMathML(tree, texExpression, options) { |
| 7052 | var expression = buildMathML_buildExpression(tree, options); // Wrap up the expression in an mrow so it is presented in the semantics |
| 7053 | // tag correctly, unless it's a single <mrow> or <mtable>. |
| 7054 | |
| 7055 | var wrapper; |
| 7056 | |
| 7057 | if (expression.length === 1 && expression[0] instanceof mathMLTree_MathNode && utils.contains(["mrow", "mtable"], expression[0].type)) { |
| 7058 | wrapper = expression[0]; |
| 7059 | } else { |
| 7060 | wrapper = new mathMLTree.MathNode("mrow", expression); |
| 7061 | } // Build a TeX annotation of the source |
| 7062 | |
| 7063 | |
| 7064 | var annotation = new mathMLTree.MathNode("annotation", [new mathMLTree.TextNode(texExpression)]); |
| 7065 | annotation.setAttribute("encoding", "application/x-tex"); |
| 7066 | var semantics = new mathMLTree.MathNode("semantics", [wrapper, annotation]); |
| 7067 | var math = new mathMLTree.MathNode("math", [semantics]); // You can't style <math> nodes, so we wrap the node in a span. |
| 7068 | // NOTE: The span class is not typed to have <math> nodes as children, and |
| 7069 | // we don't want to make the children type more generic since the children |
| 7070 | // of span are expected to have more fields in `buildHtml` contexts. |
| 7071 | // $FlowFixMe |
| 7072 | |
| 7073 | return buildCommon.makeSpan(["katex-mathml"], [math]); |
| 7074 | } |
| 7075 | // CONCATENATED MODULE: ./src/buildTree.js |
| 7076 | |
| 7077 |
no test coverage detected