code-group
Labelled alternative code samples
interactive 1.0.0 Apache-2.0
Install
docsloth component add @docsloth/code-group@1.0.0 \
--registry https://registry.docsloth.devRun it in a project that has a docsloth.config.json (docsloth init writes one). The docsloth CLI is not on npm yet: it runs from a checkout of the Docsloth engine, and the quickstart shows the setup. Every official component already renders in Docsloth sites; installing one vendors its props schema and specification and pins this exact version and digest.
What the CLI checks
docsloth component add reads this entry from index.json, recomputes the package digest from the manifest and the digest of every file, and writes nothing if one differs.
index.json, lines 277–294277 {278 "name": "@docsloth/code-group",279 "version": "1.0.0",280 "kind": "block",281 "description": "Labelled alternative code samples",282 "license": "Apache-2.0",283 "engine": ">=1 <2",284 "publisher": "docsloth",285 "digest": "sha256:eb5f37eae33a615a71ec7d4f1b84f436655eb8f4020762901bf67e80a0c8b5e8",286 "blocks": [287 "code-group"288 ],289 "capabilities": [290 "render.html"291 ],292 "manifest_path": "packages/@docsloth/code-group/1.0.0/manifest.json",293 "files_base": "packages/@docsloth/code-group/1.0.0/files"294 },Trust signals
- Runtime trust class (catalog)
- interactive. Responds to the reader inside the page, such as switching tabs or filtering, with no network access and no secrets.
- Install trust class
- interactive, derived from the declared
render.html. This is the classdocsloth component addanddocsloth component listreport; it installs under the default policy, with no trust policy. - Package
@docsloth/code-group, version1.0.0- Package digest
sha256:eb5f37eae33a615a71ec7d4f1b84f436655eb8f4020762901bf67e80a0c8b5e8- Files
- 2 files, each pinned by its own sha256 digest (listed under Package files)
- Capabilities declared
render.html. A declaration, never a grant; every official package declares the same.- Publisher
docsloth, a publisher id rather than a verified identity- Licence
Apache-2.0- Engine range
>=1 <2- Index signature
- Not signed. Digests prove the bytes match the index, not who published them.
- Tools
select_tab- Built from
packages/contracts/component-props/code-group.schema.jsonandpackages/contracts/component-specs/code-group.mdin docsloth-registry
Props
The props schema is packages/contracts/component-props/code-group.schema.json; props it does not list are rejected.
| Prop | Type | Required | Notes |
|---|---|---|---|
title | string | no | maxLength: 160 |
active | integer | no | |
activeTab | string | no | maxLength: 256 |
No prop is required.
Example props generated from the schema
{
"title": "Install",
"active": 0,
"activeTab": "npm"
}Preview
Rendered by @docsloth/renderer from the example document block in the specification.
Document block
{
"type": "code-group",
"props": {
"title": "Install",
"active": 0
},
"children": [
{
"type": "code",
"props": {
"label": "npm",
"language": "bash",
"code": "npm add @docsloth/renderer"
}
},
{
"type": "code",
"props": {
"label": "pnpm",
"language": "bash",
"code": "pnpm add @docsloth/renderer"
}
}
]
}npm add @docsloth/rendererpnpm add @docsloth/rendererThis is the renderer's real HTML with this registry's styles. Links and controls in the preview are inactive.
Rendered HTML
<div class="ds-code-group" data-component="code-group">
<div class="ds-tablist" role="tablist" aria-label="Install">
<button type="button" class="ds-tab" role="tab" id="b-tab-0" aria-controls="b-panel-0" aria-selected="true" tabindex="0">npm</button>
<button type="button" class="ds-tab" role="tab" id="b-tab-1" aria-controls="b-panel-1" aria-selected="false" tabindex="-1">pnpm</button>
</div>
<div class="ds-tabpanels">
<div class="ds-tabpanel" role="tabpanel" id="b-panel-0" aria-labelledby="b-tab-0" tabindex="0">
<pre class="ds-code" data-lang="bash">
<code>npm add @docsloth/renderer</code>
</pre>
</div>
<div class="ds-tabpanel" role="tabpanel" id="b-panel-1" aria-labelledby="b-tab-1" tabindex="0">
<pre class="ds-code" data-lang="bash">
<code>pnpm add @docsloth/renderer</code>
</pre>
</div>
</div>
</div>Specification
From packages/contracts/component-specs/code-group.md.
Contract
Packaged: this block ships as @docsloth/code-group@1.0.0 — an installable component package (kind block, capability render.html, Apache-2.0) whose production props schema is packages/contracts/component-props/code-group.schema.json and whose catalog entry is in packages/contracts/component-catalog.json. No protocol manifest fixture is published (manifest_fixture: null): the fixture models a packaged protocol runtime this block does not have.
Intended behavior
Group equivalent code samples (package managers, language variants, platform variants) without duplicating page content. Every sample stays in the DOM so no-JS and agent readers see all of them; the tablist only selects emphasis.
Failure and fallback
A group with no children, a child without a non-empty props.label, or a child that is not a code block degrades the whole block to the labelled fallback while keeping the child content visible. Unknown active/activeTab values degrade in place to the first sample.
Required acceptance cases
Switching samples must not change the meaning or content of any fence; the same language tag survives in the Markdown twin. Also test empty data, loading, denied access, browser without JS, mobile 360px, keyboard navigation, dark mode and an explicit constrained agent tool call. The server independently authorizes capability requests; a package manifest cannot grant authority.
Data and maintenance
Data bindings resolve from a specific publication/release vector and permitted fact/evidence graph. Configuration edits create versioned component patches. Update invalidation uses dependency IDs, never indiscriminate whole-page regeneration. Human-owned props survive automatic updates unless invalidated with an explicit conflict. Missing optional resources leave an honest inert/readable fallback, not a broken page or fake success.
Cost and tools
Pure/local interaction must never invoke a model by accident. Any model, remote query or executor call must reserve approved budget before dispatch. Public visitors do not inherit owner resources. The component may call only named tools in its signed manifest with valid typed inputs. A cancelled job stops polling and closes resources. No component gets platform administration, raw credentials or an unlimited execution loop.
Native renderer block
packages/renderer renders a code-group block with the existing tabs a11y contract: a role="tablist" whose role="tab" buttons wire aria-controls to matching role="tabpanel" panels, with the accessible name from props.title (default Code samples). Panels stay in the DOM (no hidden), so every sample reaches no-JS and agent readers. Markdown flattens the block to ### <label> subsections, each containing the child code fence with its original language tag.
Native block props
| prop | type | required | behaviour |
|---|---|---|---|
title | string | no | Accessible name of the tablist (aria-label, default Code samples). |
active | integer | no | Zero-based index selected by default; unknown values degrade to the first sample. |
activeTab | string | no | Label or props.id of the selected sample; unknown ids degrade to the first sample. |
children | code[] | yes | One sample per child; each child needs a non-empty props.label and type: "code". A missing label or a non-code child degrades the whole block to the labelled fallback. |
The tab buttons are content labels, not chrome, so they are not marked data-markdown-ignore; the Markdown twin carries the same labels as headings and the same language tags as fence info strings.
Example
{
"type": "code-group",
"props": { "title": "Install", "active": 0 },
"children": [
{ "type": "code", "props": { "label": "npm", "language": "bash", "code": "npm add @docsloth/renderer" } },
{ "type": "code", "props": { "label": "pnpm", "language": "bash", "code": "pnpm add @docsloth/renderer" } }
]
}
Package files
Served under packages/@docsloth/code-group/1.0.0/. The package digest covers manifest.json, which lists each file with its digest.
| File | sha256 digest | Bytes |
|---|---|---|
props.schema.json | sha256:b471c57e8015377f1a2ea16067616273005c3d976ec7456c5f667a417d03ef1f | 698 |
spec.md | sha256:75db1003a6b99dc7624a155345cd3809b44385524cd81070c24d17d6921e416c | 4029 |
Sources
| Source | Location |
|---|---|
| Markdown twin | https://registry.docsloth.dev/docs/code-group.md |
| JSON metadata | https://registry.docsloth.dev/api/v1/components/code-group.json |
| Specification | packages/contracts/component-specs/code-group.md |
| Props schema | packages/contracts/component-props/code-group.schema.json |
| Catalog | packages/contracts/component-catalog.json |