mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-05 19:28:39 +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
|
||||
},
|
||||
"overrides": [{
|
||||
"files": ["katex.js", "src/**/*.js"],
|
||||
"files": ["katex.js", "src/**/*.js", "contrib/**/*.js"],
|
||||
"excludedFiles": "unicodeMake.js",
|
||||
"rules": {
|
||||
"no-restricted-syntax": [2, "ForOfStatement", "ClassDeclaration[superClass]", "ClassExpression[superClass]"]
|
||||
|
@@ -1,12 +1,6 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 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
|
||||
Copyright (c) 2013-2018 Khan Academy
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
@@ -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