Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
{},
{
displayMode: !!props.block,
errorColor: props.errorColor,
throwOnError: !!props.renderError
},
// you can rewrite all KaTeX options directly
props.settings
)
);
return (
);
} catch (error) {
if (error instanceof KaTeX.ParseError || error instanceof TypeError) {
return props.renderError ? (
props.renderError(error)
) : (
);
}
throw error;
}
}
for (let i = 0; i < data.length; i++) {
if (data[i].type === "text") {
fragment.appendChild(document.createTextNode(data[i].data));
} else {
const span = document.createElement("span");
let math = data[i].data;
// Override any display mode defined in the settings with that
// defined by the text itself
optionsCopy.displayMode = data[i].display;
try {
if (optionsCopy.preProcess) {
math = optionsCopy.preProcess(math);
}
katex.render(math, span, optionsCopy);
} catch (e) {
if (!(e instanceof katex.ParseError)) {
throw e;
}
optionsCopy.errorCallback(
"KaTeX auto-render: Failed to parse `" + data[i].data +
"` with ",
e
);
fragment.appendChild(document.createTextNode(data[i].rawData));
continue;
}
fragment.appendChild(span);
}
}
return fragment;
};
static getDerivedStateFromProps(
props: MathComponentProps
): Partial {
try {
const { errorColor, renderError } = props
const html = KaTeX.renderToString(props.math, {
displayMode,
errorColor,
throwOnError: !!renderError
})
return { html, error: undefined }
} catch (error) {
if (error instanceof KaTeX.ParseError || error instanceof TypeError) {
return { error }
}
throw error
}
}
}