dumi icon indicating copy to clipboard operation
dumi copied to clipboard

feat: 支持在md文件里使用Mermaid

Open lane9k opened this issue 9 months ago • 6 comments

What problem does this feature solve?

项目里存在很多md文件Mermaid 时序图,官方dumi 默认不支持Mermaid,社区也没有相关可用包。期待官方支持下

Possible Solution (optional)

No response

lane9k avatar May 20 '25 05:05 lane9k

npm package: rehype-mermaid

config: extraRehypePlugins

Jinbao1001 avatar May 20 '25 10:05 Jinbao1001

@Jinbao1001 感谢,我尝试在配置文件.dumirc.ts里增加如下: export default defineConfig({

extraRehypePlugins:[ require('rehype-mermaid'), ], ##其他配置.. run时 报错: [cause]: Error [ERR_REQUIRE_ESM]: require() of ES Module /home/fire/5-6/spin/node_modules/.pnpm/[email protected]/node_modules/rehype-mermaid/dist/rehype-mermaid.js from /home/fire/5-6/spin/.dumirc.ts not supported. 不知道如何正确配置使得dumi2.4.18工作

lane9k avatar May 20 '25 13:05 lane9k

install then extraRehypePlugins: ['rehype-mermaid']

Jinbao1001 avatar May 21 '25 05:05 Jinbao1001

@Jinbao1001 试过了 Image
run起来后 页面无法识别mermaid指令 无法渲染 按普通文档显示。

Image

确定是这个extraRehypePlugins插件配置接口吗

lane9k avatar May 21 '25 07:05 lane9k

sorry 指引有误, 测试了一下,

Image

插件不生效的原因: Mermaid 的原理是在构建时, 会将<pre> | <code> 标签转换为 svg dumitag 增强插件, 会在构建时将 <pre> & <code> 转换为 <sourceCode> 标签, 代码块高亮能力会在运行时再生成对应的 <pre> | <code> 标签 此插件和 dumi 在运作与设计模式上存在冲突

目前没有计划支持此类依靠构建时识别并替换源码标签的图表类插件增强能力

如果你对此有兴趣, 并有合理方案, 欢迎 pr

Jinbao1001 avatar May 22 '25 04:05 Jinbao1001

现在还不支持mermaid渲染吗? 有什么办法支持?

sogud avatar Sep 02 '25 03:09 sogud