Replies: 1 comment 5 replies
-
我尝试了一下,目前想兼容对称和非对称的标识很麻烦,所以正对你的情况建议替换内部的公式扩展,像下面这样: npm i markdown-it-math import { config } from 'md-editor-v3';
import mathPlugin from 'markdown-it-math/dist/markdown-it-math.js';
config({
markdownItPlugins(plugins) {
return plugins
.map((item) => {
if (item.type === 'katex') {
return {
...item,
plugin: mathPlugin,
options: {
// ...item.options,
inlineOpen: '\\(',
inlineClose: '\\)',
blockOpen: '\\[',
blockClose: '\\]',
inlineRenderer: (str: string) => {
if (item.options.katexRef.value) {
const html = item.options.katexRef.value.renderToString(str, {
throwOnError: false
});
return `<span class="md-editor-katex-inline" data-processed>${html}</span>`;
} else {
return `<span class="md-editor-katex-inline">${str}</span>`;
}
},
blockRenderer: (str: string, token: Token) => {
const lineNum: number = token.map![0];
if (item.options.katexRef.value) {
const html = item.options.katexRef.value.renderToString(str, {
throwOnError: false,
displayMode: true
});
return `<p class="md-editor-katex-block" data-line=${lineNum} data-processed>${html}</p>`;
} else {
return `<p class="md-editor-katex-block" data-line=${lineNum}>${str}</p>`;
}
}
}
};
}
return item;
});
}
}); |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
我看到现在对
katex
的解析是写死使用$...$
作为行内公式,$$ ... $$
作为块级公式. 但有时候服务返回的内容采用了 MathJax\( ... \)
和\[ ... \]
的默认标签. 现在需要手动去正则替换一下这些符号才能在 md-editor-v3 中正常渲染. 如果能增加这些标签的配置就更好了! ❤️Beta Was this translation helpful? Give feedback.
All reactions