Obsidian Plugin

Code Import

Import external code files in your Obsidian notes using @import syntax. Compatible with Foam and Markdown Preview Enhanced.

See it in action

Import code files directly into your notes with automatic syntax highlighting.

examples/user.go
 1package main
 2
 3import (
 4    "fmt"
 5    "time"
 6)
 7
 8// User represents a user in the system
 9type User struct {
10    ID        int
11    Name      string
12    Email     string
13    CreatedAt time.Time
14}
15
16// NewUser creates a new user with the given name and email
17func NewUser(name, email string) *User {
18    return &User{
19        ID:        generateID(),
20        Name:      name,
21        Email:     email,
22        CreatedAt: time.Now(),
23    }
24}
25
26// String returns a string representation of the user
27func (u *User) String() string {
28    return fmt.Sprintf("User{ID: %d, Name: %s, Email: %s}", u.ID, u.Name, u.Email)
29}
30
31func generateID() int {
32    return int(time.Now().UnixNano() % 10000)
33}
34
35func main() {
36    user := NewUser("Alice", "[email protected]")
37    fmt.Println(user)
38}
Markdown
# Full File Import

@import "examples/user.go"
Full file import on desktop
Markdown
# Partial Import

Only the `User` struct (lines 8-14):

@import "examples/user.go" {line_begin=7 line_end=14}
Partial import on desktop

Simple @import Syntax

Use familiar Foam/MPE syntax to import code files with optional line ranges.

Full file

@import "path/to/file.go"

Lines 5-14

@import "path/to/file.go" {line_begin=4 line_end=14}

From line 11

@import "examples/main.py" {line_begin=10}

Exclude last 4 lines

@import "config.yaml" {line_end=-4}

Features

Everything you need to embed code in your documentation.

Import Code Files

Embed external code files directly in your Obsidian notes with syntax highlighting.

Line Range Selection

Import specific lines with line_begin and line_end parameters. Supports negative indices.

Syntax Highlighting

Automatic language detection based on file extension, using Obsidian's Prism.js.

Relative Paths

Reference files using relative paths, including parent directories with ../.

Installation

Get started in seconds.

1

Open Community Plugins

Go to Settings → Community plugins → Browse

2

Search for "Code Import"

Find the plugin in the community plugins list

3

Install and Enable

Click Install, then Enable to start using the plugin