cherry-markdown icon indicating copy to clipboard operation
cherry-markdown copied to clipboard

[Bug Report] MathJax 无法渲染

Open xdewx opened this issue 1 year ago • 6 comments

Prerequisites

Describe the Bug

公式无法正常渲染,相关的配置文档也不详细;

 mathBlock: {
    engine: 'MathJax', // katex or MathJax
    src: 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js',
    plugins: true, // Default load plug-in
},
inlineMath: {
    engine: 'MathJax', // katex or MathJax
},

图片

另外经实践发现,根据当前的文档描述,mermaid的异步引入会出错,同样需要使用default解构才可以正常工作

const registerPlugin = async () => {
    const [{ default: CherryMermaidPlugin }, { default: mermaid }] = await Promise.all([
        import('cherry-markdown/src/addons/cherry-code-block-mermaid-plugin'),
        // import('cherry-markdown/src/addons/cherry-code-block-plantuml-plugin'),
        import('mermaid'),
        // import('mathjax/es5/tex-mml-svg'),
    ]);
    console.info(CherryMermaidPlugin, mermaid)
    Cherry.usePlugin(CherryMermaidPlugin, {
        mermaid, // pass in mermaid object
    });
};

Reproduction Steps

No response

System Information

No response

Contributing

None

xdewx avatar Aug 25 '24 13:08 xdewx

配置问题吧,我这里是正常的:

      mathBlock: {
        engine: "MathJax", // katex或MathJax
        src: import.meta.env.BASE_URL + "/mathjax/es5/tex-svg.js",
        plugins: true, // 默认加载插件
      },
      inlineMath: {
        engine: "MathJax", // katex或MathJax
        src: import.meta.env.BASE_URL + "/mathjax/es5/tex-svg.js",
      },
import CherryMermaidPlugin from "cherry-markdown/dist/addons/cherry-code-block-mermaid-plugin";
import mermaid from "mermaid";

Cherry.usePlugin(CherryMermaidPlugin, {
  mermaid,
});

捕获

foxfire881 avatar Aug 28 '24 14:08 foxfire881

配置问题吧,我这里是正常的:

      mathBlock: {
        engine: "MathJax", // katex或MathJax
        src: import.meta.env.BASE_URL + "/mathjax/es5/tex-svg.js",
        plugins: true, // 默认加载插件
      },
      inlineMath: {
        engine: "MathJax", // katex或MathJax
        src: import.meta.env.BASE_URL + "/mathjax/es5/tex-svg.js",
      },
import CherryMermaidPlugin from "cherry-markdown/dist/addons/cherry-code-block-mermaid-plugin";
import mermaid from "mermaid";

Cherry.usePlugin(CherryMermaidPlugin, {
  mermaid,
});

捕获

你是指其他配置项可能影响到公式吗?直觉上来说都是独立的不应该呀

另外我是用的最新版本的markdown+mermaid9+echarts4(READMD文档上的版本号)

再者,您可以试下异步import看看mermaid的导入方式是不是如我所说

xdewx avatar Aug 28 '24 21:08 xdewx

你是指其他配置项可能影响到公式吗?直觉上来说都是独立的不应该呀 另外我是用的最新版本的markdown+mermaid9+echarts4(READMD文档上的版本号) 再者,您可以试下异步import看看mermaid的导入方式是不是如我所说

我也是最新版本,不过我没有用异步加载耶~ 很早之前在其他项目用过异步加载,感觉问题比较多处理、调试起来都很麻烦,意义也不大,所以后来就不用了,直接copy demo代码就能调通的事就不折腾了。

foxfire881 avatar Aug 29 '24 02:08 foxfire881

Prerequisites

Describe the Bug

公式无法正常渲染,相关的配置文档也不详细;

 mathBlock: {
    engine: 'MathJax', // katex or MathJax
    src: 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js',
    plugins: true, // Default load plug-in
},
inlineMath: {
    engine: 'MathJax', // katex or MathJax
},

图片

另外经实践发现,根据当前的文档描述,mermaid的异步引入会出错,同样需要使用default解构才可以正常工作

const registerPlugin = async () => {
    const [{ default: CherryMermaidPlugin }, { default: mermaid }] = await Promise.all([
        import('cherry-markdown/src/addons/cherry-code-block-mermaid-plugin'),
        // import('cherry-markdown/src/addons/cherry-code-block-plantuml-plugin'),
        import('mermaid'),
        // import('mathjax/es5/tex-mml-svg'),
    ]);
    console.info(CherryMermaidPlugin, mermaid)
    Cherry.usePlugin(CherryMermaidPlugin, {
        mermaid, // pass in mermaid object
    });
};

Reproduction Steps

No response

System Information

No response

Contributing

None

又看了一遍你的配置,确实是少了一行,你只配置了Block块级公式的src,Inline行级公式的src没有配置,而你截图里插入的都是行级公式的代码,当然无法解析。

foxfire881 avatar Aug 29 '24 02:08 foxfire881

Prerequisites

有块级公式吧,双$中间就是

xdewx avatar Aug 29 '24 05:08 xdewx

实测:

  1. 在vite+vue初始化工程下,最简配置下将cherry-markdown版本回退到0.8.45公式渲染就正常了
  2. 在我的复杂工程下,将cherry-markdown版本回退到0.8.40公式也正常渲染
  3. 最新0.8.46在以上工程下都无法正常工作

xdewx avatar Aug 31 '24 05:08 xdewx

您好,我版本改到0.8.45还是没有渲染成功该怎么办呀

ruisen2020 avatar Nov 13 '24 15:11 ruisen2020

您好,我版本改到0.8.45还是没有渲染成功该怎么办呀 见: https://github.com/Tencent/cherry-markdown/issues/961

RSS1102 avatar Nov 13 '24 15:11 RSS1102

您好,我版本改到0.8.45还是没有渲染成功该怎么办呀 见: #961

这个不稳定,偶尔成功,经常失败

ruisen2020 avatar Nov 13 '24 15:11 ruisen2020

您好,我版本改到0.8.45还是没有渲染成功该怎么办呀 见: #961

这个不稳定,偶尔成功,经常失败

mathjax 资源下载到本地引用

RSS1102 avatar Nov 13 '24 15:11 RSS1102

在哪下载到本地然后使用呀

ruisen2020 avatar Nov 13 '24 15:11 ruisen2020

在哪下载到本地然后使用呀 https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js 打开链接,右键保存到本地。

如有其他问题请新开Discussions 寻求帮助,如遇到错误,请新开Issues,尽量不要在他人issue下进行多次寻求帮助讨论以免对其他用户造成噪音干扰。

RSS1102 avatar Nov 13 '24 15:11 RSS1102

抱歉,我用本地的,还是偶然成功,经常失败

ruisen2020 avatar Nov 13 '24 16:11 ruisen2020

抱歉,我用本地的,还是偶然成功,经常失败

请新开问题,提供一个复现视频和可复现代码片段。

RSS1102 avatar Nov 13 '24 16:11 RSS1102