You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guide/markdown.md
+64Lines changed: 64 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -323,6 +323,70 @@ module.exports = {
323
323
}
324
324
</style>
325
325
326
+
## Import Code Snippets
327
+
328
+
You can import code snippets from existing files via following syntax:
329
+
330
+
```md
331
+
<<< @/filepath
332
+
```
333
+
334
+
It also supports [line highlighting](#line-highlighting-in-code-blocks):
335
+
336
+
```md
337
+
<<< @/filepath{highlightLines}
338
+
```
339
+
340
+
**Input**
341
+
342
+
```md
343
+
<<< @/snippets/snippet.js{2}
344
+
```
345
+
346
+
**Code file**
347
+
348
+
<!--lint disable strong-marker-->
349
+
350
+
<<< @/snippets/snippet.js
351
+
352
+
<!--lint enable strong-marker-->
353
+
354
+
**Output**
355
+
356
+
<!--lint disable strong-marker-->
357
+
358
+
<<< @/snippets/snippet.js{2}
359
+
360
+
<!--lint enable strong-marker-->
361
+
362
+
::: tip
363
+
The value of `@` corresponds to `process.cwd()`.
364
+
:::
365
+
366
+
You can also use a [VS Code region](https://code.visualstudio.com/docs/editor/codebasics#_folding) to only include the corresponding part of the code file. You can provide a custom region name after a `#` following the filepath (`snippet` by default):
367
+
368
+
**Input**
369
+
370
+
```md
371
+
<<< @/snippets/snippet-with-region.js{1}
372
+
```
373
+
374
+
**Code file**
375
+
376
+
<!--lint disable strong-marker-->
377
+
378
+
<<< @/snippets/snippet-with-region.js
379
+
380
+
<!--lint enable strong-marker-->
381
+
382
+
**Output**
383
+
384
+
<!--lint disable strong-marker-->
385
+
386
+
<<< @/snippets/snippet-with-region.js#snippet{1}
387
+
388
+
<!--lint enable strong-marker-->
389
+
326
390
## Advanced Configuration
327
391
328
392
VitePress uses [markdown-it](https://github.com/markdown-it/markdown-it) as the Markdown renderer. A lot of the extensions above are implemented via custom plugins. You can further customize the `markdown-it` instance using the `markdown` option in `.vitepress/config.js`:
0 commit comments