diff --git a/CHANGELOG.md b/CHANGELOG.md index 429091ab..aec59284 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,16 @@ sites keep the `github.com/pgsty/oink` module path instead of moving to a `/v2` path. Version 1.6.0 retired several in this way, and 1.8.0 replaces the `social` shortcode of 1.7.0 with a callout. A patch release only fixes. +## Unreleased + +### Added + +- **Highlighted `capabilities` code visuals.** A `visual.type: code` panel + takes `code` and `lang` as `code-plate` does, and Chroma highlights it. + `lines` keeps its per-line prefix colours. Conflicting inputs and missing, + blank or non-string source warn and drop the visual. Print shows the source + as plain text. Custom shells get the dark syntax palette in the Landing stylesheet. + ## [1.8.0] — 2026-11-28 Paper looks as it did in 1.6.0 again. Its 1.7.0 refresh grows into a preset diff --git a/assets/css/td/landing.css b/assets/css/td/landing.css index 0d0b65ad..eeca87f1 100644 --- a/assets/css/td/landing.css +++ b/assets/css/td/landing.css @@ -804,6 +804,7 @@ .td-landing-codeplate pre { margin: 0; padding: clamp(20px, 4vw, 34px); + overflow-x: auto; border: 0; background: transparent; color: #c9d6e8; @@ -812,15 +813,15 @@ line-height: 1.9; } -.td-landing-codeplate .c { - color: #64748b; +.td-landing-codeplate pre > code > .c { + color: #94a3b8; } -.td-landing-codeplate .p { +.td-landing-codeplate pre > code > .p { color: #7fd39a; } -.td-landing-codeplate .ok { +.td-landing-codeplate pre > code > .ok { color: #55c98a; } @@ -2184,11 +2185,11 @@ max-width: 920px; } -.td-landing-code-plate-section .td-landing-codeplate .highlight, -.td-landing-code-plate-section .td-landing-codeplate .chroma { +.td-landing-codeplate[data-bs-theme='dark'] :is(.highlight, .chroma) { margin: 0; border: 0; background: transparent; + color: #c9d6e8; } /* `preview`: the Markdown an author writes beside what the theme renders @@ -2682,6 +2683,22 @@ } @media print { + .td-landing-codeplate { + background: #fff; + box-shadow: none; + } + .td-landing-codeplate[data-bs-theme='dark'] :is(pre, code, span, b) { + color: var(--td-print-ink, #171717) !important; + } + .td-landing-codeplate pre, + .td-landing-codeplate pre > code { + white-space: pre-wrap; + overflow-wrap: anywhere; + overflow: visible; + } + .td-landing-codeplate .chroma .line { + display: block; + } .td-landing-marquee { overflow: visible; mask-image: none; diff --git a/bin/check-landing.py b/bin/check-landing.py index e8a93e5a..624c0f12 100755 --- a/bin/check-landing.py +++ b/bin/check-landing.py @@ -372,6 +372,8 @@ def create_site(root: Path, landing_data: str, *, language: str = "en") -> None: ("zero-capabilities-columns", "sections:\n - type: capabilities\n data:\n items:\n - title: Bad\n visual:\n type: components\n columns: 0\n items: [{title: A, icon: fa-solid fa-star}]\n", "capabilities visual columns must be at least 1"), ("bad-capabilities-rules", "sections:\n - type: capabilities\n data:\n items:\n - title: Bad\n visual:\n type: shell\n rules: not-a-list\n", "rules must be an array"), ("bad-capabilities-rule-width", "sections:\n - type: capabilities\n data:\n items:\n - title: Bad\n visual:\n type: shell\n rules: ['88%', 'nope']\n", "is not a CSS length"), + ("capabilities-code-and-lines", "sections:\n - type: capabilities\n data:\n items:\n - title: Bad\n visual:\n type: code\n lang: python\n code: print(1)\n lines: [{text: print(1)}]\n", "code visual requires exactly one of code or lines"), + ("capabilities-code-empty", "sections:\n - type: capabilities\n data:\n items:\n - title: Bad\n visual: {type: code, title: Empty}\n", "code visual requires exactly one of code or lines"), ("bad-marquee-rows", "sections:\n - type: logo-wall\n data:\n layout: marquee\n rows: nope\n items: [{title: Logo}]\n", 'marquee rows "nope" is not a whole number'), ) @@ -395,6 +397,9 @@ def check_invalid(hugo: str) -> list[str]: require(page.is_file(), f"invalid landing case {name} emitted no safe page output", errors) if page.is_file(): rendered = page.read_text(encoding="utf-8") + if name.startswith("capabilities-code-"): + require("td-landing-codeplate" not in rendered and "

Bad

