yhao32 downloadsImport code files with @import syntax. Compatible with Markdown Preview Enhanced.
Import external code files in your Obsidian notes using @import syntax (compatible with Markdown Preview Enhanced).
Full file import:

Partial import (specific lines):

| Full import | Partial import |
|---|---|
![]() |
![]() |
line_begin, line_end)../)@import "path/to/file.go"
@import "path/to/file.go" {line_begin=4 line_end=14}
@import "examples/main.py" {line_begin=10}
@import "config.yaml" {line_end=-4}
| Parameter | Description (0-based) | Description (1-based) |
|---|---|---|
line_begin |
Start line, 0-based index | Start line, 1-based index |
line_end |
End line, exclusive (supports negative) | End line, inclusive (supports negative) |
0-based mode (default, MPE-compatible):
{line_begin=0 line_end=10} → Lines 1-10 (indices 0-9){line_begin=5} → From line 6 to end{line_end=-2} → From start, excluding last 2 lines1-based mode:
{line_begin=1 line_end=10} → Lines 1-10{line_begin=5} → From line 5 to end{line_end=-2} → From start, excluding last 2 linesmain.js, manifest.json, styles.css from Releases<vault>/.obsidian/plugins/code-import/@import directive in your markdown fileIn your markdown file:
## User Struct Definition
@import "examples/user.go" {line_begin=10 line_end=25}
| Setting | Description | Default |
|---|---|---|
| Show file name | Display filename header above code block | On |
| Wrap code | Wrap long lines instead of horizontal scrolling | Off |
| Line number base | 0-based (MPE-compatible) or 1-based indexing for line_begin/line_end |
0-based |