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:
-
Unlike
codeListing,image, andvideo, this case does not inspectnode.metadataand never routes through the sharedrenderFigurehelper — adictionaryExamplenode is always rendered as a plainDictionaryExamplecomponent, even if ametadata.anchorhappened to be present on the node (the render node's ownmetadatafield, if any, is simply not read here). -
node.summary(an optional array ofRenderBlockContent) is recursively rendered viarenderChildrenand passed as the component's default<slot>content, whilenode.example(theCodeExampleobject) is passed through untouched as a prop — it is not walked or transformed byContentNode.vueat all.
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.
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).
| Field | Type | Required? | Enum values / default | Note |
|---|---|---|---|---|
type | string | yes | "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. |
example | CodeExample | yes | — | The dictionary's sample code, passed straight through as the example prop. |
CodeExample.syntax | string | no | — | 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.collapsible | boolean | yes | — | 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:
- The
summaryslot content renders as whatever block elementsrenderChildrenproduces for thoseRenderBlockContentnodes (typically a plain<p>). <div class="collapsible-code-listing">(optionally.single-linewhen the first chunk has exactly one code line) — the root ofCollapsibleCodeListing.vue, styled by its own scoped SCSS (CollapsibleCodeListing.vue#L58-L146).- Inside it,
<pre><CodeBlock>(the sharedcomponents/CodeBlock.vue) wraps one<div class="container-general">perCodeExampleContentchunk, with modifier classescollapsible(that chunk'scollapsibleflag) andcollapsed(only ever added when bothcollapsibleis true and the component's owncollapsedprop is true — never the case fordictionaryExample, see section 1). - Each line is a
<div class="code-line-container">containing<div class="code-number">(a CSS counter-driven line number, always present here sinceshowLineNumbersis hard-coded true) and<div class="code-line">with the plain line text.
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."