| 1 | --- |
| 2 | name: import-snippet |
| 3 | description: Import code from external files into slides with optional region selection |
| 4 | --- |
| 5 | |
| 6 | # Import Code Snippets |
| 7 | |
| 8 | Import code from external files into slides. |
| 9 | |
| 10 | ## Basic Syntax |
| 11 | |
| 12 | ```md |
| 13 | <<< @/snippets/snippet.js |
| 14 | ``` |
| 15 | |
| 16 | `@` = package root directory. Recommended: place snippets in `@/snippets/`. |
| 17 | |
| 18 | ## Import Region |
| 19 | |
| 20 | Use VS Code region syntax: |
| 21 | |
| 22 | ```md |
| 23 | <<< @/snippets/snippet.js#region-name |
| 24 | ``` |
| 25 | |
| 26 | ## Specify Language |
| 27 | |
| 28 | ```md |
| 29 | <<< @/snippets/snippet.js ts |
| 30 | ``` |
| 31 | |
| 32 | ## With Features |
| 33 | |
| 34 | Combine with line highlighting, Monaco editor: |
| 35 | |
| 36 | ```md |
| 37 | <<< @/snippets/snippet.js {2,3|5}{lines:true} |
| 38 | <<< @/snippets/snippet.js ts {monaco}{height:200px} |
| 39 | ``` |
| 40 | |
| 41 | ## Placeholder |
| 42 | |
| 43 | Use `{*}` for line highlighting placeholder: |
| 44 | |
| 45 | ```md |
| 46 | <<< @/snippets/snippet.js {*}{lines:true} |
| 47 | ``` |
| 48 | |
| 49 | ## Monaco Write |
| 50 | |
| 51 | Link editor to file for live editing: |
| 52 | |
| 53 | ```md |
| 54 | <<< ./some-file.ts {monaco-write} |
| 55 | ``` |
| 56 |