mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-11 05:58:40 +00:00
Add buildHTMLTree
This commit is contained in:
@@ -9,24 +9,19 @@ import Style from "./Style";
|
||||
import type ParseNode from "./ParseNode";
|
||||
import type domTree from "./domTree";
|
||||
|
||||
const buildTree = function(
|
||||
const optionsFromSettings = function(settings: Settings) {
|
||||
return new Options({
|
||||
style: (settings.displayMode ? Style.DISPLAY : Style.TEXT),
|
||||
maxSize: settings.maxSize,
|
||||
});
|
||||
};
|
||||
|
||||
export const buildTree = function(
|
||||
tree: ParseNode[],
|
||||
expression: string,
|
||||
settings: Settings,
|
||||
): domTree.span {
|
||||
settings = settings || new Settings({});
|
||||
|
||||
let startStyle = Style.TEXT;
|
||||
if (settings.displayMode) {
|
||||
startStyle = Style.DISPLAY;
|
||||
}
|
||||
|
||||
// Setup the default options
|
||||
const options = new Options({
|
||||
style: startStyle,
|
||||
maxSize: settings.maxSize,
|
||||
});
|
||||
|
||||
const options = optionsFromSettings(settings);
|
||||
// `buildHTML` sometimes messes with the parse tree (like turning bins ->
|
||||
// ords), so we build the MathML version first.
|
||||
const mathMLNode = buildMathML(tree, expression, options);
|
||||
@@ -43,4 +38,19 @@ const buildTree = function(
|
||||
}
|
||||
};
|
||||
|
||||
export const buildHTMLTree = function(
|
||||
tree: ParseNode[],
|
||||
expression: string,
|
||||
settings: Settings,
|
||||
): domTree.span {
|
||||
const options = optionsFromSettings(settings);
|
||||
const htmlNode = buildHTML(tree, options);
|
||||
const katexNode = buildCommon.makeSpan(["katex"], [htmlNode]);
|
||||
if (settings.displayMode) {
|
||||
return buildCommon.makeSpan(["katex-display"], [katexNode]);
|
||||
} else {
|
||||
return katexNode;
|
||||
}
|
||||
};
|
||||
|
||||
export default buildTree;
|
||||
|
Reference in New Issue
Block a user