Skip to content

Commit 69e0b63

Browse files
committed
feat: update markdown code docs
1 parent 5eab1ef commit 69e0b63

File tree

6 files changed

+68
-362
lines changed

6 files changed

+68
-362
lines changed

docs/guide/markdown.md

Lines changed: 2 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ Following code blocks extensions are implemented during markdown parsing in Node
158158

159159
#### Code Title
160160

161-
You can specify the title of the code block by adding a `title` key-value mark in your fenced code blocks.
161+
You can specify the title of the code block by adding a `title` key-value mark in your fenced code blocks. Note: This requires theme support.
162162

163163
**Input**
164164

@@ -192,98 +192,6 @@ export default defineUserConfig({
192192
})
193193
```
194194

195-
It can be used in combination with the other marks below. Please leave a space between them.
196-
197-
#### Line Highlighting
198-
199-
You can highlight specified lines of your code blocks by adding line ranges mark in your fenced code blocks:
200-
201-
**Input**
202-
203-
````md
204-
```ts{1,7-9}
205-
import { defaultTheme } from '@vuepress/theme-default'
206-
import { defineUserConfig } from 'vuepress'
207-
208-
export default defineUserConfig({
209-
title: 'Hello, VuePress',
210-
211-
theme: defaultTheme({
212-
logo: 'https://vuejs.org/images/logo.png',
213-
}),
214-
})
215-
```
216-
````
217-
218-
**Output**
219-
220-
```ts{1,7-9}
221-
import { defaultTheme } from '@vuepress/theme-default'
222-
import { defineUserConfig } from 'vuepress'
223-
224-
export default defineUserConfig({
225-
title: 'Hello, VuePress',
226-
227-
theme: defaultTheme({
228-
logo: 'https://vuejs.org/images/logo.png',
229-
}),
230-
})
231-
```
232-
233-
Examples for line ranges mark:
234-
235-
- Line ranges: `{5-8}`
236-
- Multiple single lines: `{4,7,9}`
237-
- Combined: `{4,7-13,16,23-27,40}`
238-
239-
::: tip
240-
This line highlighting extension is supported by our built-in plugin, which is forked and modified from [markdown-it-highlight-lines](https://github.com/egoist/markdown-it-highlight-lines).
241-
242-
Config reference: [markdown.code.highlightLines](../reference/config.md#markdown-code-highlightlines)
243-
:::
244-
245-
#### Line Numbers
246-
247-
You must have noticed that the number of lines is displayed on the left side of code blocks. This is enabled by default and you can disable it in config.
248-
249-
You can add `:line-numbers` / `:no-line-numbers` mark in your fenced code blocks to override the value set in config.
250-
251-
**Input**
252-
253-
````md
254-
```ts
255-
// line-numbers is enabled by default
256-
const line2 = 'This is line 2'
257-
const line3 = 'This is line 3'
258-
```
259-
260-
```ts:no-line-numbers
261-
// line-numbers is disabled
262-
const line2 = 'This is line 2'
263-
const line3 = 'This is line 3'
264-
```
265-
````
266-
267-
**Output**
268-
269-
```ts
270-
// line-numbers is enabled by default
271-
const line2 = 'This is line 2'
272-
const line3 = 'This is line 3'
273-
```
274-
275-
```ts:no-line-numbers
276-
// line-numbers is disabled
277-
const line2 = 'This is line 2'
278-
const line3 = 'This is line 3'
279-
```
280-
281-
::: tip
282-
This line numbers extension is supported by our built-in plugin.
283-
284-
Config reference: [markdown.code.lineNumbers](../reference/config.md#markdown-code-linenumbers)
285-
:::
286-
287195
#### Wrap with v-pre
288196

289197
As [template syntax is allowed in Markdown](#template-syntax), it would also work in code blocks, too.
@@ -346,7 +254,7 @@ const onePlusTwoPlusThree = {{ 1 + 2 + 3 }}
346254
::: tip
347255
This v-pre extension is supported by our built-in plugin.
348256

349-
Config reference: [markdown.code.vPre.block](../reference/config.md#markdown-code-vpre-block)
257+
Config reference: [markdown.vPre.block](../reference/config.md#markdown-vpre-block)
350258
:::
351259

352260
### Import Code Blocks

docs/guide/migration.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ Renamed to `pagePatterns`
145145

146146
#### markdown.lineNumbers
147147

148-
Moved to [markdown.code.lineNumbers](../reference/config.md#markdown-code-linenumbers).
148+
Removed.
149149

150-
Default value is changed from `false` to `true`.
150+
The same feature is implemented in [@vuepress/plugin-prismjs][prismjs] and [@vuepress/plugin-shiki][shiki].
151151

152152
#### markdown.pageSuffix
153153

@@ -414,7 +414,7 @@ Some major breaking changes:
414414
- Always provide a valid js entry file, and do not use `"main": "layouts/Layout.vue"` as the theme entry anymore.
415415
- `themeConfig` is removed from user config and site data. To access the `themeConfig` as you would via `this.$site.themeConfig` in v1, we now recommend using the [@vuepress/plugin-theme-data](https://ecosystem.vuejs.press/plugins/theme-data.html) plugin and its `useThemeData` composition API.
416416
- Stylus is no longer the default CSS pre-processor, and the stylus palette system is not embedded. If you still want to use similar palette system as v1, [@vuepress/plugin-palette](https://ecosystem.vuejs.press/plugins/palette.html) may help.
417-
- Markdown code blocks syntax highlighting by Prism.js is not embedded by default. You can use either [@vuepress/plugin-prismjs](https://ecosystem.vuejs.press/plugins/prismjs.html) or [@vuepress/plugin-shiki](https://ecosystem.vuejs.press/plugins/shiki.html), or implement syntax highlighting in your own way.
417+
- Markdown code blocks syntax highlighting by Prism.js is not embedded by default. You can use either [@vuepress/plugin-prismjs][prismjs] or [@vuepress/plugin-shiki][shiki], or implement syntax highlighting in your own way.
418418
- For scalability concerns, `this.$site.pages` is not available any more. See [Advanced > Cookbook > Resolving Routes](../advanced/cookbook/resolving-routes.md) for how to retrieve pages data in v2.
419419

420420
For more detailed guide about how to write a theme in v2, see [Advanced > Writing a Theme](../advanced/theme.md).
@@ -438,3 +438,6 @@ You can still inherit a parent theme with `extends: parentTheme()`, which will e
438438
You can refer to [Default Theme > Extending](https://ecosystem.vuejs.press/themes/default/extending.html) for how to extend default theme.
439439

440440
The `@theme` and `@parent-theme` aliases are removed by default, but you can still make a extendable theme with similar approach, see [Advanced > Cookbook > Making a Theme Extendable](../advanced/cookbook/making-a-theme-extendable.md).
441+
442+
[prismjs]: https://ecosystem.vuejs.press/plugins/prismjs.html
443+
[shiki]: https://ecosystem.vuejs.press/plugins/shiki.html

docs/reference/config.md

Lines changed: 26 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -400,90 +400,6 @@ const defaultOptions = {
400400
You should not configure it unless you understand what it is for.
401401
:::
402402

403-
### markdown.code
404-
405-
- Type: `CodePluginOptions | false`
406-
407-
- Details:
408-
409-
Options for VuePress built-in markdown-it code plugin.
410-
411-
Set to `false` to disable this plugin.
412-
413-
- Also see:
414-
- [Guide > Markdown > Syntax Extensions > Code Blocks](../guide/markdown.md#code-blocks)
415-
416-
#### markdown.code.highlightLines
417-
418-
- Type: `boolean`
419-
420-
- Default: `true`
421-
422-
- Details:
423-
424-
Enable code line highlighting or not.
425-
426-
- Also see:
427-
- [Guide > Markdown > Syntax Extensions > Code Blocks > Line Highlighting](../guide/markdown.md#line-highlighting)
428-
429-
#### markdown.code.lineNumbers
430-
431-
- Type: `boolean | number`
432-
433-
- Default: `true`
434-
435-
- Details:
436-
437-
Configure code line numbers.
438-
439-
- A `boolean` value is to enable line numbers or not.
440-
- A `number` value is the minimum number of lines to enable line numbers. For example, if you set it to `4`, line numbers will only be enabled when your code block has at least 4 lines of code.
441-
442-
- Also see:
443-
- [Guide > Markdown > Syntax Extensions > Code Blocks > Line Numbers](../guide/markdown.md#line-numbers)
444-
445-
#### markdown.code.preWrapper
446-
447-
- Type: `boolean`
448-
449-
- Default: `true`
450-
451-
- Details:
452-
453-
Enable the extra wrapper of the `<pre>` tag or not.
454-
455-
The wrapper is required by the `highlightLines` and `lineNumbers`. That means, if you disable `preWrapper`, the line highlighting and line numbers will also be disabled.
456-
457-
::: tip
458-
You can disable it if you want to implement them in client side. For example, [Prismjs Line Highlight](https://prismjs.com/plugins/line-highlight/) or [Prismjs Line Numbers](https://prismjs.com/plugins/line-numbers/).
459-
:::
460-
461-
#### markdown.code.vPre.block
462-
463-
- Type: `boolean`
464-
465-
- Default: `true`
466-
467-
- Details:
468-
469-
Add `v-pre` directive to `<pre>` tag of code block or not.
470-
471-
- Also see:
472-
- [Guide > Markdown > Syntax Extensions > Code Blocks > Wrap with v-pre](../guide/markdown.md#wrap-with-v-pre)
473-
474-
#### markdown.code.vPre.inline
475-
476-
- Type: `boolean`
477-
478-
- Default: `true`
479-
480-
- Details:
481-
482-
Add `v-pre` directive to `<code>` tag of inline code or not.
483-
484-
- Also see:
485-
- [Guide > Markdown > Syntax Extensions > Code Blocks > Wrap with v-pre](../guide/markdown.md#wrap-with-v-pre)
486-
487403
### markdown.component
488404

489405
- Type: `undefined | false`
@@ -671,6 +587,32 @@ const defaultOptions = {
671587
- Also see:
672588
- [Guide > Markdown > Syntax Extensions > Table of Contents](../guide/markdown.md#table-of-contents)
673589

590+
#### markdown.vPre.block
591+
592+
- Type: `boolean`
593+
594+
- Default: `true`
595+
596+
- Details:
597+
598+
Add `v-pre` directive to `<pre>` tag of code block or not.
599+
600+
- Also see:
601+
- [Guide > Markdown > Syntax Extensions > Code Blocks > Wrap with v-pre](../guide/markdown.md#wrap-with-v-pre)
602+
603+
#### markdown.vPre.inline
604+
605+
- Type: `boolean`
606+
607+
- Default: `true`
608+
609+
- Details:
610+
611+
Add `v-pre` directive to `<code>` tag of inline code or not.
612+
613+
- Also see:
614+
- [Guide > Markdown > Syntax Extensions > Code Blocks > Wrap with v-pre](../guide/markdown.md#wrap-with-v-pre)
615+
674616
## Plugin Config
675617

676618
### plugins

docs/zh/guide/markdown.md

Lines changed: 2 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ Emoji 扩展由 [markdown-it-emoji](https://github.com/markdown-it/markdown-it-e
159159

160160
#### 代码标题
161161

162-
你可以在代码块添加一个 `title` 键值对来为代码块设置标题。
162+
你可以在代码块添加一个 `title` 键值对来为代码块设置标题。提示:需要主题支持。
163163

164164
**Input**
165165

@@ -193,98 +193,6 @@ export default defineUserConfig({
193193
})
194194
```
195195

