返回 slidev
code-block-line-numbers.md
根目录 / docs / features / code-block-line-numbers.md
1 ---
2 depends:
3 - guide/syntax#code-block
4 tags: [codeblock]
5 description: |
6 Enable line numbering for all code blocks across the slides or individually.
7 ---
8
9 # Line Numbers
10
11 You can enable line numbering for all code blocks across the slides by setting `lineNumbers: true` in the headmatter, or enable each code block individually by setting `lines: true`.
12
13 You can also set the starting line for each code block and highlight the lines accordingly via `{startLine: number}`, which defaults to 1.
14
15 ````md
16 ```ts {6,7}{lines:true,startLine:5}
17 function add(
18 a: Ref<number> | number,
19 b: Ref<number> | number
20 ) {
21 return computed(() => unref(a) + unref(b))
22 }
23 ```
24 ````
25
26 Note that you can use `{*}` as a placeholder of <LinkInline link="features/line-highlighting" />:
27
28 ````md
29 ```ts {*}{lines:true,startLine:5}
30 // ...
31 ```
32 ````
33
33 lines MARKDOWN