mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-08 04:28:41 +00:00
Remove Object.assign() in auto-render which requires expensive polyfill, update LICENSE (#1591)
* Remove Object.assign() in auto-render which requires expensive polyfill * Remove underscore.js from LICENSE * Rename to LICENSE and update year * Lint `contrib` codes
This commit is contained in:
@@ -75,8 +75,22 @@ const renderElem = function(elem, optionsCopy) {
|
||||
}
|
||||
};
|
||||
|
||||
const defaultAutoRenderOptions = {
|
||||
delimiters: [
|
||||
const renderMathInElement = function(elem, options) {
|
||||
if (!elem) {
|
||||
throw new Error("No element provided to render");
|
||||
}
|
||||
|
||||
const optionsCopy = {};
|
||||
|
||||
// Object.assign(optionsCopy, option)
|
||||
for (const option in options) {
|
||||
if (options.hasOwnProperty(option)) {
|
||||
optionsCopy[option] = option;
|
||||
}
|
||||
}
|
||||
|
||||
// default options
|
||||
optionsCopy.delimiters = optionsCopy.delimiters || [
|
||||
{left: "$$", right: "$$", display: true},
|
||||
{left: "\\(", right: "\\)", display: false},
|
||||
// LaTeX uses $…$, but it ruins the display of normal `$` in text:
|
||||
@@ -87,31 +101,16 @@ const defaultAutoRenderOptions = {
|
||||
// That makes it susceptible to finding a \\[0.3em] row delimiter and
|
||||
// treating it as if it were the start of a KaTeX math zone.
|
||||
{left: "\\[", right: "\\]", display: true},
|
||||
],
|
||||
|
||||
ignoredTags: [
|
||||
];
|
||||
optionsCopy.ignoredTags = optionsCopy.ignoredTags || [
|
||||
"script", "noscript", "style", "textarea", "pre", "code",
|
||||
],
|
||||
|
||||
ignoredClasses: [],
|
||||
|
||||
errorCallback: function(msg, err) {
|
||||
console.error(msg, err);
|
||||
},
|
||||
};
|
||||
|
||||
const renderMathInElement = function(elem, options) {
|
||||
if (!elem) {
|
||||
throw new Error("No element provided to render");
|
||||
}
|
||||
|
||||
const optionsCopy = Object.assign({}, defaultAutoRenderOptions, options);
|
||||
];
|
||||
optionsCopy.ignoredClasses = optionsCopy.ignoredClasses || [];
|
||||
optionsCopy.errorCallback = optionsCopy.errorCallback || console.error;
|
||||
|
||||
// Enable sharing of global macros defined via `\gdef` between different
|
||||
// math elements within a single call to `renderMathInElement`.
|
||||
if (!optionsCopy.macros) {
|
||||
optionsCopy.macros = {};
|
||||
}
|
||||
optionsCopy.macros = optionsCopy.macros || {};
|
||||
|
||||
renderElem(elem, optionsCopy);
|
||||
};
|
||||
|
Reference in New Issue
Block a user