mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-09 04:58:40 +00:00
Support MathML display mode (#2220)
This commit is contained in:
@@ -238,6 +238,7 @@ export default function buildMathML(
|
|||||||
tree: AnyParseNode[],
|
tree: AnyParseNode[],
|
||||||
texExpression: string,
|
texExpression: string,
|
||||||
options: Options,
|
options: Options,
|
||||||
|
isDisplayMode: boolean,
|
||||||
forMathmlOnly: boolean,
|
forMathmlOnly: boolean,
|
||||||
): DomSpan {
|
): DomSpan {
|
||||||
const expression = buildExpression(tree, options);
|
const expression = buildExpression(tree, options);
|
||||||
@@ -263,6 +264,9 @@ export default function buildMathML(
|
|||||||
|
|
||||||
const math = new mathMLTree.MathNode("math", [semantics]);
|
const math = new mathMLTree.MathNode("math", [semantics]);
|
||||||
math.setAttribute("xmlns", "http://www.w3.org/1998/Math/MathML");
|
math.setAttribute("xmlns", "http://www.w3.org/1998/Math/MathML");
|
||||||
|
if (isDisplayMode) {
|
||||||
|
math.setAttribute("display", "block");
|
||||||
|
}
|
||||||
|
|
||||||
// You can't style <math> nodes, so we wrap the node in a span.
|
// You can't style <math> nodes, so we wrap the node in a span.
|
||||||
// NOTE: The span class is not typed to have <math> nodes as children, and
|
// NOTE: The span class is not typed to have <math> nodes as children, and
|
||||||
|
@@ -39,12 +39,13 @@ export const buildTree = function(
|
|||||||
const options = optionsFromSettings(settings);
|
const options = optionsFromSettings(settings);
|
||||||
let katexNode;
|
let katexNode;
|
||||||
if (settings.output === "mathml") {
|
if (settings.output === "mathml") {
|
||||||
return buildMathML(tree, expression, options, true);
|
return buildMathML(tree, expression, options, settings.displayMode, true);
|
||||||
} else if (settings.output === "html") {
|
} else if (settings.output === "html") {
|
||||||
const htmlNode = buildHTML(tree, options);
|
const htmlNode = buildHTML(tree, options);
|
||||||
katexNode = buildCommon.makeSpan(["katex"], [htmlNode]);
|
katexNode = buildCommon.makeSpan(["katex"], [htmlNode]);
|
||||||
} else {
|
} else {
|
||||||
const mathMLNode = buildMathML(tree, expression, options, false);
|
const mathMLNode = buildMathML(tree, expression, options,
|
||||||
|
settings.displayMode, false);
|
||||||
const htmlNode = buildHTML(tree, options);
|
const htmlNode = buildHTML(tree, options);
|
||||||
katexNode = buildCommon.makeSpan(["katex"], [mathMLNode, htmlNode]);
|
katexNode = buildCommon.makeSpan(["katex"], [mathMLNode, htmlNode]);
|
||||||
}
|
}
|
||||||
|
@@ -359,7 +359,9 @@ exports[`A MathML builder should output \\limsup_{x \\rightarrow \\infty} correc
|
|||||||
|
|
||||||
exports[`A MathML builder should output \\limsup_{x \\rightarrow \\infty} in displaymode correctly 1`] = `
|
exports[`A MathML builder should output \\limsup_{x \\rightarrow \\infty} in displaymode correctly 1`] = `
|
||||||
|
|
||||||
<math xmlns="http://www.w3.org/1998/Math/MathML">
|
<math xmlns="http://www.w3.org/1998/Math/MathML"
|
||||||
|
display="block"
|
||||||
|
>
|
||||||
<semantics>
|
<semantics>
|
||||||
<mrow>
|
<mrow>
|
||||||
<munder>
|
<munder>
|
||||||
@@ -766,7 +768,9 @@ exports[`A MathML builder special spaces render specially 1`] = `
|
|||||||
|
|
||||||
exports[`A MathML builder tags use <mlabeledtr> 1`] = `
|
exports[`A MathML builder tags use <mlabeledtr> 1`] = `
|
||||||
|
|
||||||
<math xmlns="http://www.w3.org/1998/Math/MathML">
|
<math xmlns="http://www.w3.org/1998/Math/MathML"
|
||||||
|
display="block"
|
||||||
|
>
|
||||||
<semantics>
|
<semantics>
|
||||||
<mtable width="100%">
|
<mtable width="100%">
|
||||||
<mtr>
|
<mtr>
|
||||||
|
@@ -20,7 +20,8 @@ const getMathML = function(expr, settings = new Settings()) {
|
|||||||
maxSize: Infinity,
|
maxSize: Infinity,
|
||||||
});
|
});
|
||||||
|
|
||||||
const built = buildMathML(parseTree(expr, settings), expr, options);
|
const built = buildMathML(parseTree(expr, settings), expr, options,
|
||||||
|
settings.displayMode);
|
||||||
|
|
||||||
// Strip off the surrounding <span>
|
// Strip off the surrounding <span>
|
||||||
return built.children[0].toMarkup();
|
return built.children[0].toMarkup();
|
||||||
|
Reference in New Issue
Block a user