Skip to content

Commit 75f18e4

Browse files
authored
feat: migrate to shikiji (#3237)
1 parent 46966ac commit 75f18e4

File tree

10 files changed

+486
-208
lines changed

10 files changed

+486
-208
lines changed

Diff for: __tests__/e2e/markdown-extensions/markdown-extensions.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -163,19 +163,19 @@ describe('Line Numbers', () => {
163163
describe('Import Code Snippets', () => {
164164
test('basic', async () => {
165165
const lines = page.locator('#basic-code-snippet + div code > span')
166-
expect(await lines.count()).toBe(22)
166+
expect(await lines.count()).toBe(11)
167167
})
168168

169169
test('specify region', async () => {
170170
const lines = page.locator('#specify-region + div code > span')
171-
expect(await lines.count()).toBe(6)
171+
expect(await lines.count()).toBe(3)
172172
})
173173

174174
test('with other features', async () => {
175175
const div = page.locator('#with-other-features + div')
176176
expect(await getClassList(div)).toContain('line-numbers-mode')
177177
const lines = div.locator('code > span')
178-
expect(await lines.count()).toBe(6)
178+
expect(await lines.count()).toBe(3)
179179
expect(await getClassList(lines.nth(0))).toContain('highlighted')
180180
})
181181
})
@@ -216,10 +216,10 @@ describe('Code Groups', () => {
216216

217217
// blocks
218218
const blocks = div.locator('.blocks > div')
219-
expect(await blocks.nth(0).locator('code > span').count()).toBe(22)
219+
expect(await blocks.nth(0).locator('code > span').count()).toBe(11)
220220
expect(await getClassList(blocks.nth(1))).toContain('line-numbers-mode')
221221
expect(await getClassList(blocks.nth(1))).toContain('language-ts')
222-
expect(await blocks.nth(1).locator('code > span').count()).toBe(6)
222+
expect(await blocks.nth(1).locator('code > span').count()).toBe(3)
223223
expect(
224224
await getClassList(blocks.nth(1).locator('code > span').nth(0))
225225
).toContain('highlighted')

Diff for: docs/.vitepress/config.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,15 @@ export default defineConfig({
1313
cleanUrls: true,
1414

1515
markdown: {
16-
math: true
16+
math: true,
17+
codeTransformers: [
18+
// We use `[!!code` in demo to prevent transformation, here we revert it back.
19+
{
20+
postprocess(code) {
21+
return code.replace(/\[\!\!code/g, '[!code')
22+
}
23+
}
24+
]
1725
},
1826

1927
sitemap: {

Diff for: docs/guide/markdown.md

+10-16
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ For more details, see [Frontmatter](../reference/frontmatter-config).
8080

8181
**Input**
8282

83-
```
83+
```md
8484
| Tables | Are | Cool |
8585
| ------------- | :-----------: | ----: |
8686
| col 3 is | right-aligned | $1600 |
@@ -265,7 +265,7 @@ Wraps in a <div class="vp-raw">
265265

266266
## Syntax Highlighting in Code Blocks
267267

268-
VitePress uses [Shiki](https://shiki.matsu.io/) to highlight language syntax in Markdown code blocks, using coloured text. Shiki supports a wide variety of programming languages. All you need to do is append a valid language alias to the beginning backticks for the code block:
268+
VitePress uses [Shikiji](https://github.com/antfu/shikiji) (an improved version of [Shiki](https://shiki.matsu.io/)) to highlight language syntax in Markdown code blocks, using coloured text. Shiki supports a wide variety of programming languages. All you need to do is append a valid language alias to the beginning backticks for the code block:
269269

270270
**Input**
271271

@@ -377,7 +377,7 @@ export default { // Highlighted
377377
}
378378
```
379379

380-
Alternatively, it's possible to highlight directly in the line by using the `// [!code hl]` comment.
380+
Alternatively, it's possible to highlight directly in the line by using the `// [!code hightlight]` comment.
381381

382382
**Input**
383383

@@ -386,7 +386,7 @@ Alternatively, it's possible to highlight directly in the line by using the `//
386386
export default {
387387
data () {
388388
return {
389-
msg: 'Highlighted!' // [!code hl]
389+
msg: 'Highlighted!' // [!!code highlight]
390390
}
391391
}
392392
}
@@ -399,7 +399,7 @@ export default {
399399
export default {
400400
data() {
401401
return {
402-
msg: 'Highlighted!' // [!code hl]
402+
msg: 'Highlighted!' // [!code highlight]
403403
}
404404
}
405405
}
@@ -413,14 +413,12 @@ Additionally, you can define a number of lines to focus using `// [!code focus:<
413413

414414
**Input**
415415

416-
Note that only one space is required after `!code`, here are two to prevent processing.
417-
418416
````
419417
```js
420418
export default {
421419
data () {
422420
return {
423-
msg: 'Focused!' // [!code focus]
421+
msg: 'Focused!' // [!!code focus]
424422
}
425423
}
426424
}
@@ -445,15 +443,13 @@ Adding the `// [!code --]` or `// [!code ++]` comments on a line will create a d
445443

446444
**Input**
447445

448-
Note that only one space is required after `!code`, here are two to prevent processing.
449-
450446
````
451447
```js
452448
export default {
453449
data () {
454450
return {
455-
msg: 'Removed' // [!code --]
456-
msg: 'Added' // [!code ++]
451+
msg: 'Removed' // [!!code --]
452+
msg: 'Added' // [!!code ++]
457453
}
458454
}
459455
}
@@ -479,15 +475,13 @@ Adding the `// [!code warning]` or `// [!code error]` comments on a line will co
479475

480476
**Input**
481477

482-
Note that only one space is required after `!code`, here are two to prevent processing.
483-
484478
````
485479
```js
486480
export default {
487481
data () {
488482
return {
489-
msg: 'Error', // [!code error]
490-
msg: 'Warning' // [!code warning]
483+
msg: 'Error', // [!!code error]
484+
msg: 'Warning' // [!!code warning]
491485
}
492486
}
493487
}

Diff for: docs/reference/site-config.md

+2-82
Original file line numberDiff line numberDiff line change
@@ -454,95 +454,15 @@ When using the default theme, enabling this option will display each page's last
454454

455455
- Type: `MarkdownOption`
456456

457-
Configure Markdown parser options. VitePress uses [Markdown-it](https://github.com/markdown-it/markdown-it) as the parser, and [Shiki](https://shiki.matsu.io/) to highlight language syntax. Inside this option, you may pass various Markdown related options to fit your needs.
457+
Configure Markdown parser options. VitePress uses [Markdown-it](https://github.com/markdown-it/markdown-it) as the parser, and [Shikiji](https://github.com/antfu/shikiji) (an improved version of [Shiki](https://shiki.matsu.io/)) to highlight language syntax. Inside this option, you may pass various Markdown related options to fit your needs.
458458

459459
```js
460460
export default {
461461
markdown: {...}
462462
}
463463
```
464464

465-
Below are all the options that you can have in this object:
466-
467-
```ts
468-
interface MarkdownOptions extends MarkdownIt.Options {
469-
// Custom theme for syntax highlighting.
470-
// You can use an existing theme.
471-
// See: https://github.com/shikijs/shiki/blob/main/docs/themes.md#all-themes
472-
// Or add your own theme.
473-
// See: https://github.com/shikijs/shiki/blob/main/docs/themes.md#loading-theme
474-
theme?:
475-
| Shiki.IThemeRegistration
476-
| { light: Shiki.IThemeRegistration; dark: Shiki.IThemeRegistration }
477-
478-
// Enable line numbers in code block.
479-
lineNumbers?: boolean
480-
481-
// Add support for your own languages.
482-
// https://github.com/shikijs/shiki/blob/main/docs/languages.md#supporting-your-own-languages-with-shiki
483-
languages?: Shiki.ILanguageRegistration[]
484-
485-
// markdown-it-anchor plugin options.
486-
// See: https://github.com/valeriangalliat/markdown-it-anchor#usage
487-
anchor?: anchorPlugin.AnchorOptions
488-
489-
// markdown-it-attrs plugin options.
490-
// See: https://github.com/arve0/markdown-it-attrs
491-
attrs?: {
492-
leftDelimiter?: string
493-
rightDelimiter?: string
494-
allowedAttributes?: Array<string | RegExp>
495-
disable?: boolean
496-
}
497-
498-
// specify default language for syntax highlighter
499-
defaultHighlightLang?: string
500-
501-
// @mdit-vue/plugin-frontmatter plugin options.
502-
// See: https://github.com/mdit-vue/mdit-vue/tree/main/packages/plugin-frontmatter#options
503-
frontmatter?: FrontmatterPluginOptions
504-
505-
// @mdit-vue/plugin-headers plugin options.
506-
// See: https://github.com/mdit-vue/mdit-vue/tree/main/packages/plugin-headers#options
507-
headers?: HeadersPluginOptions | boolean
508-
509-
// @mdit-vue/plugin-sfc plugin options.
510-
// See: https://github.com/mdit-vue/mdit-vue/tree/main/packages/plugin-sfc#options
511-
sfc?: SfcPluginOptions
512-
513-
// @mdit-vue/plugin-toc plugin options.
514-
// See: https://github.com/mdit-vue/mdit-vue/tree/main/packages/plugin-toc#options
515-
toc?: TocPluginOptions
516-
517-
// @mdit-vue/plugin-component plugin options.
518-
// See: https://github.com/mdit-vue/mdit-vue/tree/main/packages/plugin-component#options
519-
component?: ComponentPluginOptions
520-
521-
// Configure the Markdown-it instance.
522-
config?: (md: MarkdownIt) => void
523-
524-
// Same as `config` but will be applied before all other plugins.
525-
preConfig?: (md: MarkdownIt) => void
526-
527-
// Disable cache (experimental)
528-
cache?: boolean
529-
530-
// Math support (experimental)
531-
// You need to install `markdown-it-mathjax3` and set `math` to `true` to enable it.
532-
// You can also pass options to `markdown-it-mathjax3` here.
533-
// See: https://github.com/tani/markdown-it-mathjax3#customization
534-
math?: boolean | any
535-
536-
// Global custom container titles
537-
container?: {
538-
infoLabel?: string
539-
tipLabel?: string
540-
warningLabel?: string
541-
dangerLabel?: string
542-
detailsLabel?: string
543-
}
544-
}
545-
```
465+
Check the [type declaration and jsdocs](https://github.com/vuejs/vitepress/blob/main/src/node/markdown/markdown.ts) for all the options available.
546466

547467
### vite
548468

Diff for: package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@
101101
"mark.js": "8.11.1",
102102
"minisearch": "^6.2.0",
103103
"mrmime": "^1.0.1",
104-
"shiki": "^0.14.5",
104+
"shikiji": "^0.7.2",
105+
"shikiji-transformers": "^0.7.2",
105106
"vite": "^5.0.0",
106107
"vue": "^3.3.8"
107108
},
@@ -187,7 +188,6 @@
187188
"rollup-plugin-dts": "^6.1.0",
188189
"rollup-plugin-esbuild": "^6.1.0",
189190
"semver": "^7.5.4",
190-
"shiki-processor": "^0.1.3",
191191
"simple-git-hooks": "^2.9.0",
192192
"sirv": "^2.0.3",
193193
"sitemap": "^7.1.1",

0 commit comments

Comments
 (0)