Skip to content

代码块

代码块配置基于 Expressive Code,支持自定义主题和代码折叠功能。

配置文件

src/config/expressiveCodeConfig.ts

配置项

属性类型默认值说明
darkThemestring"one-dark-pro"暗色模式下的代码主题
lightThemestring"one-light"亮色模式下的代码主题
ts
export const expressiveCodeConfig: ExpressiveCodeConfig = {
  darkTheme: "one-dark-pro",
  lightTheme: "one-light",
};

更多主题请参考 Expressive Code 主题文档

代码折叠

属性类型默认值说明
pluginCollapsible.enablebooleantrue是否启用折叠功能
pluginCollapsible.lineThresholdnumber15代码行数超过此值时显示折叠按钮
pluginCollapsible.previewLinesnumber8折叠时显示的预览行数
pluginCollapsible.defaultCollapsedbooleantrue默认是否折叠长代码块
ts
pluginCollapsible: {
  enable: true,
  lineThreshold: 15,
  previewLines: 8,
  defaultCollapsed: true,
},

WARNING

修改此配置后需要重启 Astro 开发服务器才能生效。