CCM

Back

📌 自定义插件#

Focus 插件#

使用 focus={3-5} 参数或行内 // [!focus] 注释,指定行高亮聚焦,其他行淡化:

function calculateTotal(items) {
let total = 0
for (const item of items) { // ← 第3行 聚焦
total += item.price * item.quantity // ← 第4行 聚焦
} // ← 第5行 聚焦
return total
}

行内注释方式(// [!focus] 会被自动移除):

function processData(data) {
const validated = validateInput(data)
const transformed = transformData(validated)
const result = saveToDatabase(transformed)
return result
}

Python 风格(# [!focus]):

def calculate_fibonacci(n):
if n <= 1:
return n
a, b = 0, 1
for _ in range(2, n + 1):
a, b = b, a + b
return b

Footnotes 插件#

使用 // [!note:N] 注释内容 添加代码脚注:

import express from 'express'1️⃣
import cors from 'cors'3️⃣
const app = express()2️⃣
app.use(cors())
app.use(express.json())4️⃣
app.listen(3000)
  • 1️⃣Express Web 框架
  • 2️⃣创建实例
  • 3️⃣跨域处理
  • 4️⃣解析 JSON

自动编号(// [!note] 不指定编号):

import pandas as pd1️⃣
import numpy as np2️⃣
df = pd.read_csv('data.csv')3️⃣
df['norm'] = df['value'] / df['value'].max()4️⃣
print(df.head())
  • 1️⃣Pandas 数据分析库
  • 2️⃣NumPy 数组计算
  • 3️⃣读取 CSV 文件
  • 4️⃣归一化处理

📌 原生功能演示#

基础代码块#

site.css
.flex {
display: flex;
}
// Line numbers are disabled for this block
console.log('Hello?')
console.log('Sorry, do you know what line I am on?')

折叠代码块#

5 collapsed lines
// All this boilerplate setup code will be collapsed
import { someBoilerplateEngine } from '@example/some-boilerplate'
import { evenMoreBoilerplate } from '@example/even-more-boilerplate'
const engine = someBoilerplateEngine(evenMoreBoilerplate())
// This part of the code will be visible by default
engine.doSomething(1, 2, 3, calcFn)
function calcFn() {
// You can have multiple collapsed sections
3 collapsed lines
const a = 1
const b = 2
const c = a + b
// This will remain visible
console.log(`Calculation result: ${a} + ${b} = ${c}`)
return c
}
4 collapsed lines
// All this code until the end of the block will be collapsed again
engine.closeConnection()
engine.freeMemory()
engine.shutdown({ reason: 'End of example boilerplate code' })

行高亮标记#

// Line 1 - targeted by line number
// Line 2
// Line 3
// Line 4 - targeted by line number
// Line 5
// Line 6
// Line 7 - targeted by range "7-8"
// Line 8 - targeted by range "7-8"

带标签的行标记#

labeled-line-markers.jsx
<button
role="button"
{...props}
value={value}
className={buttonClassName}
disabled={disabled}
active={active}
>
{children &&
!active &&
(typeof children === 'string' ? <span>{children}</span> : children)}
</button>

行号控制#

// This code block will show line numbers
console.log('Greetings from line 2!')
console.log('I am on line 3')
// Line numbers are disabled for this block
console.log('Hello?')
console.log('Sorry, do you know what line I am on?')

多语言示例#

site
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
site
name: HelloWorld
description: A simple Java program
version: 1.0.0
mainClass: HelloWorld
dependencies:
- java: 11
Terminal window
fatal: refusing to merge unrelated histories
site.json
{
"name": "HelloWorld",
"description": "A simple Java program",
"version": "1.0.0",
"mainClass": "HelloWorld",
"dependencies": {
"java": "11"
}
}
site.py
def hello_world():
print("Hello, World!")

ANSI 颜色#

Terminal window
[1;4mStandard ANSI colors:[0m
- Dimmed: [2;30m Black [2;31m Red [2;32m Green [2;33m Yellow [2;34m Blue [2;35m Magenta [2;36m Cyan [2;37m White [0m
- Foreground: [30m Black [31m Red [32m Green [33m Yellow [34m Blue [35m Magenta [36m Cyan [37m White [0m
- Background: [40m Black [41m Red [42m Green [43m Yellow [44m Blue [45m Magenta [46m Cyan [47m White [0m
- Reversed: [7;30m Black [7;31m Red [7;32m Green [7;33m Yellow [7;34m Blue [7;35m Magenta [7;36m Cyan [7;37m White [0m
.gitignore
.starlight-icons/*
!.starlight-icons/safelist.json
app.ts
console.log('hi')
建站: code highlight by expressive-code
https://8cat.life/blog/t3.html
ccm Author ccm
Published at 2025/08/12