方案:markdown-it + markdown-it-katex
注意这里的markdown-it-katex需要用 vscode 维护的版本

第一步:下载依赖
npm install markdown-it
npm install @vscode/markdown-it-katex
第二步:引入样式文件
我这里是 vue 项目,就在 public/index.html中的 head 标签引入
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.4/dist/katex.min.css"/>
第三步:使用
我这里演示的在 vue 中使用,封装为一个组件。
<template>
<div v-html="renderedContent"></div>
</template>
<script>
import MarkdownIt from "markdown-it";
import markdownItKatex from "@vscode/markdown-it-katex";
export default {
name: "MarkdownRenderer",
props: {
content: String
},
computed: {
renderedContent() {
const md = new MarkdownIt()
md.use(markdownItKatex)
return md.render(this.content);
}
}
};
</script>
效果展示
![![[Pasted image 20250824142953.png]]](/https://i-blog.csdnimg.cn/direct/3fe5d299b74244069de96d2b87d73863.png)

5872

被折叠的 条评论
为什么被折叠?



