block

dictionaryExample

Wire value: "dictionaryExample"

Appears on: Documentation Topic, Tutorial Article

1. How swift-docc-render consumes this

dictionaryExample is one of the block-content kinds dispatched by the shared renderNode() function inside components/ContentNode.vue's BlockType map (dictionaryExample: 'dictionaryExample', line 47). The switch (node.type) case for it is:

case BlockType.dictionaryExample: {
  const props = {
    example: node.example,
  };
  return createElement(DictionaryExample, { props }, renderChildren(node.summary || []));
}

(src/components/ContentNode.vue#L371-L376). Two things stand out mechanically:

The leaf component, components/ContentNode/DictionaryExample.vue, is a thin 36-line wrapper with no local styling of its own:

<div class="DictionaryExample">
  <slot />
  <CollapsibleCodeListing
    :content="example.content"
    showLineNumbers
  />
</div>

It renders the summary slot content first (typically an introductory paragraph), then delegates the actual code rendering entirely to components/ContentNode/CollapsibleCodeListing.vue, passing example.content (the CodeExample.content array of { collapsible, code } chunks) straight through as that component's content prop, and hard-coding showLineNumbers to true. Note that DictionaryExample.vue does not pass a collapsed prop to CollapsibleCodeListing, so that prop is left at its Vue default (undefined, falsy) — every chunk starts visually expanded regardless of its own collapsible flag; collapsible only adds the .collapsible styling class (a distinct background/text color for those lines), it does not by itself collapse anything in this call site.

CollapsibleCodeListing.vue in turn renders each content chunk as its own <div class="container-general"> inside a single <pre><CodeBlock>…</CodeBlock></pre>, with one <div class="code-line-container"> per source line, each holding an optional <div class="code-number"> gutter (shown because showLineNumbers is always true here) and a <div class="code-line"> with the raw line text (CollapsibleCodeListing.vue#L11-L30). This is a structurally different (and simpler) markup path than the plain codeListing kind's dedicated CodeListing.vue: there is no copy-to-clipboard button, no wrap/lineAnnotations support, and (per the vendored schema in section 3) no per-example syntax-driven client-side syntax highlighting call in this component — highlighting, if any, happens inside the shared CodeBlock child component that wraps the whole listing, not per line.

2. Example JSON and rendered mockup

Real fixture: Tests/SwiftDocCTests/Rendering/Rendering Fixtures/plist-symbol.json in the pinned swift-docc checkout, found inside the primary content section's content array (a plist key's documentation illustrating an example dictionary value).

{
  "type": "dictionaryExample",
  "summary": [
    {
      "type": "paragraph",
      "inlineContent": [
        {
          "type": "text",
          "text": "An example of a dictionary."
        }
      ]
    }
  ],
  "example": {
    "type": "file",
    "content": [
      {
        "collapsible": false,
        "code": [
          "{",
          "  \"name\" : \"Info.plist\"",
          "}"
        ]
      }
    ]
  }
}

Note this fixture's example.type field ("file") reflects swift-docc's internal CodeExample.type property (Sources/SwiftDocC/Model/Rendering/Symbol/RESTExampleRenderSection.swift:24), which is described there as "an optional type for the example" but is not declared on the CodeExample object in the vendored wire schema (section 3) — per the generated Swift decoder, a strict decode of this exact JSON against Components.Schemas.CodeExample would simply ignore the extra type key.

An example of a dictionary.

1{
2  "name" : "Info.plist"
3}

3. Data sheet

Schema object: #/components/schemas/DictionaryExample in Sources/DocCArchive/Vendored/RenderNode.spec.json:1168-1189, one of the variants referenced from the RenderBlockContent discriminated union at spec line 476-477. It in turn references #/components/schemas/CodeExample (spec line 1125-1141) and #/components/schemas/CodeExampleContent (spec line 1107-1124). Generated Swift: Components.Schemas.DictionaryExample, a Codable, Hashable, Sendable struct at Sources/DocCArchive/generated/Types.swift:4769-4801; its example field is typed Components.Schemas.CodeExample (Types.swift:4707-4729), whose content field is [Components.Schemas.CodeExampleContent] (Types.swift:4684-4706).

FieldTypeRequired?Enum values / defaultNote
typestringyes"dictionaryExample"Discriminator; generated as _TypePayload with the single case .dictionaryExample.
summary[RenderBlockContent]no—Optional introductory content, rendered into the component's default slot ahead of the code listing.
exampleCodeExampleyes—The dictionary's sample code, passed straight through as the example prop.
CodeExample.syntaxstringno—Declared on the wire schema but not read anywhere in DictionaryExample.vue / CollapsibleCodeListing.vue — no per-language highlighting is driven by it in this render path.
CodeExample.content[CodeExampleContent]yes—Bound directly to CollapsibleCodeListing's content prop; one array element per visually-groupable chunk of lines.
CodeExampleContent.collapsiblebooleanyes—Adds the .collapsible class to that chunk's container (a distinct background/text color). Does not itself hide the lines at this call site, since DictionaryExample.vue never passes a truthy collapsed prop (see section 1).
CodeExampleContent.code[string]yes—The chunk's source lines, one array element per line (no embedded newlines).

Note the schema does not declare a metadata property on DictionaryExample (unlike CodeListing or EndpointExample's siblings), and, as shown in section 1, ContentNode.vue's render case for this kind does not check for one either.

DocCArchive's own transform layer does not yet do anything with this kind: MyHTMLTransformer and MyMarkdownTransformer (Sources/DocCArchive/DocCArchive.swift:242-254) are still stub placeholders that operate on a whole RenderNode and return a hardcoded HTML comment / empty string respectively, so a dictionaryExample block encountered while walking a parsed archive would decode correctly into Components.Schemas.DictionaryExample but has no dedicated conversion logic in this repository today.

4. HTML/CSS mapping in DocC-Render output

Root element: <div class="DictionaryExample"> (DictionaryExample.vue#L12). It has no scoped <style> block of its own — the file ends after its <script> section, so all visible styling comes from its children:

Notable SCSS/CSS from CollapsibleCodeListing.vue's scoped <style lang="scss"> block (imports docc-render/styles/_core.scss): $code-listing-with-numbers-padding and $code-number-padding (spacing variables from src/styles/core/_vars.scss), and a counter-reset: linenumbers / counter-increment: linenumbers pair driving each .code-number::before via CSS content: counter(linenumbers) — the line numbers are generated CSS content, not template-interpolated text. CSS custom properties consumed at paint time: --background / --color-code-background (listing background), --colors-grid / --color-grid (border color), --text / --color-code-plain (default text color), and --color-code-collapsible-background / --color-code-collapsible-text (applied to chunks with collapsible: true).

5. Modern CSS-only alternative

Not applicable

Current behavior, precisely: in the render path actually exercised by dictionaryExample nodes, there is no client-side interactive state at all. DictionaryExample.vue has no data, no event handlers, and no watchers; it statically composes a slot and one child component. CollapsibleCodeListing.vue likewise has no data, methods, or watchers of its own — its only dynamic behavior is the pure-template class binding { collapsible: content.collapsible === true, collapsed: content.collapsible === true && collapsed } on each chunk (line 19-20), and, as established in section 1, the collapsed prop this depends on is never actually passed a truthy value by DictionaryExample.vue, so in practice that class is dead code for this particular kind. The only genuinely dynamic piece anywhere nearby is the line-number gutter, and that is already implemented with a native CSS mechanism today (CSS counters via counter-reset/counter-increment/content: counter(...)), not JavaScript.

There is therefore no interactive behavior here to replace with <details>, :target, the Popover API, :has(), or any other stateful CSS mechanism: this block-content kind renders a static, non-collapsing, non-toggling code listing. (Contrast with the sibling codeListing kind's copy-to-clipboard button and asynchronous syntax highlighter, neither of which is present in this component tree.) If a future revision of DictionaryExample.vue started passing a real collapsed prop through (so that collapsible chunks could be toggled open/closed by a reader), that specific show/hide toggle would be a textbook fit for a checkbox/radio-input + :checked + general-sibling-selector pattern, or a native <details>/<summary> per chunk — but that would be speculating about code that does not exist in the pinned commit, so the verdict for the kind as it actually behaves today is "not applicable."