mirror of
https://github.com/pengzhanbo/vuepress-theme-plume.git
synced 2026-04-23 10:58:13 +08:00
95 lines
2.3 KiB
Markdown
95 lines
2.3 KiB
Markdown
---
|
||
title: 代码高亮
|
||
author: pengzhanbo
|
||
createTime: 2024/03/06 10:21:47
|
||
permalink: /config/plugins/code-highlight/
|
||
---
|
||
|
||
## 概述
|
||
|
||
主题内置的代码高亮插件, 对代码块进行代码高亮。
|
||
|
||
主题 使用 [Shiki](https://github.com/shikijs/shiki) 在 Markdown 代码块中使用彩色文本实现语法高亮。
|
||
Shiki 支持多种编程语言。
|
||
|
||
在 Shiki 的代码仓库中,可以找到 [合法的编程语言列表](https://shiki.style/languages) 。
|
||
|
||
关联插件: [@vuepress-plume/plugin-shikiji](https://github.com/pengzhanbo/vuepress-theme-plume/tree/main/plugins/plugin-shikiji)
|
||
|
||
默认配置:
|
||
|
||
```ts
|
||
import { plumeTheme } from 'vuepress-theme-plume'
|
||
import { defineUserConfig } from 'vuepress'
|
||
|
||
export default defineUserConfig({
|
||
theme: plumeTheme({
|
||
plugins: {
|
||
shiki: {
|
||
theme: { light: 'vitesse-light', dark: 'vitesse-dark' },
|
||
},
|
||
}
|
||
}),
|
||
})
|
||
```
|
||
|
||
## 配置
|
||
|
||
### theme
|
||
|
||
- 类型: `string | { light: string, dark: string }`
|
||
- 默认值: `{ light: 'vitesse-light', dark: 'vitesse-dark' }`
|
||
|
||
代码高亮主题,支持 浅色/暗色 双主题。
|
||
|
||
可在 支持的 [主题列表](https://shiki.style/themes) 中选择你喜欢的主题。
|
||
|
||
### languages
|
||
|
||
- 类型: `string[]`
|
||
- 默认值: `[]`
|
||
|
||
需要高亮的编程语言, 例如 `javascript`、`typescript`、`python`、`java`、`c++`、`c#`等。
|
||
默认会根据代码块的语言自动识别。
|
||
|
||
在 Shiki 的代码仓库中,可以找到 [合法的编程语言列表](https://shiki.style/languages) 。
|
||
|
||
### defaultHighlightLang
|
||
|
||
- 类型: `string`
|
||
- 默认值: `text`
|
||
|
||
默认高亮的编程语言。当代码块未指定语言时使用。
|
||
|
||
### codeTransformers
|
||
|
||
- 类型: `ShikiTransformer[]`
|
||
- 默认值: `[]`
|
||
|
||
代码转换器, 查看 [shiki transformers](https://shiki.style/guide/transformers) 了解更多信息。
|
||
|
||
### twoslash <Badge type="tip" text="实验性" />
|
||
|
||
- 类型: `boolean`
|
||
- 默认值: `false`
|
||
|
||
实验性功能,是否启用 对 `typescript` 和 `vue` 语言的 类型提示 支持。
|
||
|
||
查看 [twoslash](/guide/markdown/experiment/#twoslash) 了解更多信息。
|
||
|
||
### whitespace
|
||
|
||
- 类型: `boolean`
|
||
- 默认值: `false`
|
||
|
||
将空白字符(Tab 和空格)渲染为单独的标签(具有 tab 或 space 类名)。
|
||
|
||
效果:
|
||
|
||
```ts whitespace
|
||
function block() {
|
||
space()
|
||
table()
|
||
}
|
||
```
|