From 9a9842886e99df12e2ca6dd58ec1dd2a8a62ede5 Mon Sep 17 00:00:00 2001 From: ylemkimon Date: Mon, 13 Aug 2018 01:29:22 +0900 Subject: [PATCH] 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 --- .eslintrc | 2 +- LICENSE.txt => LICENSE | 8 +----- contrib/auto-render/auto-render.js | 45 +++++++++++++++--------------- 3 files changed, 24 insertions(+), 31 deletions(-) rename LICENSE.txt => LICENSE (81%) diff --git a/.eslintrc b/.eslintrc index 09b94bf7..ac6c841d 100644 --- a/.eslintrc +++ b/.eslintrc @@ -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]"] diff --git a/LICENSE.txt b/LICENSE similarity index 81% rename from LICENSE.txt rename to LICENSE index f7b2d38c..e2ae27da 100644 --- a/LICENSE.txt +++ b/LICENSE @@ -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 diff --git a/contrib/auto-render/auto-render.js b/contrib/auto-render/auto-render.js index e306b839..73061104 100644 --- a/contrib/auto-render/auto-render.js +++ b/contrib/auto-render/auto-render.js @@ -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); };