inline

image

Wire value: "image"

Appears on: Documentation Topic, Tutorial (Project), Tutorial Article

1. How swift-docc-render consumes this

Grepping src/components/ for the literal string 'image' lands, as with the other inline kinds, on src/components/ContentNode.vue's wire-constant table, where the InlineType object maps the key to itself:

const InlineType = {
  codeVoice: 'codeVoice',
  emphasis: 'emphasis',
  image: 'image',
  ...
};

(ContentNode.vue#L56-L69.) That constant is matched inside the module-level renderNode() factory's switch (node.type) dispatch table. The image arm is the most branching of any inline case — it inspects the node's metadata before deciding which of three different child components to delegate to:

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 distinct rendering paths fall out of this:

InlineImage.vue is a thin wrapper — its entire template is one line delegating to the shared ImageAsset component:

<template>
  <ImageAsset :alt="alt" :variants="variants"/>
</template>

(InlineImage.vue#L11-L13.) ImageAsset.vue (src/components/ImageAsset.vue) is where the real work happens: it groups the variants array by light/dark appearance and by pixel density (1x/2x/3x) via the shared imageAsset mixin, builds a <picture> element with a (prefers-color-scheme: dark) <source> when both an "Auto" appearance preference and a dark variant exist, and otherwise renders a single <img> with a computed srcset. It also has a one-time mounted() side effect that measures the loaded image's intrinsic pixel dimensions and divides by its density trait to assign an explicit width/height, so the displayed size is stable across 1x/2x/3x devices, plus an @error handler that swaps in a bundled placeholder graphic (theme/assets/img/no-image@2x.png) if the real asset URL 404s.

Also worth noting: the parent block-level handler for paragraph nodes special-cases a paragraph whose only inline child is an image node, adding an inline-image-container class to the enclosing <p> so that a lone image paragraph gets image-specific vertical spacing instead of ordinary text spacing:

case BlockType.paragraph: {
  const hasSingleImage = node.inlineContent.length === 1
    && node.inlineContent[0].type === InlineType.image;
  const props = hasSingleImage ? { class: ['inline-image-container'] } : {};

  return createElement('p', props, (
    renderChildren(node.inlineContent)
  ));
}

(ContentNode.vue#L305-L313.)

See also: The references map — how this and every other reference-dictionary lookup works across kinds.

See also: Asset variant resolution — the full light/dark/@2x/@3x bucketing mechanism shared with video and hero backgrounds.

2. Example JSON and rendered mockup

No fixture in this repository's test archives or in swift-docc's test suite contains the inline image node as literal JSON text: the Fixtures/*.doccarchive archives in this repo have no data/ RenderNode JSON checked in (only static site assets), and swift-docc's SwiftDocCTests construct RenderInlineContent.image(identifier:metadata:) as Swift enum literals (e.g. in Tests/SwiftDocCTests/Model/RenderContentMetadataTests.swift and Tests/SwiftDocCTests/Rendering/InlineContentPlainTextTests.swift) rather than as raw JSON documents. The example below is therefore hand-written to match the schema in Section 3, modeled directly on the shape those Swift-literal tests exercise (an image node with metadata.abstract set, which triggers the figure/caption path in Section 1) plus a matching references entry shaped per ImageRenderReference.

{
  "type": "image",
  "identifier": "figure1.png",
  "metadata": {
    "anchor": "figure-1",
    "abstract": [
      { "type": "text", "text": "The layout of a three-pane split view." }
    ]
  }
}

Referenced entry in the RenderNode's top-level references map:

"figure1.png": {
  "type": "image",
  "identifier": "figure1.png",
  "alt": "Diagram of a three-pane split view layout",
  "variants": [
    { "url": "/images/figure1@2x.png", "traits": ["2x", "light"] },
    { "url": "/images/figure1~dark@2x.png", "traits": ["2x", "dark"] }
  ]
}
[ image: figure1.png ]
The layout of a three-pane split view.

3. Data sheet

fieldtyperequired?enum values / defaultnote
typestringyes["image"]Discriminator; always the literal string "image".
identifierstringyesformat: reference(ImageRenderReference)Key into the RenderNode's top-level references map; resolves to an ImageRenderReference object carrying the actual asset URLs/variants.
metadataobject (RenderContentMetadata)no—Optional; presence/shape of its sub-fields is what steers swift-docc-render between the plain-image, figure, and device-frame rendering paths (Section 1).
metadata.anchorstringno—Sets the id on the enclosing <figure>; also triggers the figure path if present.
metadata.titlestringno—If set alongside a non-empty abstract, the caption is rendered above the image (CaptionPosition.leading) instead of below.
metadata.abstractarray of RenderInlineContentno—Caption text; presence (even without anchor) triggers the figure/figcaption path.
metadata.deviceFramestringno—Name of a device chassis (e.g. an iPhone model key) to frame the image in; only checked if the figure path wasn't already triggered.

Source: Sources/DocCArchive/Vendored/RenderNode.spec.json, the Image schema object (lines 1332–1351, one case of the RenderInlineContent discriminated union defined at lines 1190–1226) and the RenderContentMetadata object (lines 484–503). The referenced asset shape comes from a separate spec file, Sources/DocCArchive/Vendored/Assets.json (ImageRenderReference, lines 39–65; RenderReferenceVariant/RenderReferenceVariantTrait, lines 66–105), which the merged spec (Sources/DocCArchive/Vendored/merged-spec.json, around line 171) additionally shows carries an optional svgID field for SVG variants not present in the standalone Assets.json snapshot. Cross-checked against the generated Swift types in Sources/DocCArchive/generated/Types.swift:

public struct Image: Codable, Hashable, Sendable {
  @frozen public enum _TypePayload: String, Codable, Hashable, Sendable, CaseIterable {
    case image = "image"
  }
  public var _type: Components.Schemas.Image._TypePayload
  public var identifier: Swift.String
  public var metadata: Components.Schemas.RenderContentMetadata?
  ...
}

This struct is one case (.Image) of the generated Components.Schemas.RenderInlineContent discriminated union (line 1547 of the same file). On the authoring side, swift-docc's Swift model defines the equivalent case as case image(identifier: RenderReferenceIdentifier, metadata: RenderContentMetadata?) in RenderInlineContent.swift (an enum, not a struct — so, as with other inline kinds, no separate swiftStructSite exists upstream; the wire-level struct only exists in this repo's OpenAPI-generated code) (/Users/joeheck/src/swift-project/swift-docc/Sources/SwiftDocC/Model/Rendering/Content/RenderInlineContent.swift, line 40 for the case declaration). What an author writes to produce this node: a plain Markdown image, ![alt text](image-name), is visited by RenderContentCompiler.visitImage(_ image: Markdown.Image) (Sources/SwiftDocC/Model/Rendering/RenderContentCompiler.swift, lines 98–123), which resolves the source string against the bundle's registered image assets and emits RenderInlineContent.image(identifier:metadata:) — metadata stays nil unless a caption or device-frame directive was also supplied (e.g. via the @Image tutorial-authoring directive, which can carry an anchor/caption/device-frame).

4. HTML/CSS mapping in DocC-Render output

For the plain-image path, the final DOM is a <picture> (or a single fallback <img class="fallback"> if the asset failed to load) produced by ImageAsset.vue, itself unwrapped from InlineImage.vue. InlineImage.vue carries one scoped style rule of its own:

:deep(img) {
  max-width: 100%;
}

(InlineImage.vue#L35-L37.) ImageAsset.vue itself declares no <style> block; the generic content-area rules in DocumentationTopic/ContentNode.vue also apply to any img nested in the rendered content tree (display: block; margin: auto; max-width: 100%;), and that same file adds top-margin spacing between an .inline-image-container paragraph and its siblings via a shared between-els() selector helper (DocumentationTopic/ContentNode.vue#L57-L65).

For the figure path, the DOM is <figure id="..."> (from ContentNode/Figure.vue, which declares no styles of its own beyond the bare template) wrapping the image and, if present, a <figcaption class="caption"> from ContentNode/Caption.vue, which is styled with:

.caption {
  @include font-styles(documentation-caption);
  margin: 0 0 var(--spacing-stacked-margin-large) 0;

  &.trailing {
    margin: var(--spacing-stacked-margin-large) 0 0 0;
    text-align: center;
  }
}

(Caption.vue#L61-L72.)

For the device-frame path, the DOM is <div class="device-frame" data-device="..."> (from ContentNode/DeviceFrame.vue) containing a .device-screen wrapper around the slotted image and an absolutely-positioned .device chassis overlay. All frame geometry is passed as CSS custom properties computed per-device from a DeviceFrames lookup table: --screen-top, --screen-left, --screen-width, --screen-height, --screen-aspect, --frame-width, --frame-aspect, --device-light-url, --device-dark-url (DeviceFrame.vue#L41-L64), consumed by the scoped SCSS in the same file (DeviceFrame.vue#L78-L137), which also switches the chassis background image under @include prefers-dark.

None of these three paths involve any interaction-driven class toggling; all class/attribute state is computed once from the wire data at render time (color-scheme response is delegated to the prefers-color-scheme media feature and the app's stored color-scheme preference, not to per-image component state).

5. Modern CSS-only alternative

Not applicable

Current behavior, precisely: none of the three components involved in rendering an inline image hold any interactive, user-driven state. ImageAsset.vue has exactly one piece of reactive data(), fallbackImageSrcSet, which is set once by the @error handler if the real image URL fails to load, and one mounted() side effect that measures the loaded image's intrinsic size to assign a stable width/height — both are one-shot reactions to browser/network events, not something a user toggles, and neither has a CSS-only equivalent to "hold state" for because there is no state to hold beyond what the native <img>@error event and the image's own loading already are. Light/dark variant selection is already done with a native mechanism, not JS: Figure.vue's <picture> with a <source media="(prefers-color-scheme: dark)"> is exactly the browser-native way to swap image sources by color-scheme preference, and the DeviceFrame chassis swap uses a @include prefers-dark SCSS mixin that likewise compiles down to a prefers-color-scheme media query. There is no click handler, no disclosure/expand behavior, and no navigation state anywhere in the image rendering path itself for a mechanism like <details>/<summary>, :target, the Popover API, <dialog>, or CSS anchor positioning to replace.

One tangential, but honest, data point: elsewhere in this codebase (specifically Tutorial/SectionSteps.vue, not any of the three components used for the plain inline image kind covered by this page) swift-docc-render already uses the modern selector :has([data-orientation="landscape"]) to change a tutorial step's asset-column width based on an image's orientation attribute (SectionSteps.vue#L473-L475), proving :has() is both applicable in this codebase's browser support target and already in production use for image-orientation-driven layout — but that is a different rendering context (tutorial steps) from the plain-article inline image kind this page documents, which has no such layout-branching CSS today.