" in rendered, + f"{name} must drop only the invalid visual and keep its item", errors) if name == "bad-preview-source": require("td-landing-preview-section" not in rendered, "non-string preview.source still rendered its section", errors) @@ -648,6 +653,64 @@ def check_code_focus(hugo: str) -> list[str]: return errors +def check_capabilities_highlight(hugo: str) -> list[str]: + """Exercise highlighted source, invalid inputs and static Print in the same item list.""" + errors: list[str] = [] + data = """sections: + - type: capabilities + data: + items: + - title: Python + visual: + type: code + title: Python + lang: python + code: | + import pystac + cat = pystac.Catalog.from_file("") + - title: Plain fallback + visual: {type: code, code: " a < b", lang: [python]} + - title: Map input + visual: {type: code, code: {foo: bar}} + - title: Null input + visual: {type: code, code: null} + - title: Blank input + visual: {type: code, code: " "} +""" + with tempfile.TemporaryDirectory(prefix="td-landing-capabilities-highlight-") as temp: + site = Path(temp) + create_site(site, data) + config = site / "hugo.yaml" + write(config, config.read_text().replace("page: [HTML]", "page: [HTML, print]")) + result = run(hugo, site) + if result.returncode != 0: + return [f"capabilities highlight fixture failed: {result.stdout}{result.stderr}"] + source = (site / "public/test/index.html").read_text(encoding="utf-8") + module = source.partition('
')[2].partition("
")[0] + require('class="chroma"' in module, + "capabilities code visual with code was not highlighted", errors) + require('data-lang="python"' in module or "language-python" in module, + "capabilities code visual lost its language", errors) + require('import' in module, + "capabilities code visual lost its Chroma tokens", errors) + diagnostics = result.stdout + result.stderr + for item, message in ((2, "visual.lang must be a string"), (3, "visual.code must be a string"), + (4, "visual.code must be a string"), (5, "visual.code must not be blank")): + require(f"capabilities item {item} {message}" in diagnostics, + f"capabilities item {item} lost its input diagnostic", errors) + printed = (site / "public/_print/test/index.html").read_text(encoding="utf-8") + for label, html in (("HTML", source), ("Print", printed)): + require(html.count('class="td-landing-codeplate"') == 2 and + all(title in html for title in ("Map input", "Null input", "Blank input")), + f"{label} must keep the invalid items' text and omit their plates", errors) + require("<catalog>" in html and " a < b" in html, + f"{label} lost escaped source or indentation", errors) + require('
import pystac' in printed and
+                all("tabindex=" not in tag for tag in re.findall(r"]*>", printed)),
+                "Print must preserve source without an interactive focus target", errors)
+    return errors
+
+
 def check_rss(hugo: str) -> list[str]:
     errors: list[str] = []
     with tempfile.TemporaryDirectory(prefix="td-landing-components-landing-rss-") as temp:
@@ -877,6 +940,7 @@ def main() -> int:
         + check_rss(args.hugo)
         + check_markdown_scopes(args.hugo)
         + check_code_focus(args.hugo)
+        + check_capabilities_highlight(args.hugo)
         + check_capabilities_preset_buttons(args.hugo)
     )
     if errors:
diff --git a/layouts/_partials/css/layers.html b/layouts/_partials/css/layers.html
index b1c3f5c2..d66aebeb 100644
--- a/layouts/_partials/css/layers.html
+++ b/layouts/_partials/css/layers.html
@@ -54,7 +54,7 @@
     "appearance" "presets" "experimental-presets"
   )
   "landing" (slice
-    "charset" "landing" "presets" "experimental-presets"
+    "charset" "chroma/dark" "chroma/theme-dark" "landing" "presets" "experimental-presets"
   )
   "search" (slice
     "charset" "shell/search"
diff --git a/layouts/_partials/landing/highlight-code.html b/layouts/_partials/landing/highlight-code.html
new file mode 100644
index 00000000..2a97a922
--- /dev/null
+++ b/layouts/_partials/landing/highlight-code.html
@@ -0,0 +1,14 @@
+{{- $source := strings.TrimRight "\r\n" .code -}}
+{{- $lang := "text" -}}
+{{- if isset .data "lang" -}}
+  {{- if eq (printf "%T" .data.lang) "string" -}}
+    {{- $lang = strings.TrimSpace .data.lang | default "text" -}}
+  {{- else -}}
+    {{- warnf "%s.lang must be a string; using plain text" .position -}}
+  {{- end -}}
+{{- end -}}
+{{- if .interactive -}}
+  {{- transform.Highlight $source $lang (dict "noClasses" false) -}}
+{{- else -}}
+  
{{ $source }}
+{{- end -}} diff --git a/layouts/_partials/landing/sections/capabilities.html b/layouts/_partials/landing/sections/capabilities.html index 22a8c84d..811f1e31 100644 --- a/layouts/_partials/landing/sections/capabilities.html +++ b/layouts/_partials/landing/sections/capabilities.html @@ -30,10 +30,21 @@

{{- if not (in (slice "code" "shell" "components" "image" "card") $visualType) -}} {{- warnf "%s: capabilities item %d has unsupported visual.type %q; dropping the visual" $page.Path (add $index 1) $visualType -}} {{- end -}} - {{- if eq $visualType "code" }} + {{- $hasCode := isset . "code" -}}{{- $hasLines := isset . "lines" -}} + {{- if and (eq $visualType "code") (eq $hasCode $hasLines) -}} + {{- warnf "%s: capabilities item %d code visual requires exactly one of code or lines; dropping the visual" $page.Path (add $index 1) -}} + {{- else if and (eq $visualType "code") $hasCode (ne (printf "%T" .code) "string") -}} + {{- warnf "%s: capabilities item %d visual.code must be a string; dropping the visual" $page.Path (add $index 1) -}} + {{- else if and (eq $visualType "code") $hasCode (not (strings.TrimSpace .code)) -}} + {{- warnf "%s: capabilities item %d visual.code must not be blank; dropping the visual" $page.Path (add $index 1) -}} + {{- else if eq $visualType "code" }}
{{ .title }}
+ {{- if $hasCode }} + {{- partial "landing/highlight-code.html" (dict "code" .code "data" . "interactive" $interactive "position" (printf "%s: capabilities item %d visual" $page.Path (add $index 1))) -}} + {{- else }} {{ partial "landing/code-lines.html" (dict "lines" .lines "position" (printf "%s: capabilities item %d visual" $page.Path (add $index 1))) }}

+ {{- end }} {{- else if eq $visualType "shell" }}