imzbf / md-editor-v3

Markdown editor for vue3, developed in jsx and typescript, dark theme、beautify content by prettier、render articles directly、paste or clip the picture and upload it...
https://imzbf.github.io/md-editor-v3
MIT License
1.51k stars 145 forks source link

Options for katex-plugin not possible #622

Closed smartnio closed 3 weeks ago

smartnio commented 1 month ago

Describe the issue

Hi, i just wanna know how to set options for the katex-plugin within the md-editor-v3 config. I followed the docs with configurating the markdownItPlugins section in the README. But i can't figure out, how to change options for the katex plugin, because the katex options is a vue reactive katexRef which is not available on configuration start.

I want to set e.g. the strict mode of the plugin to get rid of warnings. They are inside p.options.katexRef.value.SETTINGS_SCHEMA

config({
  markdownItPlugins(plugins) {
    return plugins.map((p) => {
      if (p.type === 'katex') {
          //not available on startup
          //stores a ref
          console.log(p.options.katexRef)
          //undefined
          console.log(p.options.katexRef.value)      

          //available, but of course, not settable after configuration is already initiated
        setTimeout(() => {
          //filled with SETTINGS_SCHEMA
          console.log(p.options.katexRef.value)
        }, 2000)
      }
    })
  }
});

If not an issue, can be moved to discussion. But thanks for the help!

Procedure version

4.18..0

Reproduction link

No response

imzbf commented 1 month ago

When using CDN, we cannot obtain an instance of katex here, and it's currently not possible to get it here either. I will try to enhance it later.  Currently, installing via dependencies works:

npm i katex
import { config } from 'md-editor-v3';
import katex from 'katex';

config({
  markdownItPlugins(plugins, { editorId }) {
    return plugins.map((item) => {
      if (item.type === 'katex') {
        // will not be undefined
        console.log('katexRef', item.options.katexRef.value);
      }

      return item;
    });
  },
  editorExtensions: {
    katex: {
        instance: katex
    }
  }
})
imzbf commented 3 weeks ago

4.19.0中优化了这个问题,参考https://imzbf.github.io/md-editor-v3/zh-CN/docs#%F0%9F%94%A7%20katexConfig