mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-06 19:58:40 +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:
@@ -71,7 +71,7 @@
|
|||||||
"require-jsdoc": 0
|
"require-jsdoc": 0
|
||||||
},
|
},
|
||||||
"overrides": [{
|
"overrides": [{
|
||||||
"files": ["katex.js", "src/**/*.js"],
|
"files": ["katex.js", "src/**/*.js", "contrib/**/*.js"],
|
||||||
"excludedFiles": "unicodeMake.js",
|
"excludedFiles": "unicodeMake.js",
|
||||||
"rules": {
|
"rules": {
|
||||||
"no-restricted-syntax": [2, "ForOfStatement", "ClassDeclaration[superClass]", "ClassExpression[superClass]"]
|
"no-restricted-syntax": [2, "ForOfStatement", "ClassDeclaration[superClass]", "ClassExpression[superClass]"]
|
||||||
|
@@ -1,12 +1,6 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2015 Khan Academy
|
Copyright (c) 2013-2018 Khan Academy
|
||||||
|
|
||||||
This software also uses portions of the underscore.js project, which is
|
|
||||||
MIT licensed with the following copyright:
|
|
||||||
|
|
||||||
Copyright (c) 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative
|
|
||||||
Reporters & Editors
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
@@ -75,8 +75,22 @@ const renderElem = function(elem, optionsCopy) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const defaultAutoRenderOptions = {
|
const renderMathInElement = function(elem, options) {
|
||||||
delimiters: [
|
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: true},
|
||||||
{left: "\\(", right: "\\)", display: false},
|
{left: "\\(", right: "\\)", display: false},
|
||||||
// LaTeX uses $…$, but it ruins the display of normal `$` in text:
|
// 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
|
// 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.
|
// treating it as if it were the start of a KaTeX math zone.
|
||||||
{left: "\\[", right: "\\]", display: true},
|
{left: "\\[", right: "\\]", display: true},
|
||||||
],
|
];
|
||||||
|
optionsCopy.ignoredTags = optionsCopy.ignoredTags || [
|
||||||
ignoredTags: [
|
|
||||||
"script", "noscript", "style", "textarea", "pre", "code",
|
"script", "noscript", "style", "textarea", "pre", "code",
|
||||||
],
|
];
|
||||||
|
optionsCopy.ignoredClasses = optionsCopy.ignoredClasses || [];
|
||||||
ignoredClasses: [],
|
optionsCopy.errorCallback = optionsCopy.errorCallback || console.error;
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
// Enable sharing of global macros defined via `\gdef` between different
|
// Enable sharing of global macros defined via `\gdef` between different
|
||||||
// math elements within a single call to `renderMathInElement`.
|
// math elements within a single call to `renderMathInElement`.
|
||||||
if (!optionsCopy.macros) {
|
optionsCopy.macros = optionsCopy.macros || {};
|
||||||
optionsCopy.macros = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
renderElem(elem, optionsCopy);
|
renderElem(elem, optionsCopy);
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user