Skip to content

Commit

Permalink
fix: mathjax script duplicate with multiple cherry instances
Browse files Browse the repository at this point in the history
Fixed #73
  • Loading branch information
jiawei686 committed Jan 6, 2022
1 parent a1fb8b1 commit 5ba3ddd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"@types/jest": "^27.0.3",
"@types/jsdom": "^16.2.13",
"@types/lodash": "^4.14.170",
"@types/mathjax": "^0.0.37",
"@types/mermaid": "^8.2.6",
"@types/virtual-dom": "^2.1.0",
"@typescript-eslint/eslint-plugin": "^4.27.0",
Expand Down
7 changes: 6 additions & 1 deletion src/Engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,17 @@ export default class Engine {

initMath(opts) {
// 无论MathJax还是Katex,都可以先进行MathJax配置
const { syntax } = opts.engine;
const { externals, engine } = opts;
const { syntax } = engine;
const { plugins } = syntax.mathBlock;
// 未开启公式
if (!isBrowser() || (!syntax.mathBlock.src && !syntax.inlineMath.src)) {
return;
}
// 已经加载过MathJax
if (externals.MathJax || window.MathJax) {
return;
}
configureMathJax(plugins);
// 等待MathJax各种插件加载
const script = document.createElement('script');
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1700,6 +1700,11 @@
resolved "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.178.tgz#341f6d2247db528d4a13ddbb374bcdc80406f4f8"
integrity sha512-0d5Wd09ItQWH1qFbEyQ7oTQ3GZrMfth5JkbN3EvTKLXcHLRDSXeLnlvlOn0wvxVIwK5o2M8JzP/OWz7T3NRsbw==

"@types/mathjax@^0.0.37":
version "0.0.37"
resolved "https://registry.npmjs.org/@types/mathjax/-/mathjax-0.0.37.tgz#31a0076ced55c2e12da75edb44db45098b6feed6"
integrity sha512-y0WSZBtBNQwcYipTU/BhgeFu1EZNlFvUNCmkMXV9kBQZq7/o5z82dNVyH3yy2Xv5zzeNeQoHSL4Xm06+EQiH+g==

"@types/mermaid@^8.2.6":
version "8.2.7"
resolved "https://registry.npmjs.org/@types/mermaid/-/mermaid-8.2.7.tgz#1f9610c241361f66ed0591d3186e0bf3ed2211c8"
Expand Down

0 comments on commit 5ba3ddd

Please sign in to comment.