From c4990101da249c567dcf8e1f6b1dab0a1e9d82d8 Mon Sep 17 00:00:00 2001 From: Han Xiao Date: Mon, 30 Nov 2026 22:15:30 +0900 Subject: [PATCH 1/2] docs(landing): document highlighted capabilities code visuals Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01E5Vqiif7kfNNiDDMaM1B6r --- content/docs/customize/home.md | 14 ++++++++++++++ content/docs/customize/home.zh.md | 13 +++++++++++++ content/docs/design/landing.md | 5 +++++ content/docs/design/landing.zh.md | 4 ++++ 4 files changed, 36 insertions(+) diff --git a/content/docs/customize/home.md b/content/docs/customize/home.md index d5df0089..77be23b1 100644 --- a/content/docs/customize/home.md +++ b/content/docs/customize/home.md @@ -244,6 +244,20 @@ capabilities: - { class: ok, prefix: '✓ ', text: listening on :5433 } ``` +A `code` visual shows either `lines`, where `class` colours only each line's +`prefix`, or `code` with `lang`, which Chroma highlights as in `code-plate`. +Give one of the two: + +```yaml {title="data/home/en.yaml"} + visual: + type: code + title: Python + lang: python + code: | + import acme + db = acme.connect("localhost:5433") +``` + > [!DETAILS] Minimal YAML for eleven more sections > > ```yaml diff --git a/content/docs/customize/home.zh.md b/content/docs/customize/home.zh.md index f0e44085..ee84096f 100644 --- a/content/docs/customize/home.zh.md +++ b/content/docs/customize/home.zh.md @@ -211,6 +211,19 @@ capabilities: - { class: ok, prefix: '✓ ', text: 正在监听 :5433 } ``` +`code` 面板二选一:`lines` 逐行书写,`class` 只给该行的 `prefix` 上色;或者写 +`code` 加 `lang`,像 `code-plate` 一样交给 Chroma 高亮: + +```yaml {title="data/home/zh.yaml"} + visual: + type: code + title: Python + lang: python + code: | + import acme + db = acme.connect("localhost:5433") +``` + > [!DETAILS] 另外十一种分区的最小 YAML > > ```yaml diff --git a/content/docs/design/landing.md b/content/docs/design/landing.md index 3800ce37..2bdd9dfb 100644 --- a/content/docs/design/landing.md +++ b/content/docs/design/landing.md @@ -88,6 +88,11 @@ lines and scroll them with arrow keys without relying on a browser's implicit scroll-container focus behavior. Static Print output adds no focus target to these line-based renderers. +A `capabilities` code visual takes exactly one of `lines` or `code`. With +`code` it is highlighted by `transform.Highlight` with `lang` (default +`text`), the same path as `code-plate`; with both or neither it warns and +drops the visual while the item keeps its text. + Marquee duplication uses only CSS. The duplicate is `aria-hidden` and `inert`. A localized checkbox preserves pause state without JS. Reduced motion disables animation. Forced colors preserve controls. Theme images follow the shared theme event. diff --git a/content/docs/design/landing.zh.md b/content/docs/design/landing.zh.md index b417aed7..809f27fb 100644 --- a/content/docs/design/landing.zh.md +++ b/content/docs/design/landing.zh.md @@ -86,6 +86,10 @@ i18n。 浏览器自动把滚动容器加入焦点顺序。这两种逐行渲染器不为静态 Print 输出添加 焦点入口。 +`capabilities` 的代码视图只接受 `lines` 与 `code` 之一。写 `code` 时按 `lang` +(默认 `text`)经 `transform.Highlight` 高亮,与 `code-plate` 走同一路径;两者都写 +或都不写时给出警告并丢弃该视图,条目文字照常保留。 + 跑马灯只用 CSS 复制;副本带 `aria-hidden` 与 `inert`,本地化复选框无需 JavaScript 也能持久保存暂停状态。减少动画会停用动画,强制颜色保留控件,主题 图片响应共享主题事件。顶部导航栏的 mega 面板与其 `columns` 参数已退役:仍然配置 `columns` 的菜单会告警并保持单列。紧凑菜单使用真实链接 From 759d5816b4bc5e1ad98b8ea0d978e951d5487fa0 Mon Sep 17 00:00:00 2001 From: Feng Ruohang Date: Tue, 1 Dec 2026 19:06:04 +0800 Subject: [PATCH 2/2] test(landing): verify syntax colours, keyboard access and print --- content/docs/customize/home.md | 6 +- content/docs/customize/home.zh.md | 4 +- content/docs/design/architecture.md | 2 +- content/docs/design/architecture.zh.md | 2 +- content/docs/design/landing.md | 22 ++++--- content/docs/design/landing.zh.md | 16 ++--- tests/browser/landing-code-focus.spec.mjs | 61 ++++++++++++++++++- .../browser/content/landing-code-focus.md | 12 ++++ .../browser/content/landing-code-focus.zh.md | 12 ++++ .../browser/content/landing-code-shell.md | 6 ++ .../browser/layouts/landing-code-shell.html | 17 ++++++ 11 files changed, 132 insertions(+), 28 deletions(-) create mode 100644 tests/fixtures/browser/content/landing-code-shell.md create mode 100644 tests/fixtures/browser/layouts/landing-code-shell.html diff --git a/content/docs/customize/home.md b/content/docs/customize/home.md index 77be23b1..56ed056f 100644 --- a/content/docs/customize/home.md +++ b/content/docs/customize/home.md @@ -244,9 +244,9 @@ capabilities: - { class: ok, prefix: '✓ ', text: listening on :5433 } ``` -A `code` visual shows either `lines`, where `class` colours only each line's -`prefix`, or `code` with `lang`, which Chroma highlights as in `code-plate`. -Give one of the two: +For a terminal session, use `lines` to colour the prompt or status prefix of +each line. With the development theme, paste a source snippet into a YAML +block string and set `lang` to its language. Omit `lang` for plain text. ```yaml {title="data/home/en.yaml"} visual: diff --git a/content/docs/customize/home.zh.md b/content/docs/customize/home.zh.md index ee84096f..b4afdc8f 100644 --- a/content/docs/customize/home.zh.md +++ b/content/docs/customize/home.zh.md @@ -211,8 +211,8 @@ capabilities: - { class: ok, prefix: '✓ ', text: 正在监听 :5433 } ``` -`code` 面板二选一:`lines` 逐行书写,`class` 只给该行的 `prefix` 上色;或者写 -`code` 加 `lang`,像 `code-plate` 一样交给 Chroma 高亮: +展示终端会话时,用 `lines` 为每行的提示符或状态前缀上色。使用开发版主题时,可以把整段源码贴进 +`code` 的 YAML 文本块,填写语言 `lang` 即可高亮。省略 `lang` 时按纯文本展示。 ```yaml {title="data/home/zh.yaml"} visual: diff --git a/content/docs/design/architecture.md b/content/docs/design/architecture.md index 6a34f2f0..5cdf3e94 100644 --- a/content/docs/design/architecture.md +++ b/content/docs/design/architecture.md @@ -164,7 +164,7 @@ as `css/.css`. An unknown name warns. | `main` | Every theme page; 123 layers. `head-css.html` publishes it as `css/main.css`, or minified, fingerprinted and with an integrity attribute in production | | `redoc.css` | Pages that register ReDoc. It is the single file `assets/css/td/redoc.css`, outside the layer lists, published the same way as `css/redoc.css` | | `chrome` | A site-owned shell that does not load `main`: tokens, typography, the six palettes, the site navbar, and the language, theme and appearance controls | -| `landing` | Landing sections for a site-owned shell, loaded after `chrome`. It repeats the palettes, because they restyle Landing sections at equal specificity and must follow them | +| `landing` | Landing sections for a site-owned shell, loaded after `chrome`. The development version includes the dark Chroma palette for source panels. The visual presets follow the sections so their equal-specificity overrides take effect | | `search`, `compare` | The command palette with local search, and Duo View, for a site-owned shell | The four smaller stylesheets have no source of their own: each lists layers diff --git a/content/docs/design/architecture.zh.md b/content/docs/design/architecture.zh.md index b62ac074..c9c68d64 100644 --- a/content/docs/design/architecture.zh.md +++ b/content/docs/design/architecture.zh.md @@ -138,7 +138,7 @@ Bootstrap 组件拆分:其中带有主题的调色板,与某条 Bootstrap | `main` | 所有主题页面,共 123 层。`head-css.html` 把它发布为 `css/main.css`;生产构建中压缩、加指纹并带完整性属性 | | `redoc.css` | 登记了 ReDoc 的页面。它是单独的一个文件 `assets/css/td/redoc.css`,不在各层清单之内,按同样方式发布为 `css/redoc.css` | | `chrome` | 不加载 `main` 的站点自有外壳:令牌、排版、六套配色、站点导航栏,以及语言、明暗与外观控件 | -| `landing` | 站点自有外壳使用的 Landing 区块,在 `chrome` 之后加载。它重复了配色规则,因为配色以同等优先级改写 Landing 区块,必须排在其后 | +| `landing` | 站点自有外壳使用的 Landing 区块,在 `chrome` 之后加载。开发版为源码面板附带 Chroma 深色语法配色。视觉预设排在区块规则之后,以便同等优先级的覆盖生效 | | `search`、`compare` | 站点自有外壳使用的命令面板与本地搜索,以及双列视图 | 四份较小的样式表没有自己的源码:它们列出的每一层 `main` 也都加载。站点布局 diff --git a/content/docs/design/landing.md b/content/docs/design/landing.md index 2bdd9dfb..04256488 100644 --- a/content/docs/design/landing.md +++ b/content/docs/design/landing.md @@ -82,16 +82,18 @@ Server output stays complete without JavaScript or if the Landing script fails t Reveal candidates are initially visible; only an installed observer may mark one as pending entrance animation. The server renders metrics with configured number formatting, prefixes, and suffixes, and the count-up's final frame uses the same display. -Landing code plates accept keyboard focus in interactive HTML, including -`capabilities` code visuals and `code-plate` line lists. Readers can tab to long -lines and scroll them with arrow keys without relying on a browser's implicit -scroll-container focus behavior. Static Print output adds no focus target to -these line-based renderers. - -A `capabilities` code visual takes exactly one of `lines` or `code`. With -`code` it is highlighted by `transform.Highlight` with `lang` (default -`text`), the same path as `code-plate`; with both or neither it warns and -drops the visual while the item keeps its text. +In interactive HTML, readers can tab to a `capabilities` or `code-plate` code +panel and use the arrow keys to scroll long lines. In the static Print output +both panels show the source as plain text and stay out of the tab order. + +The development version adds `code` to the `capabilities` code visual alongside +the `lines` form available in 1.8.0. Choose exactly one. Use +`lines` for per-line prefixes or a nonblank `code` string for source highlighted +by Hugo at build time. Both the full theme and the `chrome` plus `landing` +stylesheets provide the dark syntax palette. The optional `lang` defaults to +`text`. A non-string language warns and uses plain text. Missing or conflicting +inputs and blank or non-string source warn and drop the visual. The item keeps +its title, text and links. Marquee duplication uses only CSS. The duplicate is `aria-hidden` and `inert`. A localized checkbox preserves pause state without JS. diff --git a/content/docs/design/landing.zh.md b/content/docs/design/landing.zh.md index 809f27fb..e329dea0 100644 --- a/content/docs/design/landing.zh.md +++ b/content/docs/design/landing.zh.md @@ -81,14 +81,14 @@ i18n。 出现动画的候选元素默认可见,只有成功安装观察器后才标记为等待动画。数字指标 由服务端按配置输出完整的数字格式、前缀和后缀,递增动画的最后一帧使用同一显示文本。 -交互式 HTML 中的代码面板可通过键盘聚焦,包括 `capabilities` 的代码视图与 -`code-plate` 的逐行代码。读者可以用 Tab 进入长行区域,再用方向键滚动,不依赖 -浏览器自动把滚动容器加入焦点顺序。这两种逐行渲染器不为静态 Print 输出添加 -焦点入口。 - -`capabilities` 的代码视图只接受 `lines` 与 `code` 之一。写 `code` 时按 `lang` -(默认 `text`)经 `transform.Highlight` 高亮,与 `code-plate` 走同一路径;两者都写 -或都不写时给出警告并丢弃该视图,条目文字照常保留。 +在交互式 HTML 中,读者可以用 Tab 聚焦 `capabilities` 或 `code-plate` 的代码面板, +再用方向键横向滚动长行。静态 Print 输出以纯文本显示源码,代码面板不占用 Tab 焦点。 + +开发版在 1.8.0 已有的 `lines` 之外,为 `capabilities` 代码面板增加了 `code`,两种写法二选一。用 `lines` 给每行的前缀上色, +用非空白的 `code` 字符串展示由 Hugo 在构建时高亮的源码。完整主题和仅加载 +`chrome`、`landing` 样式表的站点外壳都提供深色语法配色。可选的 `lang` 默认是 +`text`,类型有误时告警并按纯文本展示。两个输入都没填、同时填写,或 `code` 为空白 +或非字符串时,构建会告警并略过该面板,条目的标题、文字和链接照常显示。 跑马灯只用 CSS 复制;副本带 `aria-hidden` 与 `inert`,本地化复选框无需 JavaScript 也能持久保存暂停状态。减少动画会停用动画,强制颜色保留控件,主题 diff --git a/tests/browser/landing-code-focus.spec.mjs b/tests/browser/landing-code-focus.spec.mjs index 2261ab98..46968c6f 100644 --- a/tests/browser/landing-code-focus.spec.mjs +++ b/tests/browser/landing-code-focus.spec.mjs @@ -3,6 +3,7 @@ import { expect, test } from '@playwright/test'; const regions = [ ['#capability-code', 'h3 a'], + ['#syntax-code', 'h3 a'], ['#plain-lines', 'h2 a'], ['#highlighted-code', 'h2 a'], ]; @@ -42,12 +43,66 @@ for (const width of [360, 1440]) { } for (const language of ['', '/zh']) { - test(`${language || '/en'} Print line renderers remain static`, async ({ page }) => { + test(`${language || '/en'} Print code panels remain static`, async ({ page }) => { await page.goto(`${language}/_print/tests/landing-code-focus/`); - for (const selector of ['#capability-code pre', '#plain-lines pre']) { - const pre = page.locator(selector); + for (const [selector] of regions) { + const pre = page.locator(selector).locator('pre'); await expect(pre).toHaveCount(1); await expect(pre).not.toHaveAttribute('tabindex'); } + await expect(page.locator('#syntax-code pre code')).toContainText('import pystac\ncatalog ='); + await page.emulateMedia({ media: 'print' }); + const ink = await page.locator('#syntax-code pre code').evaluate(el => ({ + text: getComputedStyle(el).color, + paper: getComputedStyle(el.closest('.td-landing-codeplate')).backgroundColor, + fits: el.parentElement.scrollWidth <= el.parentElement.clientWidth + 1, + })); + expect(contrastRatio(ink.text, ink.paper)).toBeGreaterThanOrEqual(4.5); + expect(ink.fits).toBe(true); }); } + +for (const route of ['landing-code-focus', 'landing-code-shell']) { + test(`${route} keeps syntax colours distinct and readable`, async ({ page }) => { + await page.goto(`/tests/${route}/`); + if (route === 'landing-code-shell') { + const styles = await page.locator('link[rel="stylesheet"]').evaluateAll(links => + links.map(link => new URL(link.href).pathname)); + expect(styles).toEqual(['/css/chrome.css', '/css/landing.css']); + } + const plate = page.locator('#syntax-code .td-landing-codeplate'); + await expect(plate.locator('.kn')).toHaveText('import'); + for (const preset of ['paper', 'slate', 'github', 'ink', 'news', 'terminal']) { + for (const mode of ['light', 'dark']) { + const { keyword, name, string, background } = await plate.evaluate((el, appearance) => { + document.documentElement.dataset.tdPreset = appearance.preset; + document.documentElement.dataset.bsTheme = appearance.mode; + const colour = selector => getComputedStyle(el.querySelector(selector)).color; + return { + keyword: colour('.kn'), name: colour('.n'), string: colour('.s2'), + background: getComputedStyle(el).backgroundColor, + }; + }, { preset, mode }); + const context = `${preset}/${mode}`; + expect(new Set([keyword, name, string]).size, context).toBe(3); + for (const ink of [keyword, name, string]) { + expect(contrastRatio(ink, background), `${context} ${ink} on ${background}`).toBeGreaterThanOrEqual(4.5); + } + } + } + }); +} + +function contrastRatio(foreground, background) { + function luminance(rgb) { + const [, red, green, blue] = /^rgb\((\d+), (\d+), (\d+)\)$/.exec(rgb); + const linear = channel => { + const value = Number(channel) / 255; + return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4; + }; + return 0.2126 * linear(red) + 0.7152 * linear(green) + 0.0722 * linear(blue); + } + const a = luminance(foreground); + const b = luminance(background); + return (Math.max(a, b) + 0.05) / (Math.min(a, b) + 0.05); +} diff --git a/tests/fixtures/browser/content/landing-code-focus.md b/tests/fixtures/browser/content/landing-code-focus.md index ee29bb0a..2b1e93c4 100644 --- a/tests/fixtures/browser/content/landing-code-focus.md +++ b/tests/fixtures/browser/content/landing-code-focus.md @@ -19,6 +19,18 @@ sections: title: Capability code lines: - {prefix: '$ ', text: 'python3 -m http.server 8080 --bind 127.0.0.1 --directory /srv/repo --package-snapshot stable-2026-10-15 --manifest /srv/repo/snapshots/current/verified-package-manifest.json'} + - type: capabilities + id: syntax-code + data: + items: + - title: '[Source example](#syntax-code)' + visual: + type: code + title: Python + lang: python + code: | + import pystac + catalog = pystac.Catalog.from_file("https://example.org/archives/observations/weather-models/global-forecast-system/reference-runs/2026/11/catalog.json") - type: code-plate id: plain-lines data: diff --git a/tests/fixtures/browser/content/landing-code-focus.zh.md b/tests/fixtures/browser/content/landing-code-focus.zh.md index 8b19d278..a2dbeb75 100644 --- a/tests/fixtures/browser/content/landing-code-focus.zh.md +++ b/tests/fixtures/browser/content/landing-code-focus.zh.md @@ -19,6 +19,18 @@ sections: title: 能力区块代码 lines: - {prefix: '$ ', text: 'python3 -m http.server 8080 --bind 127.0.0.1 --directory /srv/repo --package-snapshot stable-2026-10-15 --manifest /srv/repo/snapshots/current/verified-package-manifest.json'} + - type: capabilities + id: syntax-code + data: + items: + - title: '[源码示例](#syntax-code)' + visual: + type: code + title: Python + lang: python + code: | + import pystac + catalog = pystac.Catalog.from_file("https://example.org/archives/observations/weather-models/global-forecast-system/reference-runs/2026/11/catalog.json") - type: code-plate id: plain-lines data: diff --git a/tests/fixtures/browser/content/landing-code-shell.md b/tests/fixtures/browser/content/landing-code-shell.md new file mode 100644 index 00000000..eb9b414e --- /dev/null +++ b/tests/fixtures/browser/content/landing-code-shell.md @@ -0,0 +1,6 @@ +--- +title: Landing code in a custom shell +layout: landing-code-shell +outputs: [HTML] +search_exclude: true +--- diff --git a/tests/fixtures/browser/layouts/landing-code-shell.html b/tests/fixtures/browser/layouts/landing-code-shell.html new file mode 100644 index 00000000..574fad6e --- /dev/null +++ b/tests/fixtures/browser/layouts/landing-code-shell.html @@ -0,0 +1,17 @@ + + + + + + {{ .Title }} + {{ range slice "chrome" "landing" }}{{ with partial "css/bundle.html" . }} + + {{ end }}{{ end }} + + +
+ {{ with site.GetPage "/tests/landing-code-focus" }}{{ partial "landing/render.html" + (dict "page" $ "data" (partial "landing/data.html" .)) }}{{ end }} +
+ +