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:
ylemkimon
2018-08-13 01:29:22 +09:00
committed by GitHub
parent 51bf3fa6f5
commit 9a9842886e
3 changed files with 24 additions and 31 deletions

View File

@@ -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]"]

View File

@@ -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

View File

@@ -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);
};