Skip to content

Commit 97da56b

Browse files
authored
docs: more detailed explain about code snippets (#178)
1 parent aa8c4ca commit 97da56b

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

guide/syntax.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -443,11 +443,28 @@ You can import code snippets from existing files via following syntax:
443443
<<< @/snippets/snippet.js
444444
```
445445

446-
::: tip
447-
The value of `@` corresponds to the source root, the directory where the `slides.md` is located.
446+
:::tip
447+
The value of `@` corresponds to your package's root directory. It's recommended to put snippets in `@/snippets`, for compatibility with the Monaco editor. Alternatively, you can also import from relative paths.
448448
:::
449449

450-
This feature is vendored from VitePress, learn more about it in [VitePress's documentation](https://vitepress.dev/guide/markdown#import-code-snippets).
450+
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:
451+
452+
```md
453+
<<< @/snippets/snippet.js#region-name
454+
```
455+
456+
To explicitly specify the language of the imported code, you can add a language identifier after:
457+
458+
```md
459+
<<< @/snippets/snippet.js ts
460+
```
461+
462+
Any code block features like [line highlighting](#line-highlighting) and [Monaco editor](#monaco-editor) are also supported:
463+
464+
```md
465+
<<< @/snippets/snippet.js {2,3|5}{lines:true}
466+
<<< @/snippets/snippet.js ts {monaco}{height:200px}
467+
```
451468

452469
## Configurations
453470

0 commit comments

Comments
 (0)