mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Use same config for editor and reviewer Mathjax (#1865)
* Remove custom config and use tex-chtml-full for editor Mathjax * Add mathjax package in /ts * Share mathjax config between tex-svg and tex-chtml * Use "[+]" in Mathjax config again * Remove mention of MathJaxReady * Satisfy eslint
This commit is contained in:
parent
f22d8015a6
commit
3b8aa97396
15 changed files with 94 additions and 142 deletions
|
@ -76,7 +76,6 @@
|
|||
"lodash-es": "^4.17.21",
|
||||
"marked": "^4.0.0",
|
||||
"mathjax": "^3.1.2",
|
||||
"mathjax-full": "^3.2.0",
|
||||
"protobufjs": "^6.10.2"
|
||||
},
|
||||
"resolutions": {
|
||||
|
|
|
@ -41,13 +41,21 @@ copy_files_into_group(
|
|||
package = "//ts/reviewer",
|
||||
)
|
||||
|
||||
copy_files_into_group(
|
||||
name = "mathjax",
|
||||
srcs = [
|
||||
"mathjax.js",
|
||||
],
|
||||
package = "//ts/mathjax",
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "js",
|
||||
srcs = [
|
||||
"aqt",
|
||||
"mathjax.js",
|
||||
"reviewer",
|
||||
"editor",
|
||||
"mathjax",
|
||||
"//qt/aqt/data/web/js/vendor",
|
||||
],
|
||||
visibility = ["//qt:__subpackages__"],
|
||||
|
@ -68,6 +76,5 @@ eslint_test(
|
|||
)
|
||||
|
||||
exports_files([
|
||||
"mathjax.js",
|
||||
"tsconfig.json",
|
||||
])
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
window.MathJax = {
|
||||
tex: {
|
||||
displayMath: [["\\[", "\\]"]],
|
||||
processRefs: false,
|
||||
processEnvironments: false,
|
||||
processEscapes: false,
|
||||
packages: {
|
||||
"[+]": ["noerrors", "mhchem"],
|
||||
},
|
||||
},
|
||||
startup: {
|
||||
typeset: false,
|
||||
pageReady: () => {
|
||||
return MathJax.startup.defaultPageReady();
|
||||
},
|
||||
},
|
||||
options: {
|
||||
renderActions: {
|
||||
addMenu: [],
|
||||
checkLoading: [],
|
||||
},
|
||||
ignoreHtmlClass: "tex2jax_ignore",
|
||||
processHtmlClass: "tex2jax_process",
|
||||
},
|
||||
loader: {
|
||||
load: ["[tex]/noerrors", "[tex]/mhchem"],
|
||||
},
|
||||
};
|
|
@ -155,7 +155,10 @@ class Editor:
|
|||
self.web.stdHtml(
|
||||
"",
|
||||
css=[f"css/{file}.css"],
|
||||
js=[f"js/{file}.js"],
|
||||
js=[
|
||||
"js/mathjax.js",
|
||||
f"js/{file}.js",
|
||||
],
|
||||
context=self,
|
||||
default_css=False,
|
||||
)
|
||||
|
|
|
@ -21,8 +21,8 @@ _ts_deps = [
|
|||
"//ts/lib",
|
||||
"//ts/domlib",
|
||||
"//ts/sveltelib",
|
||||
"//ts/mathjax:mathjax_ts",
|
||||
"@npm//mathjax",
|
||||
"@npm//mathjax-full",
|
||||
"@npm//svelte",
|
||||
]
|
||||
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
// Copyright: Ankitects Pty Ltd and contributors
|
||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
|
||||
import "mathjax/es5/tex-svg-full";
|
||||
|
||||
import { placeCaretAfter, placeCaretBefore } from "../domlib/place-caret";
|
||||
import { on } from "../lib/events";
|
||||
import type { DecoratedElement, DecoratedElementConstructor } from "./decorated";
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
@typescript-eslint/no-explicit-any: "off",
|
||||
*/
|
||||
|
||||
import "mathjax/es5/tex-svg";
|
||||
|
||||
import { mathIcon } from "./icons";
|
||||
|
||||
const parser = new DOMParser();
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
{ "path": "../components" },
|
||||
{ "path": "../lib" },
|
||||
{ "path": "../domlib" },
|
||||
{ "path": "../sveltelib" }
|
||||
{ "path": "../sveltelib" },
|
||||
{ "path": "../mathjax" }
|
||||
]
|
||||
}
|
||||
|
|
|
@ -410,14 +410,6 @@
|
|||
"path": "node_modules/commander",
|
||||
"licenseFile": "node_modules/commander/LICENSE"
|
||||
},
|
||||
"commander@9.1.0": {
|
||||
"licenses": "MIT",
|
||||
"repository": "https://github.com/tj/commander.js",
|
||||
"publisher": "TJ Holowaychuk",
|
||||
"email": "tj@vision-media.ca",
|
||||
"path": "node_modules/speech-rule-engine/node_modules/commander",
|
||||
"licenseFile": "node_modules/speech-rule-engine/node_modules/commander/LICENSE"
|
||||
},
|
||||
"concat-map@0.0.1": {
|
||||
"licenses": "MIT",
|
||||
"repository": "https://github.com/substack/node-concat-map",
|
||||
|
@ -875,14 +867,6 @@
|
|||
"path": "node_modules/eslint",
|
||||
"licenseFile": "node_modules/eslint/LICENSE"
|
||||
},
|
||||
"esm@3.2.25": {
|
||||
"licenses": "MIT",
|
||||
"repository": "https://github.com/standard-things/esm",
|
||||
"publisher": "John-David Dalton",
|
||||
"email": "john.david.dalton@gmail.com",
|
||||
"path": "node_modules/esm",
|
||||
"licenseFile": "node_modules/esm/LICENSE"
|
||||
},
|
||||
"espree@7.3.1": {
|
||||
"licenses": "BSD-2-Clause",
|
||||
"repository": "https://github.com/eslint/espree",
|
||||
|
@ -1437,25 +1421,12 @@
|
|||
"path": "node_modules/marked",
|
||||
"licenseFile": "node_modules/marked/LICENSE.md"
|
||||
},
|
||||
"mathjax-full@3.2.0": {
|
||||
"licenses": "Apache-2.0",
|
||||
"repository": "https://github.com/mathjax/Mathjax-src",
|
||||
"path": "node_modules/mathjax-full",
|
||||
"licenseFile": "node_modules/mathjax-full/LICENSE"
|
||||
},
|
||||
"mathjax@3.2.0": {
|
||||
"licenses": "Apache-2.0",
|
||||
"repository": "https://github.com/mathjax/MathJax",
|
||||
"path": "node_modules/mathjax",
|
||||
"licenseFile": "node_modules/mathjax/LICENSE"
|
||||
},
|
||||
"mhchemparser@4.1.1": {
|
||||
"licenses": "Apache-2.0",
|
||||
"repository": "https://github.com/mhchem/mhchemParser",
|
||||
"publisher": "Martin Hensel",
|
||||
"path": "node_modules/mhchemparser",
|
||||
"licenseFile": "node_modules/mhchemparser/LICENSE.txt"
|
||||
},
|
||||
"minimatch@3.1.2": {
|
||||
"licenses": "ISC",
|
||||
"repository": "https://github.com/isaacs/minimatch",
|
||||
|
@ -1474,12 +1445,6 @@
|
|||
"path": "node_modules/minimist",
|
||||
"licenseFile": "node_modules/minimist/LICENSE"
|
||||
},
|
||||
"mj-context-menu@0.6.1": {
|
||||
"licenses": "Apache-2.0",
|
||||
"repository": "https://github.com/zorkow/context-menu",
|
||||
"path": "node_modules/mj-context-menu",
|
||||
"licenseFile": "node_modules/mj-context-menu/README.md"
|
||||
},
|
||||
"ms@2.0.0": {
|
||||
"licenses": "MIT",
|
||||
"repository": "https://github.com/zeit/ms",
|
||||
|
@ -1765,12 +1730,6 @@
|
|||
"path": "node_modules/slice-ansi",
|
||||
"licenseFile": "node_modules/slice-ansi/license"
|
||||
},
|
||||
"speech-rule-engine@3.3.3": {
|
||||
"licenses": "Apache-2.0",
|
||||
"repository": "https://github.com/zorkow/speech-rule-engine",
|
||||
"path": "node_modules/speech-rule-engine",
|
||||
"licenseFile": "node_modules/speech-rule-engine/LICENSE"
|
||||
},
|
||||
"sprintf-js@1.0.3": {
|
||||
"licenses": "BSD-3-Clause",
|
||||
"repository": "https://github.com/alexei/sprintf.js",
|
||||
|
@ -1948,13 +1907,6 @@
|
|||
"path": "node_modules/which",
|
||||
"licenseFile": "node_modules/which/LICENSE"
|
||||
},
|
||||
"wicked-good-xpath@1.3.0": {
|
||||
"licenses": "MIT",
|
||||
"repository": "https://github.com/google/wicked-good-xpath",
|
||||
"publisher": "Google Inc.",
|
||||
"path": "node_modules/wicked-good-xpath",
|
||||
"licenseFile": "node_modules/wicked-good-xpath/LICENSE"
|
||||
},
|
||||
"word-wrap@1.2.3": {
|
||||
"licenses": "MIT",
|
||||
"repository": "https://github.com/jonschlinkert/word-wrap",
|
||||
|
@ -1972,15 +1924,6 @@
|
|||
"path": "node_modules/wrappy",
|
||||
"licenseFile": "node_modules/wrappy/LICENSE"
|
||||
},
|
||||
"xmldom-sre@0.1.31": {
|
||||
"licenses": "MIT*",
|
||||
"repository": "https://github.com/zorkow/xmldom",
|
||||
"publisher": "jindw",
|
||||
"email": "jindw@xidea.org",
|
||||
"url": "http://www.xidea.org",
|
||||
"path": "node_modules/xmldom-sre",
|
||||
"licenseFile": "node_modules/xmldom-sre/LICENSE"
|
||||
},
|
||||
"yallist@4.0.0": {
|
||||
"licenses": "ISC",
|
||||
"repository": "https://github.com/isaacs/yallist",
|
||||
|
|
24
ts/mathjax/BUILD.bazel
Normal file
24
ts/mathjax/BUILD.bazel
Normal file
|
@ -0,0 +1,24 @@
|
|||
load("//ts:prettier.bzl", "prettier_test")
|
||||
load("//ts:eslint.bzl", "eslint_test")
|
||||
load("//ts:esbuild.bzl", "esbuild")
|
||||
load("//ts:typescript.bzl", "typescript")
|
||||
|
||||
typescript(name = "mathjax_ts")
|
||||
|
||||
_esbuild_deps = [
|
||||
":mathjax_ts",
|
||||
]
|
||||
|
||||
esbuild(
|
||||
name = "mathjax",
|
||||
entry_point = "index.ts",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = _esbuild_deps,
|
||||
)
|
||||
|
||||
# Tests
|
||||
################
|
||||
|
||||
prettier_test()
|
||||
|
||||
eslint_test()
|
31
ts/mathjax/index.ts
Normal file
31
ts/mathjax/index.ts
Normal file
|
@ -0,0 +1,31 @@
|
|||
// Copyright: Ankitects Pty Ltd and contributors
|
||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
|
||||
/// <reference types="./mathjax-types" />
|
||||
|
||||
const packages = ["noerrors", "mathtools", "mhchem"];
|
||||
|
||||
function packagesForLoading(packages: string[]): string[] {
|
||||
return packages.map((value: string): string => `[tex]/${value}`);
|
||||
}
|
||||
|
||||
window.MathJax = {
|
||||
tex: {
|
||||
displayMath: [["\\[", "\\]"]],
|
||||
processEscapes: false,
|
||||
processEnvironments: false,
|
||||
processRefs: false,
|
||||
packages: {
|
||||
"[+]": packages,
|
||||
},
|
||||
},
|
||||
loader: {
|
||||
load: packagesForLoading(packages),
|
||||
paths: {
|
||||
mathjax: "/_anki/js/vendor/mathjax",
|
||||
},
|
||||
},
|
||||
startup: {
|
||||
typeset: false,
|
||||
},
|
||||
};
|
15
ts/mathjax/mathjax-types.d.ts
vendored
Normal file
15
ts/mathjax/mathjax-types.d.ts
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
// Copyright: Ankitects Pty Ltd and contributors
|
||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
|
||||
/* eslint
|
||||
@typescript-eslint/no-explicit-any: "off",
|
||||
*/
|
||||
|
||||
export {};
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
// Mathjax does not provide a full type
|
||||
MathJax: { [name: string]: any };
|
||||
}
|
||||
}
|
5
ts/mathjax/tsconfig.json
Normal file
5
ts/mathjax/tsconfig.json
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"extends": "../tsconfig.json",
|
||||
"include": ["*"],
|
||||
"references": []
|
||||
}
|
|
@ -11,6 +11,7 @@
|
|||
{ "path": "html-filter" },
|
||||
{ "path": "reviewer" },
|
||||
{ "path": "lib" },
|
||||
{ "path": "mathjax" },
|
||||
{ "path": "domlib" },
|
||||
{ "path": "sveltelib" },
|
||||
{ "path": "icons" }
|
||||
|
|
49
yarn.lock
49
yarn.lock
|
@ -1699,11 +1699,6 @@ commander@7:
|
|||
resolved "https://registry.yarnpkg.com/commander/-/commander-7.2.0.tgz#a36cb57d0b501ce108e4d20559a150a391d97ab7"
|
||||
integrity sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw==
|
||||
|
||||
commander@>=7.0.0:
|
||||
version "9.1.0"
|
||||
resolved "https://registry.yarnpkg.com/commander/-/commander-9.1.0.tgz#a6b263b2327f2e188c6402c42623327909f2dbec"
|
||||
integrity sha512-i0/MaqBtdbnJ4XQs4Pmyb+oFQl+q0lsAmokVUH92SlSw4fkeAcG3bVon+Qt7hmtF+u3Het6o4VgrcY3qAoEB6w==
|
||||
|
||||
concat-map@0.0.1:
|
||||
version "0.0.1"
|
||||
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
|
||||
|
@ -2402,11 +2397,6 @@ eslint@^7.24.0:
|
|||
text-table "^0.2.0"
|
||||
v8-compile-cache "^2.0.3"
|
||||
|
||||
esm@^3.2.25:
|
||||
version "3.2.25"
|
||||
resolved "https://registry.yarnpkg.com/esm/-/esm-3.2.25.tgz#342c18c29d56157688ba5ce31f8431fbb795cc10"
|
||||
integrity sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA==
|
||||
|
||||
espree@^7.3.0, espree@^7.3.1:
|
||||
version "7.3.1"
|
||||
resolved "https://registry.yarnpkg.com/espree/-/espree-7.3.1.tgz#f2df330b752c6f55019f8bd89b7660039c1bbbb6"
|
||||
|
@ -3743,16 +3733,6 @@ marked@^4.0.0, marked@^4.0.10:
|
|||
resolved "https://registry.yarnpkg.com/marked/-/marked-4.0.12.tgz#2262a4e6fd1afd2f13557726238b69a48b982f7d"
|
||||
integrity sha512-hgibXWrEDNBWgGiK18j/4lkS6ihTe9sxtV4Q1OQppb/0zzyPSzoFANBa5MfsG/zgsWklmNnhm0XACZOH/0HBiQ==
|
||||
|
||||
mathjax-full@^3.2.0:
|
||||
version "3.2.0"
|
||||
resolved "https://registry.yarnpkg.com/mathjax-full/-/mathjax-full-3.2.0.tgz#e53269842a943d4df10502937518991268996c5c"
|
||||
integrity sha512-D2EBNvUG+mJyhn+M1C858k0f2Fc4KxXvbEX2WCMXroV10212JwfYqaBJ336ECBSz5X9L5LRoamxb7AJtg3KaJA==
|
||||
dependencies:
|
||||
esm "^3.2.25"
|
||||
mhchemparser "^4.1.0"
|
||||
mj-context-menu "^0.6.1"
|
||||
speech-rule-engine "^3.3.3"
|
||||
|
||||
mathjax@^3.1.2:
|
||||
version "3.2.0"
|
||||
resolved "https://registry.yarnpkg.com/mathjax/-/mathjax-3.2.0.tgz#ea7c317f8c81776ecfc83b294fc313046bf7f726"
|
||||
|
@ -3773,11 +3753,6 @@ merge2@^1.3.0, merge2@^1.4.1:
|
|||
resolved "https://registry.yarnpkg.com/merge2/-/merge2-1.4.1.tgz#4368892f885e907455a6fd7dc55c0c9d404990ae"
|
||||
integrity sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==
|
||||
|
||||
mhchemparser@^4.1.0:
|
||||
version "4.1.1"
|
||||
resolved "https://registry.yarnpkg.com/mhchemparser/-/mhchemparser-4.1.1.tgz#a2142fdab37a02ec8d1b48a445059287790becd5"
|
||||
integrity sha512-R75CUN6O6e1t8bgailrF1qPq+HhVeFTM3XQ0uzI+mXTybmphy3b6h4NbLOYhemViQ3lUs+6CKRkC3Ws1TlYREA==
|
||||
|
||||
micromatch@^4.0.2, micromatch@^4.0.4:
|
||||
version "4.0.4"
|
||||
resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-4.0.4.tgz#896d519dfe9db25fce94ceb7a500919bf881ebf9"
|
||||
|
@ -3820,11 +3795,6 @@ minimist@^1.2.0, minimist@^1.2.5, minimist@^1.2.6:
|
|||
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.6.tgz#8637a5b759ea0d6e98702cfb3a9283323c93af44"
|
||||
integrity sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==
|
||||
|
||||
mj-context-menu@^0.6.1:
|
||||
version "0.6.1"
|
||||
resolved "https://registry.yarnpkg.com/mj-context-menu/-/mj-context-menu-0.6.1.tgz#a043c5282bf7e1cf3821de07b13525ca6f85aa69"
|
||||
integrity sha512-7NO5s6n10TIV96d4g2uDpG7ZDpIhMh0QNfGdJw/W47JswFcosz457wqz/b5sAKvl12sxINGFCn80NZHKwxQEXA==
|
||||
|
||||
mkdirp@^0.5.1:
|
||||
version "0.5.6"
|
||||
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.6.tgz#7def03d2432dcae4ba1d611445c48396062255f6"
|
||||
|
@ -4626,15 +4596,6 @@ spdx-satisfies@^5.0.1:
|
|||
spdx-expression-parse "^3.0.0"
|
||||
spdx-ranges "^2.0.0"
|
||||
|
||||
speech-rule-engine@^3.3.3:
|
||||
version "3.3.3"
|
||||
resolved "https://registry.yarnpkg.com/speech-rule-engine/-/speech-rule-engine-3.3.3.tgz#781ed03cbcf3279f94d1d80241025ea954c6d571"
|
||||
integrity sha512-0exWw+0XauLjat+f/aFeo5T8SiDsO1JtwpY3qgJE4cWt+yL/Stl0WP4VNDWdh7lzGkubUD9lWP4J1ASnORXfyQ==
|
||||
dependencies:
|
||||
commander ">=7.0.0"
|
||||
wicked-good-xpath "^1.3.0"
|
||||
xmldom-sre "^0.1.31"
|
||||
|
||||
sprintf-js@~1.0.2:
|
||||
version "1.0.3"
|
||||
resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c"
|
||||
|
@ -5084,11 +5045,6 @@ which@^2.0.1:
|
|||
dependencies:
|
||||
isexe "^2.0.0"
|
||||
|
||||
wicked-good-xpath@^1.3.0:
|
||||
version "1.3.0"
|
||||
resolved "https://registry.yarnpkg.com/wicked-good-xpath/-/wicked-good-xpath-1.3.0.tgz#81b0e95e8650e49c94b22298fff8686b5553cf6c"
|
||||
integrity sha1-gbDpXoZQ5JyUsiKY//hoa1VTz2w=
|
||||
|
||||
word-wrap@^1.2.3, word-wrap@~1.2.3:
|
||||
version "1.2.3"
|
||||
resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.3.tgz#610636f6b1f703891bd34771ccb17fb93b47079c"
|
||||
|
@ -5136,11 +5092,6 @@ xmlcreate@^2.0.4:
|
|||
resolved "https://registry.yarnpkg.com/xmlcreate/-/xmlcreate-2.0.4.tgz#0c5ab0f99cdd02a81065fa9cd8f8ae87624889be"
|
||||
integrity sha512-nquOebG4sngPmGPICTS5EnxqhKbCmz5Ox5hsszI2T6U5qdrJizBc+0ilYSEjTSzU0yZcmvppztXe/5Al5fUwdg==
|
||||
|
||||
xmldom-sre@^0.1.31:
|
||||
version "0.1.31"
|
||||
resolved "https://registry.yarnpkg.com/xmldom-sre/-/xmldom-sre-0.1.31.tgz#10860d5bab2c603144597d04bf2c4980e98067f4"
|
||||
integrity sha512-f9s+fUkX04BxQf+7mMWAp5zk61pciie+fFLC9hX9UVvCeJQfNHRHXpeo5MPcR0EUf57PYLdt+ZO4f3Ipk2oZUw==
|
||||
|
||||
y18n@^5.0.5:
|
||||
version "5.0.8"
|
||||
resolved "https://registry.yarnpkg.com/y18n/-/y18n-5.0.8.tgz#7f4934d0f7ca8c56f95314939ddcd2dd91ce1d55"
|
||||
|
|
Loading…
Reference in a new issue