1. How swift-docc-render consumes this
There are two distinct places the literal string "image" appears on the wire, and it's
important to keep them apart. One is the inline content node that sits inside an
inlineContent/content array (schema name Image, generated Swift
Components.Schemas.Image) — it carries only a type and an
identifier pointer, no pixels. The other is the reference-dictionary entry that the
pointer resolves to (schema name ImageRenderReference, matching this page's
doccArchiveType and swift-docc's RenderReferenceType.image case /
ImageReference struct) — it carries the actual alt text and
variants (URLs, pixel-density/appearance traits, optional SVG element id). This page
documents the reference-dictionary entry; the inline node that points at it is covered in the data
sheet below for completeness since the two are inseparable in practice.
Grepping src/components/ for the literal string 'image' turns up
src/components/ContentNode.vue's InlineType constant table
(ContentNode.vue#L56-L69), whose image key holds
InlineType.image = 'image'. That constant is matched in the renderNode()
factory function's switch (node.type) dispatch table:
case InlineType.image: {
if (node.metadata && (node.metadata.anchor || node.metadata.abstract)) {
return renderFigure(node);
}
const image = references[node.identifier];
if (!image) return null;
if (node.metadata && node.metadata.deviceFrame) {
return renderDeviceFrame(node);
}
return createElement(InlineImage, {
props: {
alt: image.alt,
variants: image.variants,
},
});
}
(ContentNode.vue#L442-L458.) Three branches, checked in order. If
node.metadata.anchor or node.metadata.abstract is present, the node is routed
through the shared renderFigure() helper
(ContentNode.vue#L220-L249), which re-invokes renderChildren on the image node
(with metadata stripped down to everything except abstract/anchor/title) inside
a <figure>, and renders metadata.abstract as a Caption
(<figcaption>), positioned above the image if metadata.title is also set,
otherwise below it. Otherwise, the reference is looked up by node.identifier in the render
node's shared references map; if it can't be resolved the node renders as nothing
(return null). If it resolves and node.metadata.deviceFrame is set, the node is
instead routed through renderDeviceFrame()
(ContentNode.vue#L251-L257), which wraps an InlineImage in a
DeviceFrame component keyed by the device string. In the plain case, an
InlineImage component is mounted with just alt and variants plucked
off the resolved ImageRenderReference object — the block's own identifier
and metadata are discarded once the lookup succeeds.
There is a fourth piece of context worth noting from the surrounding paragraph block
handling: if a paragraph's inlineContent is a single image node, the enclosing
<p> gets an extra inline-image-container class
(ContentNode.vue#L305-L313), which is purely a styling hook (see Section 4) and has no
effect on which Vue component renders the image itself.
src/components/ContentNode/InlineImage.vue is a thin wrapper that forwards straight to the
shared ImageAsset component:
<template>
<ImageAsset :alt="alt" :variants="variants"/>
</template>
(InlineImage.vue#L11-L13.) Its only scoped style constrains any nested <img>
to max-width: 100%
(InlineImage.vue#L34-L38).
src/components/ImageAsset.vue is where the variants array actually becomes DOM.
It groups the reference's flat variants array into light/dark buckets and per-density
srcset strings via the imageAsset mixin
(mixins/imageAsset.js#L20-L30), then picks one of three template branches depending on the
app-wide preferredColorScheme setting (light / dark / auto, read from
AppStore.state, not the OS alone): a fallback <img> if a previous load
already failed, a dark-preferring <img> if the user explicitly chose "Dark" and a dark
variant exists, or (the "Auto" default) a native <picture> with a
<source media="(prefers-color-scheme: dark)"> plus a light/default
<img> fallback
(ImageAsset.vue#L11-L59). On an error event from the mounted
<img>, handleImageLoadError() swaps in a bundled
no-image@2x.png placeholder
(ImageAsset.vue#L150-L155). After the image first loads, if no explicit size was already
supplied by the JSON, optimizeImageSize() measures the loaded image's intrinsic dimensions
and divides by its pixel density to compute a stable width/height for layout,
so 1x and 2x variants of the same asset render at the same on-page size
(ImageAsset.vue#L156-L219).
When metadata.deviceFrame routes through DeviceFrame.vue instead, the resolved
device name is looked up against a theme-settings table and rendered as CSS custom properties
(background art URLs, screen inset percentages) on a div.device-frame wrapper, with the
actual InlineImage positioned absolutely inside a div.device-screen cutout
(DeviceFrame.vue#L11-L76).
See also: Asset variant resolution — the full light/dark/@2x/@3x bucketing mechanism shared with video and hero backgrounds.
See also: The references map — how this and every other reference-dictionary lookup works across kinds.
2. Example JSON and rendered mockup
A real ImageRenderReference fixture (the reference-dictionary entry) exists in swift-docc's
test suite: Tests/SwiftDocCTests/Indexing/RenderIndexTests.swift, inside a
RenderIndex.fromString(...) JSON literal used to assert round-trip encoding of a rendered
index (lines 803–818 at the pinned commit). It shows a plus.svg icon reference with a
1x/light SVG variant carrying an svgID:
"references" : {
"plus.svg" : {
"alt" : "A plus icon.",
"type" : "image",
"identifier" : "plus.svg",
"variants" : [
{
"url" : "/images/org.swift.docc.Book/plus.svg",
"traits" : [
"1x",
"light"
],
"svgID" : "plus-id"
}
]
}
}
That fixture only shows the reference-dictionary side. No fixture in either
Tests/DocCArchiveTests/Fixtures/ (neither .doccarchive bundle's
data/documentation/*.json files contain an inline "type": "image" content node
— their sample articles don't embed any images) or the rest of
Tests/SwiftDocCTests/ pairs a real inline Image node with its reference in one
place, so the combined example below splices the real fixture's reference object together with a
hand-written inline node that points at it, following the Image schema from Section 3 (an
author would produce this pair by writing standard Markdown  image syntax,
or the tutorial-only @Image(source:alt:) directive documented in swift-docc's
Directives.md).
{
"type": "image",
"identifier": "plus.svg",
"metadata": {
"abstract": [
{ "type": "text", "text": "The add-item icon used throughout the toolbar." }
]
}
}
Its companion reference in the render node's top-level references map (verbatim from the
RenderIndexTests.swift fixture cited above):
"plus.svg": {
"alt": "A plus icon.",
"type": "image",
"identifier": "plus.svg",
"variants": [
{
"url": "/images/org.swift.docc.Book/plus.svg",
"traits": ["1x", "light"],
"svgID": "plus-id"
}
]
}
mockup: because metadata.abstract is present, ContentNode.vue routes
this node through renderFigure(), wrapping the resolved image in a
<figure> with the abstract rendered as a trailing <figcaption> (no
metadata.title here, so the caption sits below rather than above). Without an abstract or
anchor, the same reference would render as a bare <picture>/<img>
with no figure/caption wrapper at all.
3. Data sheet
Source: Sources/DocCArchive/Vendored/RenderNode.spec.json. Two schema objects are involved.
The inline content node, #/components/schemas/Image (lines 1332–1351), is one arm of
the RenderInlineContent discriminated union; cross-checked against
Components.Schemas.Image in Sources/DocCArchive/generated/Types.swift (lines
1814–1845). The reference-dictionary entry it points at,
#/components/schemas/ImageRenderReference (lines 1552–1578), is one arm of the
RenderReference discriminated union that populates a render node's top-level
references map; cross-checked against
Components.Schemas.ImageRenderReference (generated lines 376–414, exposed as the
.ImageRenderReference case of the generated RenderReference enum at line 2117).
This matches this page's doccArchiveType and swift-docc's ImageReference struct
(Sources/SwiftDocC/Model/Rendering/References/ImageReference.swift:14), whose
type property is hard-coded to .image and which conforms to the
RenderReference protocol's type: RenderReferenceType requirement
(Sources/SwiftDocC/Model/Rendering/References/RenderReference.swift:29, the case
image arm of the RenderReferenceType enum).
| Field | Type | Required | Enum values / default | Note |
|---|---|---|---|---|
Image (inline content node) | ||||
type |
string | yes | "image" (single-value enum) |
Generated as _TypePayload { case image = "image" }; the discriminator matched by
InlineType.image in ContentNode.vue. |
identifier |
string | yes | — | format: reference(ImageRenderReference). A key into the render node's
references map; if unresolvable, ContentNode.vue renders nothing for the node. |
metadata |
RenderContentMetadata object |
no | default: absent (decoded as nil) |
Schema at lines 484–503 / generated lines 2768–2794. Nested fields: anchor
(string, optional named anchor — triggers the figure branch), title (string, optional
caption title), abstract (array of RenderInlineContent, optional caption body
— also triggers the figure branch), deviceFrame (string, optional device-frame
identifier, checked only after the figure branch is ruled out). |
ImageRenderReference (reference-dictionary entry) | ||||
type |
string | yes | "image" (single-value enum) |
Generated as _TypePayload { case image = "image" }. Matches
RenderReferenceType.image in swift-docc's Swift model. |
identifier |
string | yes | — | The dictionary key this object is stored under in references; also duplicated as this
field for self-description. |
alt |
string | no | nullable; default: absent | Alternate/accessibility text. Passed straight through as the alt prop to
InlineImage/ImageAsset and ultimately the native <img alt>
attribute. Swift-docc's ImageReference.altText documents this as text for screen readers. |
variants |
array of RenderReferenceVariant |
yes | — | Schema at lines 1579–1600 / generated lines 415–444. Each variant has a required
url (string), a required traits array of RenderReferenceVariantTrait
values (enum "1x"/"2x"/"3x"/"light"/"dark";
schema lines 1601–1604 / generated lines 447–453, generated as
case _1x = "1x", etc.), and an optional svgID (string) naming the element id to
render when the asset is an SVG sprite sheet. ImageAsset.vue groups these variants by
appearance trait (light/dark) and then by density trait (1x/2x/3x) to build srcset strings. |
DocCArchive's own transform layer does not yet act on this kind: MyHTMLTransformer and
MyMarkdownTransformer (Sources/DocCArchive/DocCArchive.swift) are still stub
placeholders — the former returns a hardcoded HTML comment and the latter an empty string —
so a parsed Components.Schemas.Image inline node or
Components.Schemas.RenderReference.ImageRenderReference case would currently reach a
transformer only as an untyped case inside the still-unimplemented walk over
RenderInlineContent/references, with no real conversion logic written for
either.
4. HTML/CSS mapping in DocC-Render output
In the plain case (no metadata.anchor/abstract/deviceFrame), the
DOM is just a native <picture> (from ImageAsset.vue) containing an
optional <source media="(prefers-color-scheme: dark)"> and a single <img
decoding="async" data-orientation="...">, with no wrapping <div> of its own
— the enclosing element comes from whatever block contains the inline content (typically a
<p class="inline-image-container"> when the image is the paragraph's only child, per
ContentNode.vue#L305-L313). If the source image failed to load, the <picture>
is replaced by a single fallback <img class="fallback"> pointing at the bundled
placeholder. With a caption, the whole thing is wrapped in <figure id="{anchor}"> (from
Figure.vue) with a <figcaption class="caption leading|trailing"> (from
Caption.vue) placed before or after depending on whether metadata.title was also
supplied. With a device frame, a div.device-frame[data-device="{deviceFrame}"] (from
DeviceFrame.vue) wraps a div.device-screen.with-device containing the picture,
plus a decorative div.device for the frame artwork.
Relevant SCSS: InlineImage.vue's own scoped style is minimal — just
:deep(img) { max-width: 100%; }
(InlineImage.vue#L34-L38). The heavier layout rules live one level up, in
src/components/DocumentationTopic/ContentNode.vue's scoped SCSS block, which imports
docc-render/styles/_core.scss and declares generic img { display: block; margin: auto;
max-width: 100%; } plus a between-els('.inline-image-container') helper selector that
adds margin-top: var(--spacing-stacked-margin-xlarge) whenever an
.inline-image-container paragraph is adjacent to another block-level sibling
(DocumentationTopic/ContentNode.vue#L40-L75). DeviceFrame.vue's scoped SCSS
consumes several CSS custom properties it computes itself from a theme-settings lookup:
--screen-top, --screen-left, --screen-width,
--screen-height, --screen-aspect, --frame-width,
--frame-aspect, --device-light-url, and --device-dark-url
(DeviceFrame.vue#L41-L108), and also swaps its background art via a
@include prefers-dark mixin. ImageAsset.vue itself has no <style>
block of its own; its native <picture>/<img>/<source>
structure relies entirely on the ancestor rules above plus normal browser image layout.
5. Modern CSS-only alternative
PARTIAL
Current JS/Vue behavior in play: ImageAsset.vue reads a global, three-state
preferredColorScheme (light/dark/auto) out of a shared Vuex-like AppStore.state
object (set elsewhere in the app by an explicit user toggle, not just the OS setting) and uses that,
via computed properties prefersAuto/prefersDark, to pick between three mutually
exclusive template branches — a fallback <img>, a forced-dark
<img v-bind="darkVariantAttributes">, or a <picture> containing a
<source media="(prefers-color-scheme: dark)"> plus a light/default
<img> fallback.
For the "Auto" branch specifically — the default, and the one most visitors see — DocC-Render
is already using a purely native CSS-adjacent mechanism: the browser's own
prefers-color-scheme media feature inside a <picture>/<source
media> pair does the light/dark selection with no JavaScript involved once the markup is
emitted; the Vue layer's job there is just to decide *whether* to emit that native construct, and to
build the srcset strings from the reference's variants array. That decision-making
step could not be replaced by CSS alone, because it depends on an explicit, app-level three-way user
preference (persisted across the whole site, overriding the OS setting when set to "Light" or "Dark")
rather than only the OS media query — there is no selector for "the user picked 'Dark' in our own
in-app toggle" the way :checked matches a checkbox. A radio-input-driven approach (three
hidden <input type="radio" name="color-scheme"> elements plus :checked and
general sibling selectors to swap which <picture>/<img> variant is
displayed) could hold the three-way "Light/Dark/Auto" *choice* itself in pure CSS, but the
"Auto" state still needs the prefers-color-scheme media query nested inside that same rule
to resolve to an actual light/dark image, and the "load-error fallback" branch
(fallbackImageSrcSet, driven by a real @error event fired only after a network
request fails) has no CSS equivalent at all — CSS has no selector that reacts to an
<img> failing to load. So the color-scheme branch of this kind's behavior is
replaceable with native CSS (prefers-color-scheme, already partially in use, extendable with
a radio/:checked override for the explicit in-app toggle), while the load-error fallback
branch is not. Verdict is therefore partial.