Code Preview

approved

by Hank

Code block preview by file path.

39 stars5,349 downloadsUpdated 3y agoMIT
View on GitHub

Obsidian Code Previews Plugin

中文

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: languagelang

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

ConfigDescriptionTypeDefault
pathfile pathstringRequired
startpreview start line. Start with 1number or string or RegExp-
endpreview end line.number or string or RegExp-
highlighthighlight linesnumber or string or RegExp-
linenumberdisplay line Numbers, priority is greater than the plugin configurationtrue or falseplugin config

Plugin configuration

ConfigDescriptionTypeDefault
watchAliasListening Alias folder changes, update input suggest. May affect performancebooleanfalse
watchCodeListen to the previewed code file and update the render when the file changes. May affect performancebooleanfalse
highLightColorhighlight backgroundcss color#2d82cc20
includeinclude path, Empty is AllArray<string or RegExp>[]
excludeexclude pathArray<string or RegExp>["node_modules", ".obsidian"]
includeFileinclude file, RequiredArray<string or RegExp>["/\.js$/", "/\.css$/"]
excludeFileexclude fileArray<string or RegExp>[]
aliasalias pathstring | Aliascode
linenumberdisplay linenumbertrue or falsetrue

Thank

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

For plugin developers

Search results and similarity scores are powered by semantic analysis of your plugin's README. If your plugin isn't appearing for searches you'd expect, try updating your README to clearly describe your plugin's purpose, features, and use cases.