🚧 Rspress 2.0 文档还在开发中
close

CodeBlockRuntime non-ejectable

Warning

该组件是非 ejectable 组件,代码与核心代码耦合度较高,不建议通过 wrap/eject 进行定制。

CodeBlockRuntime 用于在运行时渲染可执行的代码块。

用法

index.mdx
import { CodeBlockRuntime } from '@theme';

export default function Page() {
  return (
    <CodeBlockRuntime
      lang="js"
      title="index.js"
      code={`console.log('Hello World!')`}
      shikiOptions={{}}
    />
  );
}

传入 langtitlecode 渲染代码块;shikiOptions 可自定义高亮配置。

Warning

建议仅在必要条件下使用 CodeBlockRuntime,因为它会增加运行时的包体积,尤其是在需要引入多门语言的时候,并且无法享受编译时高亮带来的性能优势。