mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-06 19:58:40 +00:00
Add configurable error callback (#658)
Replace console.error with a configurable option. This mimcs the current default behaviour to guaranteee compatibility with previous versions. Update errorCallback to the README.md
This commit is contained in:
committed by
Kevin Barabash
parent
2da06d541e
commit
2eb32a8775
@@ -19,7 +19,6 @@ const splitWithDelimiters = function(text, delimiters) {
|
||||
*/
|
||||
const renderMathInText = function(text, optionsCopy) {
|
||||
const data = splitWithDelimiters(text, optionsCopy.delimiters);
|
||||
|
||||
const fragment = document.createDocumentFragment();
|
||||
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
@@ -37,7 +36,7 @@ const renderMathInText = function(text, optionsCopy) {
|
||||
if (!(e instanceof katex.ParseError)) {
|
||||
throw e;
|
||||
}
|
||||
console.error(
|
||||
optionsCopy.errorCallback(
|
||||
"KaTeX auto-render: Failed to parse `" + data[i].data +
|
||||
"` with ",
|
||||
e
|
||||
@@ -85,6 +84,10 @@ const defaultAutoRenderOptions = {
|
||||
ignoredTags: [
|
||||
"script", "noscript", "style", "textarea", "pre", "code",
|
||||
],
|
||||
|
||||
errorCallback: function(msg, err) {
|
||||
console.error(msg, err);
|
||||
},
|
||||
};
|
||||
|
||||
const renderMathInElement = function(elem, options) {
|
||||
@@ -93,7 +96,6 @@ const renderMathInElement = function(elem, options) {
|
||||
}
|
||||
|
||||
const optionsCopy = Object.assign({}, defaultAutoRenderOptions, options);
|
||||
|
||||
renderElem(elem, optionsCopy);
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user