禁止 VitePress 渲染代码块

在把 VuePress 迁移到 VitePress 后,发现一些代码块里的伪代码报错, 查了下才知道 VitePress 不支持配置关闭.

但还是在issues里找到解决方法.

config.mts 中添加如下配置:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
markdown: {
  config: (md) => {
    const render = md.render
    md.render = function (src, env) {
      return `<div v-pre>${render.call(this, src, env)}</div>`
    }
  },
  html: false,
  attrs: {
    disable: true
  }
}

attrs 是关闭双大括号解析的

build with Hugo, theme Stack, visits 0