﻿---
title: Shiki Highlight
date: 2025-08-11
excerpt: Hexo Shiki Highlighter Demo
tags:
  - CSS
  - Shiki
  - Markdown
cover: https://assets.vluv.space/cover/FrontEnd/shiki.webp
---

<script data-swup-reload-script type="module" src="/js/components/tab.js"></script>

> [!NOTE]-  Github Repo Link:
>
> - For hexo:  [Efterklang/hexo-shiki-highlight](https://github.com/Efterklang/hexo-shiki-highlight)
> - For Markdown-exit: [Efterklang/markdown-exit-shiki](https://github.com/Efterklang/markdown-exit-shiki)
## Features

### Inline Code

Shiki support inline code highlighting using the following syntax:

<x-tabs>

<x-tab title="Markdown" active>

```markdown
- **Plain**: `printf("Hello, World")`
- **Python**: `{python} print("Hello, World")`
- **JavaScript**: `{javascript} console.log("Hello, World")`
- **HTML**: `{html} <h1>Hello, World!</h1>`
- **Rust** `{rust} fn main() { println!("Hello, World!"); }`
- **Shell**: `{shell} echo "Hello, World!"`
```

</x-tab>

<x-tab title="Preview">

- **Plain**: `printf("Hello, World")`
- **Python**: `{python} print("Hello, World")`
- **JavaScript**: `{javascript} console.log("Hello, World")`
- **HTML**: `{html} <h1>Hello, World!</h1>`
- **Rust** `{rust} fn main() { println!("Hello, World!"); }`
- **Shell**: `{shell} echo "Hello, World!"`

</x-tab>

</x-tabs>

### Code Blocks

Standard Markdown code blocks are also supported:

<x-tabs>

<x-tab title="Markdown" active>

````markdown
```python fibonacci.py
def fibonacci(n):
    fib_sequence = [0, 1]
    while len(fib_sequence) < n:
        fib_sequence.append(fib_sequence[-1] + fib_sequence[-2])
    return fib_sequence

# Example usage
print(fibonacci(10))  # Output: [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
```
````

</x-tab>

<x-tab title="Preview">

```python fibonacci.py
def fibonacci(n):
    fib_sequence = [0, 1]
    while len(fib_sequence) < n:
        fib_sequence.append(fib_sequence[-1] + fib_sequence[-2])
    return fib_sequence


# Example usage
print(fibonacci(10))  # Output: [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
```

</x-tab>

</x-tabs>

### Transformer

Check [@shikijs/transformers | Shiki](https://shiki.style/packages/transformers) for more details

Shiki支持通过标记为代码块设置 classes。例如，在注释中添加 `[!code--]`，Shiki 将为该改行代码对应的 span 元素中添加 `diff` class

| Type        | Mark                                |
| ----------- | ----------------------------------- |
| Diff-Remove | `{py} print(A) # [!code--]`         |
| Diff-Add    | `{py} print(A) # [!code++]`         |
| Highlight   | `{py} print(A) # [!code highlight]` |
| ...         | ...                                 |

####  Diff

<x-tabs>

<x-tab title="Markdown" sync-id="md" active>

````md
```ts
console.log("hewwo"); // [\!code --]
console.log("hello"); // [\!code ++]
console.log("goodbye"); // [\!code --]
```
````

</x-tab>

<x-tab title="Preview" sync-id="Preview">

```ts
console.log("hewwo"); // [!code --]
console.log("hello"); // [!code ++]
console.log("goodbye"); // [!code --]
```

</x-tab>

</x-tabs>

#### Highlight

<x-tabs>

<x-tab title="Markdown" sync-id="md" active>

````md
```ts
console.log("Not highlighted");
console.log("Highlighted"); // [\!code highlight]
console.log("Not highlighted");
```
````

</x-tab>

<x-tab title="Preview" sync-id="Preview">

```ts
console.log("Not highlighted");
console.log("Highlighted"); // [!code highlight]
console.log("Not highlighted");
```

</x-tab>

</x-tabs>

#### WordHighlight

<x-tabs>

<x-tab title="Markdown" sync-id="md" active>

````md
```ts
// [\!code word:Hello]
const message = "Hello World";
console.log(message); // prints Hello World
```
````

</x-tab>

<x-tab title="Preview" sync-id="Preview">

```ts
// [!code word:Hello]
const message = "Hello World";
console.log(message); // prints Hello World
```

</x-tab>

</x-tabs>

#### Focus

<x-tabs>

<x-tab title="Markdown" sync-id="md" active>

````md
```ts
console.log("Not focused");
console.log("Focused"); // [\!code focus]
console.log("Not focused");
```
````

</x-tab>

<x-tab title="Preview" sync-id="Preview">

```ts
console.log("Not focused");
console.log("Focused"); // [!code focus]
console.log("Not focused");
```

</x-tab>

</x-tabs>

#### ErrorLevel

<x-tabs>

<x-tab title="Markdown" sync-id="md" active>

````md
```ts
console.log("No errors or warnings");
console.error("Error"); // [\!code error]
console.warn("Warning"); // [\!code warning]
console.log('Info') // [\!code info]
```
````

</x-tab>

<x-tab title="Preview" sync-id="Preview">

```ts
console.log("No errors or warnings");
console.error("Error"); // [!code error]
console.warn("Warning"); // [!code warning]
console.log("Info"); // [!code info]
```

</x-tab>

</x-tabs>