2024-03-09 01:09:31 +08:00

95 lines
2.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
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()
}
```