Skip to content

Commit 80c8d42

Browse files
yuyinwsantfu
andauthored
feat: enhance code block & code group (#2174)
Co-authored-by: Anthony Fu <[email protected]>
1 parent ef1b15e commit 80c8d42

26 files changed

+81
-76
lines changed

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

docs/custom/config-routes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Add custom pages to the Slidev app.
88

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

11-
```ts twoslash
11+
```ts twoslash [./setup/routes.ts]
1212
import { defineRoutesSetup } from '@slidev/types'
1313

1414
export default defineRoutesSetup((routes) => {

docs/custom/config-shortcuts.md

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

77
Create `./setup/shortcuts.ts` with the following content:
88

9-
```ts twoslash
9+
```ts twoslash [./setup/shortcuts.ts]
1010
import type { NavOperations, ShortcutOptions } from '@slidev/types'
1111
import { defineShortcutsSetup } from '@slidev/types'
1212

docs/custom/config-transformers.md

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

55
This setup function allows you to define custom transformers for the markdown content of **each slide**. This is useful when you want to add custom Markdown syntax and render custom code blocks. To start, create a `./setup/transformers.ts` file with the following content:
66

7-
````ts twoslash
7+
````ts twoslash [setup/transformers.ts]
88
import type { MarkdownTransformContext } from '@slidev/types'
99
import { defineTransformersSetup } from '@slidev/types'
1010

docs/custom/config-unocss.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ You can therefore style your content the way you want. For example:
3131

3232
You can create `uno.config.ts` under the root of your project to extend the builtin configurations
3333

34-
```ts twoslash
34+
```ts twoslash [uno.config.ts]
3535
import { defineConfig } from 'unocss'
3636

3737
export default defineConfig({

docs/custom/config-vite.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ To configure the built-in plugins listed above, create a `vite.config.ts` with t
2121

2222
<!-- eslint-disable import/first -->
2323

24-
```ts twoslash
24+
```ts twoslash [vite.config.ts]
2525
/// <reference types="@slidev/types" />
2626
import type MarkdownIt from 'markdown-it'
2727
declare const MyPlugin: (md: any) => void

docs/custom/config-vue.md

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

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

11-
```ts twoslash
11+
```ts twoslash [setup/main.ts]
1212
import type { Plugin } from 'vue'
1313
declare const YourPlugin: Plugin
1414
// ---cut---

docs/custom/directory-structure.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ The `index.html` provides the ability to inject meta tags and/or scripts to the
9393

9494
For example, for the following custom `index.html`:
9595

96-
```html
97-
<!-- ./index.html -->
96+
```html [index.html]
9897
<head>
9998
<link rel="preconnect" href="https://fonts.gstatic.com">
10099
<link href="https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;600&family=Nunito+Sans:wght@200;400;600&display=swap" rel="stylesheet">

docs/guide/global-context.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,13 @@ Slidev injects several global context values for advanced navigation controls.
66

77
You can access them directly in your slides or components:
88

9-
```md
10-
<!-- slides.md -->
11-
9+
```md [slides.md]
1210
# Page 1
1311

1412
Current page is: {{ $nav.currentPage }}
1513
```
1614

17-
```vue
18-
<!-- Foo.vue -->
19-
15+
```vue [Foo.vue]
2016
<template>
2117
<div>Title: {{ $slidev.configs.title }}</div>
2218
<button @click="$nav.next">

docs/guide/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ Slidev provides a set of commands in its CLI. Here are some common ones:
117117

118118
To run these commands, you can add them to your `package.json` scripts (which has been done for you if the project was created via `npm init slidev`):
119119

120-
```json
120+
```json [package.json]
121121
{
122122
"scripts": {
123123
"dev": "slidev --open",

docs/guide/write-addon.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ An addon can also specify its required Slidev version in the same way as themes.
2929

3030
The same as themes, you can preview your addon via a `./slides.md` like this:
3131

32-
```md
32+
```md [slides.md]
3333
---
3434
addons:
3535
- ./

docs/guide/write-layout.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ Layouts are Vue components, so you can use all the features of Vue in them.
1717

1818
In the layout component, use `<slot/>` (the default slot) for the slide content:
1919

20-
```vue
21-
<!-- default.vue -->
20+
```vue [default.vue]
2221
<template>
2322
<div class="slidev-layout default">
2423
<slot />
@@ -28,8 +27,7 @@ In the layout component, use `<slot/>` (the default slot) for the slide content:
2827

2928
You can also have [named slots](https://vuejs.org/guide/components/slots.html) for more complex layouts:
3029

31-
```vue
32-
<!-- split.vue -->
30+
```vue [split.vue]
3331
<template>
3432
<div class="slidev-layout split">
3533
<div class="left">

docs/guide/write-theme.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Basically, the way to provide global styles, layouts, components and configure t
4848

4949
To provide default Slidev configurations, you can add a `slidev.defaults` field in the `package.json` file, which will be merged with the user's configurations:
5050

51-
```json
51+
```json [package.json]
5252
{
5353
"slidev": {
5454
"defaults": {
@@ -77,7 +77,7 @@ An error message will be shown when the an incompatible version is used.
7777

7878
By default, Slidev assumes themes support both light mode and dark mode. If you only want your theme to be presented in a specific color schema, you need to specify it explicitly in the `package.json`:
7979

80-
```json
80+
```json [package.json]
8181
{
8282
"slidev": {
8383
"colorSchema": "light" // or "dark" or "both"
@@ -89,7 +89,7 @@ By default, Slidev assumes themes support both light mode and dark mode. If you
8989

9090
You can preview your theme when developing by using a demo slide deck. To do so, create a `./slides.md` file with the following headmatter:
9191

92-
```md
92+
```md [slides.md]
9393
---
9494
theme: ./ # Use the theme in the current directory
9595
---

docs/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"unplugin-vue-components": "catalog:prod",
4242
"vite-plugin-inspect": "catalog:prod",
4343
"vitepress": "catalog:docs",
44+
"vitepress-plugin-group-icons": "catalog:docs",
4445
"vitepress-plugin-llms": "catalog:docs",
4546
"vue": "catalog:frontend"
4647
}

docs/vite.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Icons from 'unplugin-icons/vite'
55
import Components from 'unplugin-vue-components/vite'
66
import { defineConfig } from 'vite'
77
import Inspect from 'vite-plugin-inspect'
8+
import { groupIconVitePlugin } from 'vitepress-plugin-group-icons'
89
import llmstxt from 'vitepress-plugin-llms'
910

1011
export default defineConfig({
@@ -46,5 +47,6 @@ export default defineConfig({
4647
}),
4748
Inspect(),
4849
UnoCSS(),
50+
groupIconVitePlugin(),
4951
],
5052
})

0 commit comments

Comments
 (0)