程式碼區塊
所有程式碼區塊均使用 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);}檔案名稱標題
Section titled “檔案名稱標題”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 圓角及盒陰影