Skip to content

Commit 80c8d42

Browse files
yuyinwsantfu
andauthored
feat: enhance code block & code group (#2174)
Co-authored-by: Anthony Fu <github@antfu.me>
1 parent ef1b15e commit 80c8d42

26 files changed

Lines changed: 81 additions & 76 deletions

docs/.vitepress/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { DefaultTheme } from 'vitepress'
22
import { fileURLToPath } from 'node:url'
33
import { transformerTwoslash } from '@shikijs/vitepress-twoslash'
44
import { defineConfig } from 'vitepress'
5+
import { groupIconMdPlugin } from 'vitepress-plugin-group-icons'
56
import { version } from '../package.json'
67
import Customizations from './customizations'
78
import { Advanced, BuiltIn, Guides, Resources } from './pages'
@@ -72,6 +73,9 @@ export default defineConfig({
7273
},
7374
}),
7475
],
76+
config(md) {
77+
md.use(groupIconMdPlugin)
78+
},
7579
},
7680
cleanUrls: true,
7781
themeConfig: {

docs/.vitepress/theme/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import './styles/vars.css'
88
import './styles/demo.css'
99
import './styles/custom.css'
1010
import 'uno.css'
11+
import 'virtual:group-icons.css'
1112

1213
export default {
1314
extends: Theme,

docs/components.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// @ts-nocheck
33
// Generated by unplugin-vue-components
44
// Read more: https://github.com/vuejs/core/pull/3399
5+
// biome-ignore lint: disable
56
export {}
67

78
/* prettier-ignore */
@@ -26,6 +27,7 @@ declare module 'vue' {
2627
CarbonArrowLeft: typeof import('~icons/carbon/arrow-left')['default']
2728
CarbonArrowRight: typeof import('~icons/carbon/arrow-right')['default']
2829
CarbonBadge: typeof import('~icons/carbon/badge')['default']
30+
CarbonDocumentPdf: typeof import('~icons/carbon/document-pdf')['default']
2931
CarbonDownload: typeof import('~icons/carbon/download')['default']
3032
CarbonEdit: typeof import('~icons/carbon/edit')['default']
3133
CarbonInformation: typeof import('~icons/carbon/information')['default']
@@ -36,6 +38,7 @@ declare module 'vue' {
3638
CarbonPen: typeof import('~icons/carbon/pen')['default']
3739
CarbonSettingsAdjust: typeof import('~icons/carbon/settings-adjust')['default']
3840
CarbonSun: typeof import('~icons/carbon/sun')['default']
41+
CarbonTextAnnotationToggle: typeof import('~icons/carbon/text-annotation-toggle')['default']
3942
CarbonUserAvatar: typeof import('~icons/carbon/user-avatar')['default']
4043
CarbonUserSpeaker: typeof import('~icons/carbon/user-speaker')['default']
4144
CarbonVideo: typeof import('~icons/carbon/video')['default']

docs/custom/config-code-runners.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Create `./setup/code-runners.ts` with the following content:
1010

1111
<!-- eslint-disable import/first -->
1212

13-
```ts twoslash
13+
```ts twoslash [setup/code-runners.ts]
1414
declare const executePythonCodeRemotely: (code: string) => Promise<string>
1515
declare const sanitizeHtml: (html: string) => string
1616
// ---cut---

docs/custom/config-context-menu.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Create `./setup/context-menu.ts` with the following content:
88

99
<!-- eslint-disable import/first -->
1010

11-
```ts twoslash
11+
```ts twoslash [./setup/context-menu.ts]
1212
// ---cut---
1313
import { useNav } from '@slidev/client'
1414
import { defineContextMenuSetup } from '@slidev/types'

docs/custom/config-highlighter.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ Slidev uses [Shiki](https://github.com/shikijs/shiki) as the code highlighter. I
88

99
Create `./setup/shiki.ts` file with the following content:
1010

11-
```ts twoslash
12-
/* ./setup/shiki.ts */
11+
```ts twoslash [setup/shiki.ts]
1312
import { defineShikiSetup } from '@slidev/types'
1413

1514
export default defineShikiSetup(() => {
@@ -29,8 +28,7 @@ If you want to add custom theme or language (TextMate grammar/themes in JSON), y
2928

3029
<!-- eslint-disable import/first-->
3130

32-
```ts twoslash
33-
/* ./setup/shiki.ts */
31+
```ts twoslash [setup/shiki.ts]
3432
import { defineShikiSetup } from '@slidev/types'
3533
// ---cut-start---
3634
// @ts-expect-error missing types

docs/custom/config-katex.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
Create `./setup/katex.ts` with the following content:
66

7-
```ts twoslash
7+
```ts twoslash [setup/katex.ts]
88
import { defineKatexSetup } from '@slidev/types'
99

1010
export default defineKatexSetup(() => {

docs/custom/config-mermaid.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
Create `./setup/mermaid.ts` with the following content:
66

7-
```ts twoslash
7+
```ts twoslash [setup/mermaid.ts]
88
import { defineMermaidSetup } from '@slidev/types'
99

1010
export default defineMermaidSetup(() => {

docs/custom/config-monaco.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
Create `./setup/monaco.ts` with the following content:
66

7-
```ts twoslash
7+
```ts twoslash [./setup/monaco.ts]
88
import { defineMonacoSetup } from '@slidev/types'
99

1010
export default defineMonacoSetup(async (monaco) => {
@@ -71,8 +71,7 @@ console.log('HelloWorld')
7171

7272
Alternatively if you would like these options to be applied to every Monaco instance, you can return them in the `defineMonacoSetup` function
7373

74-
```ts twoslash
75-
// ./setup/monaco.ts
74+
```ts twoslash [./setup/monaco.ts]
7675
import { defineMonacoSetup } from '@slidev/types'
7776

7877
export default defineMonacoSetup(() => {

docs/custom/config-parser.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ The preparser (step 1 above) is highly extensible and allows you to implement cu
2626

2727
To customize it, create a `./setup/preparser.ts` file with the following content:
2828

29-
```ts twoslash
29+
```ts twoslash [./setup/preparser.ts]
3030
import { definePreparserSetup } from '@slidev/types'
3131

3232
export default definePreparserSetup(({ filepath, headmatter, mode }) => {
@@ -76,7 +76,7 @@ see you next time
7676

7777
To allow these `@src:` and `@cover:` syntaxes, create a `./setup/preparser.ts` file with the following content:
7878

79-
```ts twoslash
79+
```ts twoslash [./setup/preparser.ts]
8080
import { definePreparserSetup } from '@slidev/types'
8181

8282
export default definePreparserSetup(() => {
@@ -157,7 +157,7 @@ Here we used an underscore in `_scale` to avoid possible conflicts with existing
157157

158158
To handle this `_scale: ...` syntax in the frontmatter, create a `./setup/preparser.ts` file with the following content:
159159

160-
```ts twoslash
160+
```ts twoslash [./setup/preparser.ts]
161161
import { definePreparserSetup } from '@slidev/types'
162162

163163
export default definePreparserSetup(() => {
@@ -207,7 +207,7 @@ Here we used an underscore in `_note` to avoid possible conflicts with existing
207207

208208
To handle this `_note: ...` syntax in the frontmatter, create a `./setup/preparser.ts` file with the following content:
209209

210-
```ts twoslash
210+
```ts twoslash [./setup/preparser.ts]
211211
import fs, { promises as fsp } from 'node:fs'
212212
import { definePreparserSetup } from '@slidev/types'
213213

0 commit comments

Comments
 (0)