这篇文章汇总本站代码块的全部功能。除了工具栏的交互按钮外,大多数能力是写作语法——不需要任何配置,围栏代码块里直接用就行。

文件名标题

语言围栏后加 title="文件名",标题栏就显示文件名(代替语言名):

server.ts
import { createServer } from "node:http";
createServer((req, res) => {
res.writeHead(200, { "content-type": "text/plain" });
res.end("hello world\n");
}).listen(8080);

文本标记

在代码行末尾用 // [!code ...] 注释打标记:

ts
function fetchUser(id: number) {
if (id <= 0) {
return Promise.reject(new Error("invalid id")); // [!code error]
}
return fetch(`/api/users/${id}`).then((r) => r.json()); // [!code highlight]
}
标记含义
[!code highlight]高亮该行
[!code ++] / [!code --]diff 新增 / 删除
[!code warn]警告(黄色)
[!code error]错误(红色)
[!code mark]默认标记色

Diff 视图

直接声明 diff 语言即可:

diff
const port = 8080;
const port = Number(process.env.PORT ?? 8080);

终端窗口

bash / sh / zsh / shell 等语言自动渲染成终端窗口(带红绿灯标题栏):

bash
$ ssh netcup
Last login: Tue Aug 11 13:00:00 2026 from 113.13.73.128
Welcome to netcup-piko-g11s!
$ uptime
13:00:01 up 42 days, 3:21, 1 user, load average: 0.04, 0.02, 0.00

超长代码块自动折叠

超过 18 行的代码块默认收起,点击工具栏的折叠按钮(或底部的渐隐处)展开:

python
def sieve_of_eratosthenes(limit):
"""埃拉托斯特尼筛法:找出所有小于 limit 的质数。"""
if limit < 2:
return []
is_prime = [True] * (limit + 1)
is_prime[0] = is_prime[1] = False
for p in range(2, int(limit ** 0.5) + 1):
if is_prime[p]:
for multiple in range(p * p, limit + 1, p):
is_prime[multiple] = False
return [i for i, is_prime in enumerate(is_prime) if is_prime[i]]
def main():
primes = sieve_of_eratosthenes(100)
print(f"100 以内的质数共 {len(primes)} 个:")
print(primes)
if __name__ == "__main__":
main()

多语言标签页

tabs 块把同一段逻辑的不同语言实现并排切换:

const greet = (name) => `你好,${name}`;
console.log(greet("晴空"));

工具栏

每个代码块右上角有一排工具:行号(默认开)、换行、折叠、全屏(ESC 退出)、复制。桌面端复制按钮与其余按钮统一为纯图标;移动端保留 40px 触控目标。

行内代码

行内代码 与文件路径 server.ts 用同一种带边框的样式,鼠标悬停有强调色。

以上就是全部。写文章时按需取用,零配置。