Search...Search plugins and themes...
⌘K
Sign in
  • Get started
  • Download
  • Pricing
  • Enterprise
  • Account
  • Obsidian
  • Overview
  • Sync
  • Publish
  • Canvas
  • Mobile
  • Web Clipper
  • CLI
  • Learn
  • Help
  • Developers
  • Changelog
  • About
  • Roadmap
  • Blog
  • Resources
  • System status
  • License overview
  • Terms of service
  • Privacy policy
  • Security
  • Community
  • Plugins
  • Themes
  • Discord
  • Forum / 中文论坛
  • Merch store
  • Brand guidelines
Follow us
DiscordTwitterBlueskyThreadsMastodonYouTubeGitHub
© 2026 Obsidian

Code Preview

hankjshankjs5k downloads

Code block preview by file path.

Add to Obsidian
  • Overview
  • Scorecard
  • Updates11

中文

Example

Specific examples can be use Open folder as vault open example.zip.

Path

Basic

Code language is extname by path

```preview
path: hello.js
```
Relative Path
```preview
path: ./hello.js
```
Absolute Path

The root path is Vault folder

```preview
path: /sub/color.css
```
```preview
path: /hello.js
```

CodeBlock language

Code language is extname by path

Language key: language、lang

language、lang
```preview
path: ./hello.js
lang: ts
```
```preview
path: ./hello.js
language: ts
```

Select display line range

custom start or end

The third line of the file ends
```preview
path: /sub/color.css
start: 3
```
The first line to the third line
```preview
path: /sub/color.css
end: 3
```
Only preview the third line
```preview
path: /sub/color.css
start: 3
end: 3
```
Line Range
```preview
path: /sub/color.css
start: 2
end: 3
```
end increase by start

end: "+1", config " is required.

```preview
path: /sub/color.css
start: 2
end: "+1"
```
Use RegExp or Search text)

/dd\d{2}/

```preview
path: /sub/color.css
start: body
end: /dd\d{2}/
```

If you don't know RegExp, just use text directly. like:

start: body: match body inside the line end: dd00dd: match dd00dd inside the line

```preview
path: /sub/color.css
start: body
end: dd00dd
```

Highlight

By line
```preview
path: /sub/color.css
highlight: 1
```
Range
```preview
path: /sub/color.css
highlight: 1-3
```
Search text
```preview
path: /sub/color.css
highlight: dd00dd
```
RegExp
```preview
path: /sub/color.css
highlight: /dd\d{2}/
```
Multi rule

Separator ,.

```preview
path: /sub/color.css
highlight: /dd\d{2}/, 1, body
```

YAML list

```preview
path: /sub/color.css
highlight:
  - /dd\d{2}/
  - 1
  - body
```

CodeBlock YAML config

Config Description Type Default
path file path string Required
start preview start line. Start with 1 number or string or RegExp -
end preview end line. number or string or RegExp -
highlight highlight lines number or string or RegExp -
linenumber display line Numbers, priority is greater than the plugin configuration true or false plugin config

Plugin configuration

Config Description Type Default
watchAlias Listening Alias folder changes, update input suggest. May affect performance boolean false
watchCode Listen to the previewed code file and update the render when the file changes. May affect performance boolean false
highLightColor highlight background css color #2d82cc20
include include path, Empty is All Array<string or RegExp> []
exclude exclude path Array<string or RegExp> ["node_modules", ".obsidian"]
includeFile include file, Required Array<string or RegExp> ["/\.js$/", "/\.css$/"]
excludeFile exclude file Array<string or RegExp> []
alias alias path string | Alias code
linenumber display linenumber true or false true

Thank

linenumber, highlight Based on obsidian-better-codeblock his implementation

HealthFair
ReviewCaution
About
Preview code files from your vault directly inside notes using simple preview codeblocks with relative or absolute paths. Specify language, extract line ranges by number, text or RegExp, and highlight lines or patterns with multiple rules or YAML lists.
CodeFilesSyntax
Details
Current version
1.3.11
Last updated
4 years ago
Created
4 years ago
Updates
11 releases
Downloads
5k
Compatible with
Obsidian 1.0.0+
Platforms
Desktop, Mobile
License
MIT
Report bugRequest featureReport plugin
Author
hankjshankjs
github.com/zjhcn
GitHubhankjs
  1. Community
  2. Plugins
  3. Code
  4. Code Preview

Related plugins

Code Space

Professional code file management with visual dashboard, syntax highlighting editor, and Markdown embedding.

VSCode Editor

Edit Code Files like VSCode.

Shiki Highlighter

Highlight code blocks with Shiki.

Notebook Navigator

A better file browser and calendar inspired by Apple Notes, Bear, Evernote and Day One.

Claudian

Embeds Claude Code/Codex and other local Agents as AI collaborators in your vault.

Advanced URI

Control everything with URI.

Local REST API with MCP

Unlock your automation needs by interacting with your notes over a secure REST API.

Find orphaned files and broken links

Find files that are not linked anywhere and would otherwise be lost in your vault. In other words: files with no backlinks.

Omnisearch

Intelligent search for your notes, PDFs, and OCR for images.

Recent Files

Display a list of recently opened files.