mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-05 03:08: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
@@ -83,8 +83,11 @@ in addition to two auto-render-specific keys:
|
||||
|
||||
- `ignoredTags`: This is a list of DOM node types to ignore when recursing
|
||||
through. The default value is
|
||||
`["script", "noscript", "style", "textarea", "pre", "code"]`.
|
||||
`["script", "noscript", "style", "textarea", "pre", "code"]`.
|
||||
|
||||
- `errorCallback`: A callback method returning a message and an error stack
|
||||
in case of an critical error during rendering. The default uses `console.error`.
|
||||
|
||||
Note that the `displayMode` property of the options object is ignored, and is
|
||||
instead taken from the `display` key of the corresponding entry in the
|
||||
`delimiters` key.
|
||||
`delimiters` key.
|
@@ -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