An open source design system that's fully customizable and agent ready
TypeScript
docs(spec): CodeBlock caller controls beside Copy (endContent); controls never cover code; one-line blocks are one row (#8112)
Cindy Zhang524564aedb34
diff --git a/docs/specs/AST-061-document-surface-parity/spec.md b/docs/specs/AST-061-document-surface-parity/spec.mdindex e1e1382392..c6f60e604a 100644--- a/docs/specs/AST-061-document-surface-parity/spec.md+++ b/docs/specs/AST-061-document-surface-parity/spec.md@@ -95,11 +95,12 @@ reflows no line; only editing affordances appear or disappear.and `©`, render as the characters they name on every surface; insideinline code and fenced code they stay literal. Every surface decodes themwith the one decoder `Markdown` exports (DEC-5).-- **FR8 — Same code block frame.** A fenced code block shows the same header,- its language label and copy action, at the same height in read and edit- mode, so the switch does not move the code. In edit mode the header sits- outside the editable text: it is not part of the document and cannot be- edited.+- **FR8 — Same code block frame.** A fenced code block shows the same frame —+ its header, or the corner cluster when it has none, with its language label+ and copy action placed as `component:CodeBlock` FR3 and FR11 place them — at+ the same height in read and edit mode, so the switch does not move the code.+ In edit mode the frame — the header or the corner cluster — sits outside the+ editable text: it is not part of the document and cannot be edited.- **FR9 — Reading and editing in place.** Edit mode may add a caret,selection, placeholder, focus ring, field border and inset, and a toolbar.Together these offset the whole document by one constant amount: after that@@ -155,6 +156,9 @@ FR5 wrap; RichText already wraps fenced code. RichText's editing surface isline that wraps close to the available width can take one more line in editmode than in read mode, against FR9; at phone width a long fenced code linedoes.+`Markdown`, through `component:CodeBlock`, and the RichText surfaces float+Copy over the code of a fence that names no language; both adopt the FR8+corner cluster that `component:CodeBlock` FR11 places.## Verification@@ -168,7 +172,7 @@ does.| FR5, DEC-9 | Real-browser line boxes and horizontal overflow of a long-line code fixture on both surfaces, read and edit | 390px and 1440px; light and dark; left-to-right and right-to-left | A code block whose scroll width exceeds its client width, or a long line that is taller in one mode than the other, fails || FR5, DEC-6 | Real-browser marker style per depth on both surfaces | Bulleted and numbered lists nested 0–8 deep and of mixed types; starts of 0, −1, 26, 27, 3999, and 4000 at alpha and roman depths; right-to-left; light and dark | A level that draws another level's marker, or one surface differing from the other, fails || FR5, FR11 | Real-browser counter line boxes, sibling text starts, and nested-list insets on Markdown and RichText | Short and wide-counter lists at the same depth; decimal 9–10 and 99–100; alpha z–aa; roman vi–viii; adjacent parents whose child lists have different widest counters; phone/desktop; LTR/RTL; light/dark; read/edit | A split, clipped, or overlapping counter, a per-item text shift, a nested-list anchor displaced from its parent list's shared text-start line, or a cross-renderer/read-edit inset mismatch fails |-| FR8 | Real-browser code block header geometry in both modes | Fenced code with an info string | A header missing from one mode moves the code and fails |+| FR8 | Real-browser code block header geometry in both modes | Fenced code with an info string; a one-line fence with a language; a long fence with no language | A header or corner cluster present in only one mode, a control over the code in either mode, or a line that wraps differently between modes fails || FR9–FR10 | Real-browser read/edit switch of the parity fixture and a long document | Short document at the top; long document halfway down | A per-block shift beyond the constant offset, or an anchor block leaving the top of the view, fails |## Decision logdiff --git a/packages/core/src/CodeBlock/CodeBlock.spec.md b/packages/core/src/CodeBlock/CodeBlock.spec.mdindex 6747675c12..186489c96d 100644--- a/packages/core/src/CodeBlock/CodeBlock.spec.md+++ b/packages/core/src/CodeBlock/CodeBlock.spec.md@@ -39,15 +39,15 @@ system_specs: [spec:AST-025]## Contract at a glance-| Area | Contract |-| ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |-| Public contract | `CodeBlock` and `CodeBlockProps` are exported from `@astryxdesign/core/CodeBlock`; `code` is required, and the remaining released props configure language, header, line presentation, copy, wrapping, sizing, syntax theme, and collapse behavior; `isDiff` (FR9) adds the diff layer as a caller choice over any language. |-| Behavior | CodeBlock renders a read-only multi-line code surface, applies syntax highlighting when available, preserves the source string for copy, and exposes optional line, header, copy, theme, and disclosure behavior without editing the content. |-| End-user impact | Readers can inspect and copy code, understand optional line emphasis, and operate long or collapsible examples with keyboard and assistive technology. |-| Builder impact | Builders choose the released display axes without an additional migration or opt-in; the diff layer is one more opt-in axis, and five defaulted syntax-theme slots mean no syntax theme has to change for it. |-| Compatibility/readiness | The released `CodeBlock` API and defaults remain stable; FR9 (the diff layer) is current and shipped; Markdown's default path for `diff` fences follows it (`component:Markdown` FR29). |-| Review checks | Reject lost code text, copy of a transformed string, an unnamed copy or disclosure control, stale disclosure state/wiring, dropped root props/ref, a theme target off its painter, or viewport focusability that ignores effective overflow. |-| Governing rules | `architecture:public-component-api/INV1,INV5–INV9`; `architecture:component-theming-surface/INV3–INV7,INV12`; `architecture:component-test-sufficiency/INV1–INV7,INV10–INV11`; `spec:AST-025/FR12–FR13`; `architecture:theme-tokens` (syntax vocabulary and the diff slot defaults). |+| Area | Contract |+| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |+| Public contract | `CodeBlock` and `CodeBlockProps` are exported from `@astryxdesign/core/CodeBlock`; `code` is required, and the remaining released props configure language, header, line presentation, copy, wrapping, sizing, syntax theme, and collapse behavior; `isDiff` (FR9) adds the diff layer as a caller choice over any language; `endContent` (FR10) places caller controls beside Copy. |+| Behavior | CodeBlock renders a read-only code surface, applies syntax highlighting when available, preserves the source string for copy, and exposes optional line, header, copy, caller-control, theme, and disclosure behavior without editing the content; no control covers the code, and a one-line block with no header (no title, language label hidden) reads as one row (FR11). |+| End-user impact | Readers can inspect and copy code, understand optional line emphasis, and operate long or collapsible examples with keyboard and assistive technology. Readers of a block with no header never have code under a control, at the cost of the controls' column width, and a one-line command whose label is hidden reads as one row with its controls beside it; product actions sit beside Copy instead of outside the block. |+| Builder impact | Builders choose the released display axes without an additional migration or opt-in; the diff layer is one more opt-in axis, `endContent` (FR10) is one optional slot for their own controls, and five defaulted syntax-theme slots mean no syntax theme has to change for it. |+| Compatibility/readiness | The released `CodeBlock` API remains stable and its defaults hold except for the visible headerless layout in Compatibility below (FR11); FR10 (`endContent`, additive) and FR11 are current and await implementation; FR9 (the diff layer) is current and shipped; Markdown's default path for `diff` fences follows it (`component:Markdown` FR29). |+| Review checks | Reject lost code text, copy of a transformed string, an unnamed copy or disclosure control, stale disclosure state/wiring, dropped root props/ref, a theme target off its painter, viewport focusability that ignores effective overflow, a control painted over the code, or caller controls that toggle the disclosure. |+| Governing rules | `architecture:public-component-api/INV1,INV5–INV9`; `architecture:component-theming-surface/INV3–INV7,INV12`; `architecture:component-test-sufficiency/INV1–INV7,INV10–INV11`; `spec:AST-025/FR12–FR13`; `architecture:theme-tokens` (syntax vocabulary and the diff slot defaults). |This table is a review projection; the body below is authoritative only after owner approval.@@ -57,9 +57,10 @@ Present read-only, standalone or multi-line code with optional syntax, navigatio## Compatibility and migration-- Released default preserved: yes+- Released default preserved: yes, except the visible headerless layout (FR11, below)- Compatibility class: compatible; no prop, export, type, default, target, or ref migration is required- Controlled/uncontrolled behavior: collapse state remains component-owned, starts expanded when applicable, and returns to expanded when its control disappears+- Visible default change (FR11), not breaking: a block with no header shows its controls in their own column beside the code instead of over it, so its code ends that much earlier, a block sized to its content (`fit-content`) grows by the column's width, and a one-line block reads as one row. A block with a title or a visible language label keeps its header at every line count. Markdown fences with no language take it through the default code path (`component:Markdown`). No prop, type, or target migration follows from it.- Migration decision: noneConsumer migration instructions belong in consumer docs and release notes.@@ -79,31 +80,35 @@ Consumer migration instructions belong in consumer docs and release notes.## Public concepts-| Concept | Closed values or states | Meaning | Availability | Default | Owner | Stability | Invalid-value behavior |-| ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------- | ----------- | ------------------- | --------- | --------------------------------------------------------------------- |-| code content | caller-supplied string | Supplies the exact read-only source that is displayed and copied. | Every render | required | product callsite | stable | rejected by the public type |-| language | built-in identifier, custom-tokenizer identifier, or plaintext/unknown | Selects tokenization and the optional visible/accessible language label. | Every render | `plaintext` | component:CodeBlock | stable | unsupported built-ins render without tokens |-| line presentation | numbers off/on; highlights absent or one-indexed line set; wrapped/unwrapped | Adds navigation and emphasis without changing the copied source string. | Code body | off/absent | component:CodeBlock | stable | out-of-range highlights have no rendered line |-| diff layer | off; on — each line classified by its first character: `+` added, `-` removed, header (`@@`; a `--- `/`+++ ` pair directly before an `@@`), else context | Tints added and removed rows and quiets header rows from the syntax theme while the rest of every line keeps the base language's syntax paint; the glyph stays in display and copy. | Code body, any `language` | off | product callsite | stable | rejected by the public type (boolean) |-| header | absent; title; language label; title and language label | Gives the snippet context and houses the copy control when any visible header content exists. | Derived from title and label choices | derived | component:CodeBlock | stable | empty visible content still requires AT naming |-| copy | hidden; available; transient copied feedback | Copies the exact code string, then invokes `onCopy` only after a successful clipboard write. | Every render when enabled | available | component:CodeBlock | stable | failed clipboard writes do not invoke `onCopy` |-| syntax rendering | auto; CSS ranges; spans; custom tokenizer; optional per-instance syntax theme | Selects a supported paint path without changing the text or public code semantics. | Every render | `auto` | component:CodeBlock | stable | unsupported range capability falls back to spans |-| collapse | unavailable; expanded; collapsed | Turns an eligible visible header into a disclosure when the line threshold is met. | Long blocks with a header and collapse enabled | unavailable | component:CodeBlock | stable | missing-header or below-threshold blocks remain expanded and ordinary |-| container geometry | card/section; small/medium; fit-content/custom width; unbounded/bounded height | Selects presentation and overflow geometry while preserving the read-only code task. | Every render | card/md | component:CodeBlock | stable | values follow their documented CSS/type behavior |+| Concept | Closed values or states | Meaning | Availability | Default | Owner | Stability | Invalid-value behavior |+| ------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------- | ----------- | ------------------- | --------- | --------------------------------------------------------------------- |+| code content | caller-supplied string | Supplies the exact read-only source that is displayed and copied. | Every render | required | product callsite | stable | rejected by the public type |+| language | built-in identifier, custom-tokenizer identifier, or plaintext/unknown | Selects tokenization and the optional visible/accessible language label. | Every render | `plaintext` | component:CodeBlock | stable | unsupported built-ins render without tokens |+| line presentation | numbers off/on; highlights absent or one-indexed line set; wrapped/unwrapped | Adds navigation and emphasis without changing the copied source string. | Code body | off/absent | component:CodeBlock | stable | out-of-range highlights have no rendered line |+| diff layer | off; on — each line classified by its first character: `+` added, `-` removed, header (`@@`; a `--- `/`+++ ` pair directly before an `@@`), else context | Tints added and removed rows and quiets header rows from the syntax theme while the rest of every line keeps the base language's syntax paint; the glyph stays in display and copy. | Code body, any `language` | off | product callsite | stable | rejected by the public type (boolean) |+| header | absent; title; language label; title and language label | Gives the snippet context and houses the caller controls and copy when it exists. | Derived from title and label choices | derived | component:CodeBlock | stable | empty visible content still requires AT naming |+| copy | hidden; available; transient copied feedback | Copies the exact code string, then invokes `onCopy` only after a successful clipboard write. | Every render when enabled | available | component:CodeBlock | stable | failed clipboard writes do not invoke `onCopy` |+| caller controls (`endContent`) | absent; caller-rendered nodes | Places product actions beside Copy, before it in reading order, in the header or the corner cluster; never creates the header. | Every render | absent | product callsite | stable | any React node; CodeBlock does not inspect it |+| corner cluster | absent; caller controls and copy, in that order | Holds the controls of a block with no header in their own inline-end column beside the code, centred on the first line. | Blocks with no header and any control | derived | component:CodeBlock | stable | an empty cluster takes no column |+| syntax rendering | auto; CSS ranges; spans; custom tokenizer; optional per-instance syntax theme | Selects a supported paint path without changing the text or public code semantics. | Every render | `auto` | component:CodeBlock | stable | unsupported range capability falls back to spans |+| collapse | unavailable; expanded; collapsed | Turns an eligible visible header into a disclosure when the line threshold is met. | Long blocks with a header and collapse enabled | unavailable | component:CodeBlock | stable | missing-header or below-threshold blocks remain expanded and ordinary |+| container geometry | card/section; small/medium; fit-content/custom width; unbounded/bounded height | Selects presentation and overflow geometry while preserving the read-only code task. | Every render | card/md | component:CodeBlock | stable | values follow their documented CSS/type behavior |## Behavioral and layout contract-| ID | Candidate invariant | Basis | Draft review state |-| --- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- | ---------------------------------- |-| FR1 | CodeBlock MUST display the caller's code string as read-only code. Built-in or custom tokenization MAY change syntax paint but MUST NOT change displayed or copied source text. | released types, source, tests, consumer docs; established public interface | verify |-| FR2 | A successful copy MUST write the exact `code` string, invoke `onCopy` once, expose localized copied feedback, and preserve the copy control's discoverable purpose. A failed write MUST NOT report success. | shipped source/tests; `architecture:component-test-sufficiency/INV2–INV6`; WCAG name/status obligations | verify |-| FR3 | A title or visible non-plaintext language label MUST create the visible header. Hiding the language label MUST NOT remove copy behavior. Headerless copy remains available when enabled. | shipped source/tests/docs; established public interface | verify |-| FR4 | Line numbers, highlighted lines, wrapping, width, container presentation, size, and maximum height MUST affect only their documented presentation axes. Numeric `maxHeight={0}` MUST remain a valid zero-pixel bound rather than being discarded. | released public type/docs; `architecture:public-component-api/INV3,INV9`; objective JavaScript nullish semantics | verified by focused regression |-| FR5 | Collapse MUST become available only when enabled, a visible header exists, and the line threshold is met. The control MUST expose expanded state and a resolvable controlled region; collapsed content remains mounted but inert, and losing the control expands the region before hiding the control. | shipped docs/source/tests; WAI-ARIA disclosure pattern and HTML `inert` semantics | verify |-| FR6 | The root and documented header/title/copy targets MUST remain on their visible painters, reflect the documented visual axes, and continue emitting the approved deprecated aliases until their authorized removal window. | `architecture:component-theming-surface/INV3–INV7,INV12`; source/docs/tests | verify |-| FR7 | Supported DOM, data, ARIA, class, style, and `xstyle` inputs MUST compose on the documented root, and the public ref MUST reach that root. | `architecture:public-component-api/INV5,INV6,INV8`; shipped source | verify |-| FR8 | The code viewport MUST enter sequential keyboard navigation only while at least one applicable axis effectively overflows; losing overflow MUST NOT move current focus. It retains an appropriate role and accessible name while focusable. | `spec:AST-025/FR12–FR13` | settled by current authority |-| FR9 | With the diff layer on (`isDiff`), CodeBlock MUST classify each line by its first character — `+` added, `-` removed, `@@` header, anything else context — except that a `--- ` line (three minus signs and a space, the unified-diff file header form) directly followed by a `+++ ` line and then an `@@` line is a file header (both lines), wherever it occurs; every other `---`/`+++` line, `---i;` included, is removed or added. CodeBlock MUST set the glyph column aside and tokenize the REST of every line (context, added, and removed alike) with the base `language`'s syntax highlighting. Added, removed, and header lines MUST paint as whole rows — the line-number gutter cell included — from the syntax-theme slots `--color-syntax-added`, `--color-syntax-removed`, and `--color-syntax-diff-header`, whose defaults `architecture:theme-tokens` owns; header rows take the syntax theme's `punctuation` colour as text (`--color-text-secondary` in the default theme) and never change paint; context rows keep ordinary paint. On an added or removed row, the line number and the glyph take the row's marker slot — `--color-syntax-added-marker` / `--color-syntax-removed-marker` — so the margin reads the change in colour; every run of code text, painted by a token or not, keeps its syntax-theme colour. In the Astryx default syntax theme the marker slots default to the theme's tinted-text tokens and the header paint to the muted background (`architecture:theme-tokens` owns the values); a syntax theme that does not set them inherits its own colours — the marker slots and the header text its line-number colour (its `punctuation` slot), the header paint none at all (the header row sits on the theme's own syntax background) — so number, glyph, and header text stay legible on that theme's background in every page mode, and the glyph's shape carries the meaning where its colour does not. The glyph (`+`, `-`, the leading space of a context line, or nothing for a context or header line without one — the marker column is then empty and the whole line is code) MUST render in its own fixed-width marker column — secondary colour on context rows and the row's marker slot on added and removed rows, separated from the code by a token gap (`--spacing-2`, a proportion themes may vary like the rest), excluded from selection for layout yet present in the copied text — so the code column starts at the same inline offset on every line and the content's own indentation is never shifted; the gutter order is line number, marker, code, mirrored in RTL with the code's direction unchanged. The header (language label, copy, disclosure) and the viewport's name stay as for any other code: with the layer over plaintext the visible language label and the viewport name are `diff`, and over a language they name both (`tsx diff`). Markdown's fence mapping onto the layer is `component:Markdown` FR29. Row paint MUST compose with line numbers without moving text; on a highlighted added, removed, or header line the highlight REPLACES the row paint rather than stacking on it, so text keeps its single-paint contrast; and row paint MUST span the full line width — the scrolled overflow of a long line included, in wrapped and unwrapped mode — not only the visible viewport. Contrast floor: in the Astryx default syntax theme, every default token colour and the row's marker slot (line number and glyph) on a painted row MUST measure ≥ 4.5:1 against the default tints composited over the code block's own `--color-syntax-background` on the default card surface. In a syntax theme that overrides a diff slot, a token that already measures under 4.5:1 on that theme's own syntax background MUST NOT drop further on the slot, and every other token MUST clear 4.5:1 on it. Two known shortfalls, tracked separately: the shipped syntax presets do not yet meet the floor on the default tints with the layer on, and shipped page themes whose own text tokens fall under it on the tints keep that shortfall, tracked for a fix in those themes, until each sets its tokens or the diff slots. | this record DEC-1 | current; owner-approved 2026-10-12 |+| ID | Candidate invariant | Basis | Draft review state |+| ---- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- | ---------------------------------- |+| FR1 | CodeBlock MUST display the caller's code string as read-only code. Built-in or custom tokenization MAY change syntax paint but MUST NOT change displayed or copied source text. | released types, source, tests, consumer docs; established public interface | verify |+| FR2 | A successful copy MUST write the exact `code` string, invoke `onCopy` once, expose localized copied feedback, and preserve the copy control's discoverable purpose. A failed write MUST NOT report success. | shipped source/tests; `architecture:component-test-sufficiency/INV2–INV6`; WCAG name/status obligations | verify |+| FR3 | A title or visible non-plaintext language label MUST create the visible header, at every line count. Hiding the language label MUST NOT remove copy behavior. Headerless copy remains available when enabled. `endContent` never creates the header. | released types, source, tests, consumer docs; established public interface; proposal for `endContent` | verify |+| FR4 | Line numbers, highlighted lines, wrapping, width, container presentation, size, and maximum height MUST affect only their documented presentation axes. Numeric `maxHeight={0}` MUST remain a valid zero-pixel bound rather than being discarded. | released public type/docs; `architecture:public-component-api/INV3,INV9`; objective JavaScript nullish semantics | verified by focused regression |+| FR5 | Collapse MUST become available only when enabled, a visible header exists, and the line threshold is met. The control MUST expose expanded state and a resolvable controlled region; collapsed content remains mounted but inert, and losing the control expands the region before hiding the control. | shipped docs/source/tests; WAI-ARIA disclosure pattern and HTML `inert` semantics | verify |+| FR6 | The root and documented header/title/copy targets MUST remain on their visible painters, reflect the documented visual axes, and continue emitting the approved deprecated aliases until their authorized removal window. | `architecture:component-theming-surface/INV3–INV7,INV12`; source/docs/tests | verify |+| FR7 | Supported DOM, data, ARIA, class, style, and `xstyle` inputs MUST compose on the documented root, and the public ref MUST reach that root. | `architecture:public-component-api/INV5,INV6,INV8`; shipped source | verify |+| FR8 | The code viewport MUST enter sequential keyboard navigation only while at least one applicable axis effectively overflows; losing overflow MUST NOT move current focus. It retains an appropriate role and accessible name while focusable. | `spec:AST-025/FR12–FR13` | settled by current authority |+| FR9 | With the diff layer on (`isDiff`), CodeBlock MUST classify each line by its first character — `+` added, `-` removed, `@@` header, anything else context — except that a `--- ` line (three minus signs and a space, the unified-diff file header form) directly followed by a `+++ ` line and then an `@@` line is a file header (both lines), wherever it occurs; every other `---`/`+++` line, `---i;` included, is removed or added. CodeBlock MUST set the glyph column aside and tokenize the REST of every line (context, added, and removed alike) with the base `language`'s syntax highlighting. Added, removed, and header lines MUST paint as whole rows — the line-number gutter cell included — from the syntax-theme slots `--color-syntax-added`, `--color-syntax-removed`, and `--color-syntax-diff-header`, whose defaults `architecture:theme-tokens` owns; header rows take the syntax theme's `punctuation` colour as text (`--color-text-secondary` in the default theme) and never change paint; context rows keep ordinary paint. On an added or removed row, the line number and the glyph take the row's marker slot — `--color-syntax-added-marker` / `--color-syntax-removed-marker` — so the margin reads the change in colour; every run of code text, painted by a token or not, keeps its syntax-theme colour. In the Astryx default syntax theme the marker slots default to the theme's tinted-text tokens and the header paint to the muted background (`architecture:theme-tokens` owns the values); a syntax theme that does not set them inherits its own colours — the marker slots and the header text its line-number colour (its `punctuation` slot), the header paint none at all (the header row sits on the theme's own syntax background) — so number, glyph, and header text stay legible on that theme's background in every page mode, and the glyph's shape carries the meaning where its colour does not. The glyph (`+`, `-`, the leading space of a context line, or nothing for a context or header line without one — the marker column is then empty and the whole line is code) MUST render in its own fixed-width marker column — secondary colour on context rows and the row's marker slot on added and removed rows, separated from the code by a token gap (`--spacing-2`, a proportion themes may vary like the rest), excluded from selection for layout yet present in the copied text — so the code column starts at the same inline offset on every line and the content's own indentation is never shifted; the gutter order is line number, marker, code, mirrored in RTL with the code's direction unchanged. The header (language label, copy, disclosure) and the viewport's name stay as for any other code: with the layer over plaintext the visible language label and the viewport name are `diff`, and over a language they name both (`tsx diff`). Markdown's fence mapping onto the layer is `component:Markdown` FR29. Row paint MUST compose with line numbers without moving text; on a highlighted added, removed, or header line the highlight REPLACES the row paint rather than stacking on it, so text keeps its single-paint contrast; and row paint MUST span the full line width — the scrolled overflow of a long line included, in wrapped and unwrapped mode — not only the visible viewport. Contrast floor: in the Astryx default syntax theme, every default token colour and the row's marker slot (line number and glyph) on a painted row MUST measure ≥ 4.5:1 against the default tints composited over the code block's own `--color-syntax-background` on the default card surface. In a syntax theme that overrides a diff slot, a token that already measures under 4.5:1 on that theme's own syntax background MUST NOT drop further on the slot, and every other token MUST clear 4.5:1 on it. Two known shortfalls, tracked separately: the shipped syntax presets do not yet meet the floor on the default tints with the layer on, and shipped page themes whose own text tokens fall under it on the tints keep that shortfall, tracked for a fix in those themes, until each sets its tokens or the diff slots. | this record DEC-1 | current; owner-approved 2026-10-12 |+| FR10 | `endContent` MUST render the caller's nodes beside Copy and before it in reading order: in the header when one exists, otherwise in the corner cluster (FR11); without Copy it keeps that place. It MUST sit outside the disclosure control, and pointer or keyboard activation inside it MUST NOT toggle collapse. CodeBlock MUST NOT name, restyle, or announce its content; the caller owns each control's name, state, and action. | proposal; the end-content slot of the Dialog and Drawer headers | verify |+| FR11 | With no header, the corner cluster MUST occupy its own inline-end column beside the code viewport, as wide as its content and never over the viewport, so that no line, at rest, scrolled, wrapped, or in either direction, is painted under a control; the cluster MUST be centred on the first line of code. A headerless block whose code is one line — counted after removing one trailing newline — therefore reads as one row: code, then the controls, with even space above and below; the single-line mode a caller gets by leaving out the title and passing `hasLanguageLabel={false}`. When the code gains lines, the block grows downward and the controls keep their place. A visible language label or a title keeps the header at every line count (FR3). The column paints from the `code-block` root, so no theme target is added. | the Code Body and Copy Button design relationships; proposal | verify |### Allowed variation@@ -113,18 +118,19 @@ Consumer migration instructions belong in consumer docs and release notes.### Representative states-| State | Required invariant | Allowed variation |-| ------------------------------ | --------------------------------------------------------------------------------------------------- | ---------------------------------------------- |-| plaintext/headerless | Exact source text; localized code viewport name; optional floating copy control. | Caller code and container geometry. |-| titled highlighted code | Header context, optional line numbers/highlights, exact copy string. | Language, title, size, and theme paint. |-| wrapped or height-bounded | Content remains readable and copy preserves the source; keyboard focus follows effective overflow. | Width, height, line count, and writing mode. |-| collapsible expanded/collapsed | Named disclosure, correct expanded state, resolvable controlled region, inert only while collapsed. | Title/language content and theme paint. |-| custom syntax path | Tokens may change paint but not source text or copy output. | Token types, rendering mode, and syntax theme. |+| State | Required invariant | Allowed variation |+| ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------- |+| plaintext/headerless | Exact source text; localized code viewport name; corner cluster beside the code, never over it. | Caller code and container geometry. |+| one-line row | With no header (no title, `hasLanguageLabel={false}`): one row: code, then the controls, centred with even space; more lines grow downward and the controls stay put. | Code and caller controls. |+| titled highlighted code | Header context, optional line numbers/highlights, exact copy string. | Language, title, size, and theme paint. |+| wrapped or height-bounded | Content remains readable and copy preserves the source; keyboard focus follows effective overflow. | Width, height, line count, and writing mode. |+| collapsible expanded/collapsed | Named disclosure, correct expanded state, resolvable controlled region, inert only while collapsed. | Title/language content and theme paint. |+| custom syntax path | Tokens may change paint but not source text or copy output. | Token types, rendering mode, and syntax theme. |### Transformation and precedence order- **ORD1 — Source.** Caller code string → line partition → built-in or custom tokenization → range/span paint; copy always consumes the original code string.-- **ORD2 — Header.** Title and eligible language label determine header presence; copy is placed in that header when present and on the root when absent.+- **ORD2 — Header.** Title and eligible language label determine header presence (FR3); caller controls and then copy are placed in that header when present and in the corner cluster beside the code when absent.- **ORD3 — Styling.** Root theme target and reflected visual axes → base/container/size/dynamic styles → consumer `xstyle`, class, and inline-style composition.### Performance and resources@@ -142,14 +148,14 @@ Consumer migration instructions belong in consumer docs and release notes.## Design relationships-| Anatomy or state | Design requirement | Representation authority | Hierarchy role | Component contract |-| ----------------- | -------------------------------------------------------------------------------------------- | ------------------------------- | ------------------- | ------------------ |-| Header Bar | Provides supporting file/language context and houses the optional disclosure/copy controls. | observed shipped representation | supporting context | FR3, FR5, AR1–AR3 |-| Header Title | Groups the visible title, language label, and disclosure indicator inside the header. | observed shipped representation | supporting context | FR3, FR5, AR1–AR2 |-| Line Numbers | Support code navigation without becoming part of copied source. | observed shipped representation | supporting metadata | FR1, FR4 |-| Code Body | Keeps code text dominant, readable, scrollable or wrappable, and syntax-themed. | observed shipped representation | primary content | FR1, FR4, FR8 |-| Highlighted Lines | Add optional emphasis without replacing or mutating the source string. | observed shipped representation | supporting emphasis | FR1, FR4 |-| Copy Button | Exposes the code-copy action and transient success feedback without toggling the disclosure. | objective interaction semantics | secondary action | FR2, AR1–AR3 |+| Anatomy or state | Design requirement | Representation authority | Hierarchy role | Component contract |+| ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------- | ------------------- | ----------------------- |+| Header Bar | Provides supporting file/language context and houses the optional disclosure, caller controls, and copy. | observed shipped representation | supporting context | FR3, FR5, FR10, AR1–AR3 |+| Header Title | Groups the visible title, language label, and disclosure indicator inside the header. | observed shipped representation | supporting context | FR3, FR5, AR1–AR2 |+| Line Numbers | Support code navigation without becoming part of copied source. | observed shipped representation | supporting metadata | FR1, FR4 |+| Code Body | Keeps code text dominant, readable, scrollable or wrappable, and syntax-themed. | observed shipped representation | primary content | FR1, FR4, FR8 |+| Highlighted Lines | Add optional emphasis without replacing or mutating the source string. | observed shipped representation | supporting emphasis | FR1, FR4 |+| Copy Button | Exposes the code-copy action and transient success feedback without toggling the disclosure; with no header it sits with the caller controls in the corner cluster beside the code, never over it. | objective interaction semantics | secondary action | FR2, FR11, AR1–AR3 |Exact CodeBlock proportions and syntax colors are not contract requirements; they remain within the syntax-paint and theme-paint variation allowed above.@@ -186,7 +192,9 @@ Exact CodeBlock proportions and syntax colors are not contract requirements; the| FR7 | focused root-prop/ref tests; strict lint/typecheck; consumer-doc validation | ref plus supported root/style/data/ARIA inputs | The ref misses the root, accepted props disappear, or styling inputs replace rather than compose. | `audit:CodeBlock/api` || FR8, AR4 | `spec:AST-025` integration evidence plus real-browser fit/overflow/focus transitions | fitting, inline overflow, block overflow, losing overflow | A fitting viewport adds a stop, overflow is unreachable, naming disappears, or focus moves when overflow ends. | `audit:CodeBlock/a11y` || FR9 | `tokenizer.test.ts` (diff line classes; file-header pair rule; base-language tokens past the glyph); `CodeBlock.test.tsx` (row attributes, marker column, copy string incl. glyphs, `highlightLines`, header kept with the `diff` / `tsx diff` label and viewport name); syntax-theme tests (five slot defaults and overrides; a preset without marker or header slots takes punctuation text and no header paint); exact-head browser evidence incl. every default syntax token colour and the row marker slot (line number and glyph) measured ≥ 4.5:1 on painted rows in light and dark against the code block's own `--color-syntax-background` on the default card surface (the two known shortfalls in FR9 excepted) (on the light page background the surface is translucent and a plain row's default keyword already sits under the floor — a pre-existing shortfall that affects every CodeBlock there, tracked separately), and equal code-column x-offsets for context, added, and removed lines | added/removed/header/context over `tsx` and over plaintext; a removed line starting with `--`; `---i;` / `+++i;` right before an `@@` (removed/added, not header); a `--- `/`+++ ` pair with no `@@` after it (removed/added); a `--- `/`+++ `/`@@` file header after an earlier hunk (header); the layer over plaintext (label and viewport name `diff`) and over `tsx` (`tsx diff`); a context line with no leading space; a line longer than the viewport, scrolled (tint to the full scroll width) and wrapped; with `highlightLines` on an added line and on a header line (highlight paint only, text measured on it); with line numbers (gutter cell tinted, number in the row's marker slot); plain and token-painted text on a changed row keeping their syntax colours; light and dark (contrast measured on each); a custom syntax theme overriding the slots; indented code under all three line kinds; RTL (gutter mirrored, code direction unchanged) | A glyph removed from display or copy, a changed line's code starting at a different offset than its neighbours, a header row painted as a change or hidden, a header's text or paint taken from the page theme under a defined syntax theme, a `--`-prefixed removed line painted as a header, syntax paint lost past the glyph, a tint from anywhere but the three row slots, a gutter cell left untinted, a line number or glyph left in the ordinary colour on a changed row, code text recoloured by the row, a tint that stops at the viewport edge of a scrolled line, the header, collapse control, or viewport name lost on a diff, a `---i;` line painted as a header, or a default token or marker on a painted row under 4.5:1 on the default surface, or an override on which a token that clears 4.5:1 on the theme's own background falls under it or an already-short token drops further | `audit:CodeBlock/a11y` |-| RTL | `rtl:audit -- --filter CodeBlock` D2 target plus exact-head browser evidence | title and copy order in LTR/RTL | Logical order fails to mirror or physical placement leaks. | `audit:CodeBlock/rtl` |+| FR10 | `CodeBlock.test.tsx` (before Copy in the header and in the corner cluster, outside the disclosure control, pointer and Enter/Space inside it do not toggle, no header created, kept in place without Copy); exact-head browser evidence | header and headerless, with and without Copy, collapsible, LTR and RTL | A caller control toggles collapse, sits inside the disclosure or after Copy, creates a header, or is renamed or restyled by CodeBlock. | `audit:CodeBlock/behavior` |+| FR11 | real-browser geometry evidence over built stories | a long first line at rest, scrolled to its end, and wrapped; a one-line headerless block with and without caller controls; a one-line block with a visible label (keeps its header); one line growing to several; both sizes; LTR and RTL; light and dark | Any control box overlaps the code viewport, the cluster leaves the first line's centre, a one-line headerless block's space above and below differs, a block with a visible label or title loses its header, or the controls move when lines are added. | `audit:CodeBlock/behavior` |+| RTL | `rtl:audit -- --filter CodeBlock` D2 target plus exact-head browser evidence | title, caller controls, and copy order, and the corner cluster at the inline end, in LTR/RTL | Logical order fails to mirror or physical placement leaks. | `audit:CodeBlock/rtl` || Consumer metadata | CLI `component CodeBlock --json`; docs typecheck; prop/target validation; package-export checks | released props/defaults/ref and current/deprecated targets | A released prop/default/ref/target disappears from consumer discovery or docs name an unsupported value. | `audit:CodeBlock/docs` |## Decision log@@ -199,6 +207,18 @@ A reader of a changelog, migration note, or review comment sees what was added aA per-line typed wash (an added/removed flavour of `highlightLines`) is not decided here: the layer answers the need with the diff text itself. On a highlighted changed line the highlight replaces the tint because two translucent paints would compound into a colour no theme chose and push tokens under the floor. Rejected: hiding header lines (paint would change the displayed text and break copy; authors omit headers by omitting them from the fence); `diff` as a standalone language (every line falls to plaintext, so the code stops reading as code); tinting from the semantic tokens alone with no syntax slots (a custom syntax theme could not harmonize the rows with its palette); colouring the changed text with `--color-success`/`--color-error` (below the 4.5:1 text minimum on the tinted rows); per-language `diff-<lang>` identifiers in the component API (they multiply the language list; the fence convention maps to the prop instead); a separate Diff component (a fence is a CodeBlock and Markdown already routes fences there).+### DEC-2 — Product actions are one caller-rendered slot beside Copy++**Decider:** `cixzhang`, `2026-10-24`++A product that gives a snippet a second verb, such as running a command in a terminal, needs that control in the same place a reader already finds Copy, and the system needs that without learning the product's verbs. `endContent` is that place: the caller renders its own controls and owns their names, states, and actions, and CodeBlock only positions them, before Copy in reading order, so Copy stays the last control at the inline end in every block. The name follows the header end-content slot of Dialog and Drawer, which carries the same meaning there. Caller controls never create a header, because a header exists to carry the snippet's context, and a block without context keeps its controls in the corner cluster. Rejected: a declared list of `{label, icon, onClick}` actions (CodeBlock would render controls it does not own); a prop per product verb.++### DEC-3 — Controls take their own column, so a headerless one-line block is one row++**Decider:** `cixzhang`, `2026-10-24`++A control painted over code hides the reader's text, so a headerless block's controls sit in their own inline-end column beside the code viewport, as wide as the controls themselves; the column runs the block's full height because a scroll box clips its lines as one rectangle. Centring the column on the first line makes a headerless one-line block read as one row with even space and keeps the controls still while a block grows line by line, so a streamed block never moves its controls. Single-line mode is the existing choice to hide the language label: a caller that shows the label keeps the header and its context at every line count, and one that hides it gets the row. The column has no width cap; the caller supplies a few icon controls, and the code viewport takes the rest. Rejected: folding a visible label into a one-line row (the label is context the caller chose to show, and a streamed block would move its code when the label returned to a header); reserving space on the first line only (a scrolled line still runs under the control).+## Open questionsNone.diff --git a/packages/core/src/Markdown/Markdown.spec.md b/packages/core/src/Markdown/Markdown.spec.mdindex 9c961c4ba1..faf1c73fd8 100644--- a/packages/core/src/Markdown/Markdown.spec.md+++ b/packages/core/src/Markdown/Markdown.spec.md@@ -67,15 +67,17 @@ rendering, and native typed document-start frontmatter. They may separately optrenderer for both inline and display expressions. The parser accepts matchingexplicit options. Plugins and math change nothing when absent; the default Codeblock path renders `diff` and `diff-<language>` fences as CodeBlock's diff layer-(FR29) and wraps every fence's long lines (`spec:AST-061` FR5, DEC-9), and every-other parsing, rendering, styling, and streaming behavior is the released one.+(FR29), wraps every fence's long lines (`spec:AST-061` FR5, DEC-9), and lays+out a fence with no header the way CodeBlock does (`component:CodeBlock` FR11),+and every other parsing, rendering, styling, and streaming behavior is the+released one.## Compatibility and migration-- Released default preserved: `yes`, except the default Code block path for `diff` fences (FR29, below) and its long-line wrap (below)-- Compatibility class: additive, opt-in public API, with two visible- default-path rendering changes (the FR29 diff layer and the fenced-code wrap,- below); existing parser nodes, DOM, styling, targets,+- Released default preserved: `yes`, except the default Code block path for `diff` fences (FR29, below), its long-line wrap (below), and its headerless layout (below)+- Compatibility class: additive, opt-in public API, with three visible+ default-path rendering changes (the FR29 diff layer, the fenced-code wrap, and+ the headerless layout, below); existing parser nodes, DOM, styling, targets,dollar-delimited text, `components`, and `inlinePlugins` remain unchanged unlessthe caller supplies `plugins`, supplies `components.math`, or passes the matchingexplicit parser option.@@ -87,15 +89,20 @@ other parsing, rendering, styling, and streaming behavior is the released one.which rendered as plain text with a `diff` label and viewport name, itsleading word being all Markdown read — as the layer over that language witha `<language> diff` label; the header, copy, disclosure, and viewport name- stay, and a supplied `code` renderer's contract is unchanged. The way back to+ stay as for any other fence, and a supplied `code` renderer's contract is unchanged. The way back toplain text is a `text` fence or a custom `code` renderer. Every other fence- is unchanged apart from the wrap below.+ is unchanged apart from the wrap and the headerless layout below.- Default-path wrap change (`spec:AST-061` FR5, DEC-9), visual and not breaking:the default Code block wraps long lines instead of scrolling them sideways, soa fence whose lines no longer overflow also no longer takes the conditionalscroll-region tab stop. Text, line numbers, syntax colours, copy output, and asupplied `code` renderer's contract are unchanged. The way back to sidewaysscrolling is a custom `code` renderer.+- Default-path headerless layout (`component:CodeBlock` FR11), visual and not+ breaking: a fence with no language label shows Copy in its own column beside+ the code, so long lines wrap before it. A fence that names a language other than+ `plaintext` keeps its header at every line count. Text, copy output, syntax colours, the+ viewport name, and a supplied `code` renderer's contract are unchanged.- Default-path layout change (FR26–FR28): a default table's columns may becomewider than the released fixed buckets, never narrower; header labels wrapinstead of truncating; a table that squashed its columns may now scroll.