docslothregistry

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.dev

Run 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–294
277    {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 class docsloth component add and docsloth component list report; it installs under the default policy, with no trust policy.
Package
@docsloth/code-group, version 1.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.json and packages/contracts/component-specs/code-group.md in docsloth-registry

Props

The props schema is packages/contracts/component-props/code-group.schema.json; props it does not list are rejected.

PropTypeRequiredNotes
titlestringnomaxLength: 160
activeintegerno
activeTabstringnomaxLength: 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/renderer
pnpm add @docsloth/renderer

This 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

proptyperequiredbehaviour
titlestringnoAccessible name of the tablist (aria-label, default Code samples).
activeintegernoZero-based index selected by default; unknown values degrade to the first sample.
activeTabstringnoLabel or props.id of the selected sample; unknown ids degrade to the first sample.
childrencode[]yesOne 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.

Filesha256 digestBytes
props.schema.jsonsha256:b471c57e8015377f1a2ea16067616273005c3d976ec7456c5f667a417d03ef1f698
spec.mdsha256:75db1003a6b99dc7624a155345cd3809b44385524cd81070c24d17d6921e416c4029

Sources

SourceLocation
Markdown twinhttps://registry.docsloth.dev/docs/code-group.md
JSON metadatahttps://registry.docsloth.dev/api/v1/components/code-group.json
Specificationpackages/contracts/component-specs/code-group.md
Props schemapackages/contracts/component-props/code-group.schema.json
Catalogpackages/contracts/component-catalog.json