196-
它可以和下列的其他标记一起使用。请在它们之间使用空格分隔。
197-
198-
#### 行高亮
199-
200-
你可以在代码块添加行数范围标记,来为对应代码行进行高亮:
201-
202-
**输入**
203-
204-
````md
205-
```ts{1,7-9}
206-
import { defaultTheme } from '@vuepress/theme-default'
207-
import { defineUserConfig } from 'vuepress'
208-
209-
export default defineUserConfig({
210-
title: '你好, VuePress',
211-
212-
theme: defaultTheme({
213-
logo: 'https://vuejs.org/images/logo.png',
214-
}),
215-
})
216-
```
217-
````
218-
219-
**输出**
220-
221-
```ts{1,7-9}
222-
import { defaultTheme } from '@vuepress/theme-default'
223-
import { defineUserConfig } from 'vuepress'
224-
225-
export default defineUserConfig({
226-
title: '你好, VuePress',
227-
228-
theme: defaultTheme({
229-
logo: 'https://vuejs.org/images/logo.png',
230-
}),
231-
})
232-
```
233-
234-
行数范围标记的例子:
235-
236-
- 行数范围: `{5-8}`
237-
- 多个单行: `{4,7,9}`
238-
- 组合: `{4,7-13,16,23-27,40}`
239-
240-
::: tip
241-
行高亮扩展是由我们的内置插件支持的,该扩展 Fork 并修改自 [markdown-it-highlight-lines](https://github.com/egoist/markdown-it-highlight-lines)
242-
243-
配置参考: [markdown.code.highlightLines](../reference/config.md#markdown-code-highlightlines)
244-
:::
245-
246-
#### 行号
247-
248-
你肯定已经注意到在代码块的最左侧会展示行号。这个功能是默认启用的,你可以通过配置来禁用它。
249-
250-
你可以在代码块添加 `:line-numbers` / `:no-line-numbers` 标记来覆盖配置项中的设置。
251-
252-
**输入**
253-
254-
````md
255-
```ts
256-
// 行号默认是启用的
257-
const line2 = 'This is line 2'
258-
const line3 = 'This is line 3'
259-
```
260-
261-
```ts:no-line-numbers
262-
// 行号被禁用
263-
const line2 = 'This is line 2'
264-
const line3 = 'This is line 3'
265-
```
266-
````
267-
268-
**输出**
269-
270-
```ts
271-
// 行号默认是启用的
272-
const line2 = 'This is line 2'
273-
const line3 = 'This is line 3'
274-
```
275-
276-
```ts:no-line-numbers
277-
// 行号被禁用
278-
const line2 = 'This is line 2'
279-
const line3 = 'This is line 3'
280-
```
281-
282-
::: tip
283-
行号扩展是由我们的内置插件支持的。
284-
285-
配置参考: [markdown.code.lineNumbers](../reference/config.md#markdown-code-linenumbers)
286-
:::
287-
288196
#### 添加 v-pre
289197

290198
由于 [模板语法可以在 Markdown 中使用](#模板语法),它也同样可以在代码块中生效。
@@ -347,7 +255,7 @@ const onePlusTwoPlusThree = {{ 1 + 2 + 3 }}
347255
::: tip
348256
v-pre 扩展是由我们的内置插件支持的。
349257

350-
配置参考: [markdown.code.vPre.block](../reference/config.md#markdown-code-vpre-block)
258+
配置参考: [markdown.vPre.block](../reference/config.md#markdown-vpre-block)
351259
:::
352260

353261
### 导入代码块

0 commit comments

Comments
 (0)