代码块
所有代码块均使用 Expressive Code,并在 styles/custom.css 中定义了自定义样式。
JavaScript
Section titled “JavaScript”function fibonacci(n) { if (n <= 1) return n; return fibonacci(n - 1) + fibonacci(n - 2);}
console.log(fibonacci(10)); // 55Python
Section titled “Python”def fibonacci(n: int) -> int: if n <= 1: return n return fibonacci(n - 1) + fibonacci(n - 2)
print(fibonacci(10)) # 55#!/bin/bashfor i in $(seq 1 5); do echo "Iteration $i"donesite: title: Documentation base: / integrations: - starlight - react{ "name": "@f5-sales-demo/docs-theme", "version": "1.0.0", "type": "module", "main": "index.js"}<!DOCTYPE html><html lang="en"> <head> <meta charset="UTF-8" /> <title>Test Page</title> </head> <body> <h1>Hello World</h1> </body></html>:root { --sl-color-accent: #f06680; --sl-font: "proximaNova", system-ui;}
h1 { font-family: var(--sl-font-heading); font-weight: 700;}TypeScript
Section titled “TypeScript”interface Config { title: string; base: string; plugins: string[];}
const config: Config = { title: "Documentation", base: "/", plugins: ["starlight", "react"],};终端风格的代码块(使用 ```bash 或 ```sh 围栏)会呈现受 iTerm 启发的窗口边框,并带有 macOS 交通灯圆点。
npm install @f5-sales-demo/docs-themenpx astro buildnpx astro preview终端 CSS 参考
Section titled “终端 CSS 参考”/* 边框 */.expressive-code .frame.is-terminal { border: 2px solid rgba(255, 255, 255, 0.15);}
/* 带有交通灯 SVG 圆点的深色标题栏 */.expressive-code .frame.is-terminal .header { background: #323232 !important; color: #ccc !important;}
/* 深色模式终端主体 — 受 Tokyo Night 启发 */:root:not([data-theme="light"]) .expressive-code .frame.is-terminal pre { background: #1a1b26 !important;}
/* 浅色模式边框覆盖 */:root[data-theme="light"] .expressive-code .frame.is-terminal { border-color: rgba(0, 0, 0, 0.2);}export default { site: "https://example.com", title: "My Docs",};const name = "highlighted"; // 第 1 行高亮const other = "normal";const a = 1; // 第 3-5 行高亮const b = 2;const c = 3;const d = "normal again";插入与删除行
Section titled “插入与删除行”const config = { theme: "dark", // 插入 theme: "light", // 删除 lang: "en",};const oldValue = "deprecated";const newValue = "replacement";const unchanged = "stays";removeThis();addThis();CSS 参考
Section titled “CSS 参考”所有代码块均具有圆角和多层阴影:
.expressive-code .frame { --header-border-radius: 0.75rem; border-radius: 0.75rem; overflow: hidden; box-shadow: 0 2px 4px rgba(0,0,0,0.04), 0 8px 16px rgba(0,0,0,0.08), 0 24px 48px rgba(0,0,0,0.12);}主题感知边框
Section titled “主题感知边框”/* 深色模式(默认) */.expressive-code .frame.is-terminal { border: 2px solid rgba(255, 255, 255, 0.15);}
/* 浅色模式 */:root[data-theme="light"] .expressive-code .frame.is-terminal { border-color: rgba(0, 0, 0, 0.2);}- 代码块背景色随主题自适应
- 终端标题栏背景色为
#323232,并带有 macOS 交通灯圆点 - 终端边框在深色模式下使用
rgba(255, 255, 255, 0.15),在浅色模式下使用rgba(0, 0, 0, 0.2) - 深色模式终端主体使用
#1a1b26 - 语法颜色在两种主题下均保持可读性
- 行高亮具有可见的背景色调
- 插入行显示绿色色调,删除行显示红色色调
- 代码块具有 0.75rem 圆角半径和盒阴影