Code related

Dark Mode Compatible

All the code block features are fully compatible with dark mode. Toggle dark mode to see the styles.

Code highlight

This feature integrate Shiki

<script>
  const  = 'world!'
</script>

<h1>
  Hello, {}
</h1>
svelte
```svelte
<script>
  const msg = 'world!'
</script>

<h1>
  Hello, {msg}
</h1>
```
md
View code

You can customize the supported languages and theme in light/dark mode. More info reference to Default theme reference - highlight option

Code title

HelloWorld.svelte
<script>
  const  = 'world!'
</script>

<h1>
  Hello, {}
</h1>
svelte
```svelte title="HelloWorld.svelte"
<script>
  const msg = 'world!'
</script>

<h1>
  Hello, {msg}
</h1>
```
md
View code

Line numbers

Add ln in code block meta field would add line numbers in the rendered result.

<script>
  const  = 'world!'
</script>

<h1>
  Hello, {}
</h1>
svelte
1
2
3
4
5
6
7
```svelte ln
<script>
  const msg = 'world!'
</script>

<h1>
  Hello, {msg}
</h1>
```
md
View code

Line highlight

Use // [svp! hl] // [svp! ~~] to highlight the line you want Use // [svp! hl:num] or // [svp! ~~:num] to highlight the num lines from the current line you want

<script>
  const  = 'world!' 

  function () {
    const  = 'bar' 
    const  = 

    return 
  }
</script>

<h1>
  Hello, {}  
</h1>
svelte
```svelte
<script>
  const msg = 'world!' // [svp! hl]

  function hello() {
    const foo = 'bar' // [svp! hl:2]
    const bar = foo

    return foo
  }
</script>

<h1>
  Hello, {msg}  // [svp! ~~]
</h1>
```
md
View code

Diff

Use // [svp! df:+] or // [svp! ++] for diff add Use // [svp! df:-] or // [svp! --] for diff subtract

-
+
-
+
const msg = 'world!' 
const newMsg = 'new world!' 

function hello() {
  console.log('Hello', msg) 
  console.log('Hello', newMsg) 
}
js
```js
const msg = 'world!' // [svp! df:-]
const newMsg = 'new world!' // [svp! df:+]

function hello() {
  console.log('Hello', msg) // [svp! --]
  console.log('Hello', newMsg) // [svp! ++]
}
```
md
View code

Focus

Use // [svp! fc] or // [svp! !!] to focus line Use // [svp! fc:num] or // [svp! !!:num] to focus num lines from current line

Multiple focus ranges

You can use multiple focus commands in the same code block. Each selected line or range stays focused, while the remaining lines are dimmed.

<div>
  this would be blur
</div>
<div>
  this would be blur
</div>
<h1> 
  this would be focus
</h1>
<div>
  this would be blur
</div>
<div>
  this would be blur
</div>
<p>this would also be focus</p> 
<div>
  this would be blur
</div>
html
```html
<div>
  this would be blur
</div>
<div>
  this would be blur
</div>
<h1> // [svp! !!:3]
  this would be focus
</h1>
<div>
  this would be blur
</div>
<div>
  this would be blur
</div>
<p>this would also be focus</p> // [svp! fc]
<div>
  this would be blur
</div>
```
md
View code

Markdown live code

Literal Markdown live source

Use the md language with the live prop to render the Markdown preview and show its source below. The source panel only applies Markdown syntax highlighting: code commands and other transforms run in the preview, while the original Markdown remains unchanged in the source.

Input

````md live
### Title
* item1
* item2
```js
const foo = 'bar' 
```
````
md

Output

Title

  • item1
  • item2
const foo = 'bar' 
js
### Title
* item1
* item2
```js
const foo = 'bar' // [svp! hl]
```
md
View code

Svelte live code

Use svelte lang and live prop would render the result and the source codes under the result.

Input

```svelte live ln title=Counter.svelte
<script>
  let count = $state(0)

  const handleClick = () => {
    count++
  }
</script>
<button onclick={handleClick}>
  You've clicked {count} times
</button>
<style>
  button {
    background-color: purple;
    color: white;
    outline: 0;
    border: 0;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
  }
</style>
```
md

Output

Counter.svelte
<script>
  let  = (0)

  const  = () => {
    ++
  }
</script>
<button ={}>
  You've clicked {} times
</button>
<style>
  button {
    background-color: purple;
    color: white;
    outline: 0;
    border: 0;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
  }
</style>
svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
View code

Async svelte live code

The js file that render the demo part would be bundled into a single js file and load async in the page

Input

```svelte live async
<h1>This is an async svelte live code</h1>
```
md

Output

<h1>This is an async svelte live code</h1>
svelte
View code
Live code in live code is not supported

The nested live code block below would be rendered as normal highlight code block.

```md live
### Title
```
md
````md
```md live
### Title
```
````
md
View code

Combine features

You can use more than one features mentioned above:

complex-example.js
-
+
+
function hello() {
  const oldMsg = 'Some msg with focus, diff --'  
  const newMsg1 = 'Some msg with both focus, diff ++, highlight line'  
  const newMsg2 = 'Some msg with both focus, diff ++' 
}
js
1
2
3
4
5
```js ln title="complex-example.js"
function hello() {
  const oldMsg = 'Some msg with focus, diff --' // [svp! --] // [svp! !!:3]
  const newMsg1 = 'Some msg with both focus, diff ++, highlight line' // [svp! ++] // [svp! ~~]
  const newMsg2 = 'Some msg with both focus, diff ++' // [svp! ++]
}
```
md
View code

Import code

This feature can allow you to import some code directly from a file. And use the file extension name as lang to highlight the code. And you can specify the startLine and endLine to intercept the code you want.

@code(/path/to/file[,startLine[,endLine]])
md

Path can starts with . or /

  • . is the relative path to the current md file
  • / is the relative path to project root, where you start the vite command

For example you have file tree like this

├─ src
│  ├─ routes
│  │  ├─ foo
│  │  │  ├─ +page.md
│  │  │  ├─ Foo.svelte
txt
  • @code(./Foo.svelte) - import all code from Foo.svelte
  • @code(/src/routes/foo/Foo.svelte) - import all code from Foo.svelte
  • @code(./Foo.svelte,5,10) - import the line 10 to line 20 in Foo.svelte
  • @code(/src/routes/foo/Foo.svelte,10,20) - import the line 10 to line 20 in Foo.svelte
Tip

Notice that start line and end line both would be included in the final content.

Cheat list

AliasEqualsFunction
~~hlhighlight single line
~~:numhl:numhighlight num line from current line
++df:+diff add line
--df:-diff subtract line
!!fcfocus single line
!!:numfc:numfocus num line from current line