Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug report]编辑器重复引入MathJax导致控制台报错 #73

Closed
Morris-G opened this issue Dec 27, 2021 · 1 comment
Closed

[Bug report]编辑器重复引入MathJax导致控制台报错 #73

Morris-G opened this issue Dec 27, 2021 · 1 comment

Comments

@Morris-G
Copy link
Contributor

Describe the bug
使用src引入MathJax时,多个实例切换时控制台会报错

To Reproduce

  1. 在Vue 2.x环境下使用Cherry封装编辑器组件
const options =  {
  ...
  engine: {
    ...
    syntax: {
      ...
      mathBlock: {
           engine: 'MathJax', // katex或MathJax
           src: './static/mathjax/text-svg.js'
      },
  ...
}
this.cherry = new Cherry(this.options)
  1. 外层页面引用封装的组件
  2. 外层页面切换不同的MD文档

Expected behavior
正常显示,控制台无报错

Screenshots
控制台报错:
控制台报错
多次重复引入:
多次重复引入

Environment (please complete the following information):

  • OS: macOS
  • Browser: Chrome
  • Version:0.5.14

Additional context
感觉像是Engine.js这里在动态加载script的时候没有做是否存在的判断,每次都会加载一遍对应的js文件,然后mathjax抛出了错误...

如果使用externals配置MathJax为window.MathJax同时设置mathBlock的src为空,此时可以自行控制引入js文件,但是插件(cherry配置默认引入的'input/asciimath', '[tex]/noerrors', '[tex]/cancel', '[tex]/color', '[tex]/boldsymbol')不会自动引入,需要手动一个一个去加载,感觉不太友好...

if (!window.MathJax) {
  loadScript(MATH_JAX_LIB).then(() => {
     this.initCherry()
  })
} else {
     this.initCherry()
}

设置externals时未自动加载plugins:
设置externals时未自动加载plugins
设置mathBlock.src时会自动加载同目录下的plugins:
设置mathBlock.src时会自动加载同目录下的plugins

@jiawei686
Copy link
Collaborator

收到,问题描述很详细,我们优化下mathjax的引入机制,感谢反馈!

Morris-G added a commit to Morris-G/cherry-markdown that referenced this issue May 16, 2022
* fix(insert): file type wrong

* chore(release): 0.6.1

* fix(suggester):  adapt empty regex in safari

* chore(actions): run github actions on dev branch events

* fix(lookbehind): fix `replaceStringByBuffer` returns empty string when nothing to replace

* fix(*): fix usage of lookbehind support

* fix: 0xA0 need to be treated as space

Fixed Tencent#83

* fix: use 0xa0 unicode instead

Tencent#84 (comment)
Tencent#84

* fix(suggester): suggester lookbehind regex support & fix list test case

* fix(suggester): extract replacer from toHtml to avoid regex error in safari

* fix(suggester): add leadingChars

* fix: mathjax script duplicate with multiple cherry instances

Fixed Tencent#73

* style(*): eslint fix

* fix: type error in mathjax

* fix: delay backslash tranform time

* chore(release): 0.6.2

* feat: api:setValue() 更新内容时支持保持光标位置 (Tencent#106)

* fix(list): avoid string collect error while building tree

* Support poster in video (Tencent#94)

* feat: support poster in video

Fixed Tencent#93

* docs: support poster in video

Tencent#93

* feat: add force append

* fix(Image): encode poster url

* chore(release): 0.6.3

* build(deps): bump mermaid from 8.11.1 to 8.13.8

Bumps [mermaid](https://github.com/knsv/mermaid) from 8.11.1 to 8.13.8.
- [Release notes](https://github.com/knsv/mermaid/releases)
- [Changelog](https://github.com/mermaid-js/mermaid/blob/develop/docs/CHANGELOG.md)
- [Commits](mermaid-js/mermaid@8.11.1...8.13.8)

---
updated-dependencies:
- dependency-name: mermaid
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

* chore(release): 0.6.4

* fix(list): adapt list cases to avoid array out of boundary

* feat: optimize error output

* perf(image): fix poor performance when referencing data-url images

* style(*): lint

* fix(list): adapt list cases to avoid array out of boundary

* feat: optimize error output

* fix(ts file): fix ts file couldn't submit

* chore(release): 0.6.5

* build(deps): bump node-fetch from 2.6.6 to 2.6.7

Bumps [node-fetch](https://github.com/node-fetch/node-fetch) from 2.6.6 to 2.6.7.
- [Release notes](https://github.com/node-fetch/node-fetch/releases)
- [Changelog](https://github.com/node-fetch/node-fetch/blob/main/docs/CHANGELOG.md)
- [Commits](node-fetch/node-fetch@v2.6.6...v2.6.7)

---
updated-dependencies:
- dependency-name: node-fetch
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

* build(deps): bump node-fetch from 2.6.6 to 2.6.7 in /client

Bumps [node-fetch](https://github.com/node-fetch/node-fetch) from 2.6.6 to 2.6.7.
- [Release notes](https://github.com/node-fetch/node-fetch/releases)
- [Changelog](https://github.com/node-fetch/node-fetch/blob/main/docs/CHANGELOG.md)
- [Commits](node-fetch/node-fetch@v2.6.6...v2.6.7)

---
updated-dependencies:
- dependency-name: node-fetch
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

* fix: fix README content of engine mode.

* fix Tencent#132 (Tencent#139)

* add pre  增加pre语法(四个空格变成代码块) (Tencent#137)

* add pre  增加pre语法(四个空格变成代码块)

* 优化缩进代码块的逻辑,兼容高亮代码块和行内代码块互相嵌套的场景

* fix 缩进语法内嵌列表失效的问题,fix 缩进语法行号没有正确计算的问题

* add header anchorStyle  Fixed:Tencent#134 (Tencent#138)

* add header anchorStyle  Fixed:Tencent#134

* 优化paste功能:1、优化样式;2、增加粘贴时将HTML转成md的开关 (Tencent#141)

* chore(release): 0.6.6

* fix: refresh codemirror while toggling fullscreen

* fix: add no-escape regex in math

* feat: add code tag in indent code block

* feat: 增加拖拽上传功能; Fixed:Tencent#36 (Tencent#146)

* feat: 增加拖拽上传功能; Fixed:Tencent#36

* feat: 增加拖拽上传文件的功能,包括:批量拖拽上传、拖拽文本直接回显、拖拽图片回显图片、拖拽文件回显超链接

* build(deps): bump prismjs from 1.25.0 to 1.27.0 in /client

Bumps [prismjs](https://github.com/PrismJS/prism) from 1.25.0 to 1.27.0.
- [Release notes](https://github.com/PrismJS/prism/releases)
- [Changelog](https://github.com/PrismJS/prism/blob/master/CHANGELOG.md)
- [Commits](PrismJS/prism@v1.25.0...v1.27.0)

---
updated-dependencies:
- dependency-name: prismjs
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

* fix: 修复代码块内嵌套缩进时出现占位字符的情况

* fix(editor): fix the compatibility issue of cjk ime (Tencent#150)

Fixed Tencent#82

* Fix/url cache miss (Tencent#151)

* fix(editor): fix the compatibility issue of cjk ime

Fixed Tencent#82

* fix(url-cache): fix url cache string not working correctly

* fix(Cherry.js): fix cherry resize and refresh codemirror context (Tencent#142)

* chore(release): 0.6.7

* chore(test): fix jest dependencies

* chore(test): add complete test for engine

* feat: add commonmark test suites

* feat: add commonmark test suites

* feat: add commonmark test suites

* chore(test): add complete test for engine

* chore(test): add complete test for engine

* feat: improve content cache for paragraph

* fix: eslint fix & list test case fix

* chore(release): 0.6.8

* Fix/suggester compatible node (Tencent#157)

* fix(suggester): fix sugggester hook compatible for node env

* docs: optimize docs about node env usage

Co-authored-by: humyfred <513407656@qq.om>

* fix(table-head): fix th content not rendering

* improve readme file

* chore(release): 0.6.9

* fix:(suggester): fix keydown up down or enter which does not work

* chore(release): 0.6.10

* fix: replace lookbehind in math regex

* chore(release): 0.6.11

* fix(list): use list start number

* chore(release): 0.6.12

* build(deps-dev): bump electron from 16.0.3 to 16.0.6 in /client

Bumps [electron](https://github.com/electron/electron) from 16.0.3 to 16.0.6.
- [Release notes](https://github.com/electron/electron/releases)
- [Changelog](https://github.com/electron/electron/blob/main/docs/breaking-changes.md)
- [Commits](electron/electron@v16.0.3...v16.0.6)

---
updated-dependencies:
- dependency-name: electron
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>

* fix(link): add bracket match check

* fix(code-block): fix language matching regex

Fixed Tencent#90

* build: add cherry engine esm output

* chore(jsdom): upgrade jsdom to 19.0.0

* Feat: add table wysiwyg v1.0 (Tencent#189)

* fix: 列表嵌套段落语法时,行号计算错误

* feat: 完善表格所见即所得**基本**编辑功能

* feat: 增加预览区域编辑功能的开关配置

* feat: change codemirror mode to 'gfm'

* feat: update unit test (Tencent#188)

* feat: 增加表格编辑文档

* update readme

* fix(suggester): fix keydown 'enter' affect the default logic of newlineAndIndentContinueMarkdownList (Tencent#190)

LGTM

* build(deps-dev): bump node-sass from 6.0.1 to 7.0.0

Bumps [node-sass](https://github.com/sass/node-sass) from 6.0.1 to 7.0.0.
- [Release notes](https://github.com/sass/node-sass/releases)
- [Changelog](https://github.com/sass/node-sass/blob/master/CHANGELOG.md)
- [Commits](sass/node-sass@v6.0.1...v7.0.0)

---
updated-dependencies:
- dependency-name: node-sass
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>

* Feat preview scroll animation (Tencent#193)

* feat: add previewer scroll animation

* chore(release): 0.7.0

* build(deps): bump minimist from 1.2.5 to 1.2.6 in /client

Bumps [minimist](https://github.com/substack/minimist) from 1.2.5 to 1.2.6.
- [Release notes](https://github.com/substack/minimist/releases)
- [Commits](https://github.com/substack/minimist/compare/1.2.5...1.2.6)

---
updated-dependencies:
- dependency-name: minimist
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

* build(deps): bump ansi-regex from 3.0.0 to 3.0.1 in /client

Bumps [ansi-regex](https://github.com/chalk/ansi-regex) from 3.0.0 to 3.0.1.
- [Release notes](https://github.com/chalk/ansi-regex/releases)
- [Commits](chalk/ansi-regex@v3.0.0...v3.0.1)

---
updated-dependencies:
- dependency-name: ansi-regex
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

* fix: update list type regex to avoid content lost (Tencent#196)

Fixed Tencent#194

* Feat table support codeblock (Tencent#198)

* feat: add previewer scroll animation

* fix: save the last move

* feat: 表格编辑兼容代码块的场景,修复纯预览模式下可以所见即所得编辑的问题

* fix(checklist): illegal inline checklist (Tencent#200)

* fix(checklist): illegal inline checklist

* chore(.gitignore): ignore package-lock.json

* chore: restore lock files

* fix(checklist): fix reg exp

* fix: update blockquote regex to split list

Fixed Tencent#165

* feat(toolbar): add quote hook & optimize quote level implementation

* fix(comment-reference): fix npe problem when there is a comment reference at the beginning of the document

* fix: 最小高度调整 Tencent#207

* fix(code-block): fix Tencent#166 parse hr and indent code (Tencent#205)

* fix(code-block): fix Tencent#166 parse hr and indent code

* fix(code-block): remove lookbehind assertion and prepend line feed

Co-authored-by: jaredjywang <jaredjywang@tencent.com>

* fix: 修复批量拖拽上传文件没回调就插入内容的bug

* fix: 通过工具栏插入内容时,默认选中被插入的内容 Tencent#206

* fix: 修复缩进代码块行号计算不准的问题

* fix: 增加使用el初始化编辑器的能力 Tencent#203

* feat: 插入有序列表的时候,序号自增 Tencent#160

* docs(*): update multiple instance demo

* docs(*): update custom menu docs

* docs(config): improve docs about cherry default config

* docs(toolbar): add custom toolbar guide

Fixed Tencent#202

* chore(release): 0.7.1

* bump to 0.7.1

Co-authored-by: humyfred <513407656@qq.com>
Co-authored-by: jiawei686 <892001108@qq.com>
Co-authored-by: ivorwei <ivorwei@tencent.com>
Co-authored-by: 韩野 <hanye9895@163.com>
Co-authored-by: barryhu <barryhu@tencent.com>
Co-authored-by: sunsonliu <383977164@qq.com>
Co-authored-by: hanye9895 <68373171+hanye9895@users.noreply.github.com>
Co-authored-by: sunsonliu <sunsonliu@tencent.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: jrainliu <jrainliu@tencent.com>
Co-authored-by: lyngai <wlxjust@gmail.com>
Co-authored-by: humyfred <513407656@qq.om>
Co-authored-by: Jared Wang <stillba@icloud.com>
Co-authored-by: jaredjywang <jaredjywang@tencent.com>
wty92911 pushed a commit to wty92911/cherry-markdown that referenced this issue May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants