mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-06 11:48:41 +00:00
Remove tree cloning before building HTML (#1470)
* Reset `supSub.value.base` after building `supSubGroup` * Remove tree cloning before building HTML `buildExpression` is no longer destructive, added comment regarding it,
This commit is contained in:
@@ -318,10 +318,6 @@ function buildHTMLUnbreakable(children, options) {
|
||||
* nodes.
|
||||
*/
|
||||
export default function buildHTML(tree: AnyParseNode[], options: Options): DomSpan {
|
||||
// buildExpression is destructive, so we need to make a clone
|
||||
// of the incoming tree so that it isn't accidentally changed
|
||||
tree = JSON.parse(JSON.stringify(tree));
|
||||
|
||||
// Strip off outer tag wrapper for processing below.
|
||||
let tag = null;
|
||||
if (tree.length === 1 && tree[0].type === "tag") {
|
||||
|
@@ -22,8 +22,6 @@ export const buildTree = function(
|
||||
settings: Settings,
|
||||
): DomSpan {
|
||||
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);
|
||||
const htmlNode = buildHTML(tree, options);
|
||||
|
||||
|
@@ -116,12 +116,14 @@ type FunctionDefSpec<NODETYPE: NodeType> = {|
|
||||
|
||||
// This function returns an object representing the DOM structure to be
|
||||
// created when rendering the defined LaTeX function.
|
||||
// This should not modify the `ParseNode`.
|
||||
htmlBuilder?: HtmlBuilder<NODETYPE>,
|
||||
|
||||
// TODO: Currently functions/op.js returns documentFragment. Refactor it
|
||||
// and update the return type of this function.
|
||||
// This function returns an object representing the MathML structure to be
|
||||
// created when rendering the defined LaTeX function.
|
||||
// This should not modify the `ParseNode`.
|
||||
mathmlBuilder?: MathMLBuilder<NODETYPE>,
|
||||
|};
|
||||
|
||||
|
@@ -41,6 +41,9 @@ export const htmlBuilder: HtmlBuilderSupSub<"accent"> = (grp, options) => {
|
||||
// Rerender the supsub group with its new base, and store that
|
||||
// result.
|
||||
supSubGroup = assertDomContainer(html.buildGroup(supSub, options));
|
||||
|
||||
// reset original base
|
||||
supSub.value.base = group;
|
||||
} else {
|
||||
group = assertNodeType(grp, "accent");
|
||||
base = group.value.base;
|
||||
|
Reference in New Issue
Block a user