1. How swift-docc-render consumes this
Grepping src/components/ for the literal string 'reference' lands 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',
inlineHead: 'inlineHead',
link: 'link',
newTerm: 'newTerm',
reference: 'reference',
strong: 'strong',
text: 'text',
superscript: 'superscript',
subscript: 'subscript',
strikethrough: 'strikethrough',
};
(ContentNode.vue#L56-L69.)
That constant is matched inside the module-level renderNode() factory function
(defined at
ContentNode.vue#L121),
in its switch (node.type) dispatch table, in the InlineType.reference arm:
case InlineType.reference: {
const reference = references[node.identifier];
if (!reference) return null;
const titleInlineContent = node.overridingTitleInlineContent
|| reference.titleInlineContent;
const titlePlainText = node.overridingTitle || reference.title;
return createElement(Reference, {
props: {
url: reference.url,
kind: reference.kind,
role: reference.role,
isActive: node.isActive,
ideTitle: reference.ideTitle,
titleStyle: reference.titleStyle,
hasInlineFormatting: !!titleInlineContent,
},
class: 'inline-link',
}, (
titleInlineContent ? renderChildren(titleInlineContent) : titlePlainText
));
}
(ContentNode.vue#L467-L487.)
Unlike most other inline kinds, this one does not render its payload directly—the wire node
only carries an opaque identifier (a doc:// URI), isActive, and an
optional title override. The actual url, kind, role, title,
and styling hints are looked up from the top-level references dictionary (the RenderNode's
RenderReferenceMap, injected via the referencesProvider mixin at
src/mixins/referencesProvider.js)
keyed by that identifier. If no matching entry exists in references, the whole node silently
renders as null—there is no fallback text or broken-link placeholder at this layer.
The merged props are handed to a dedicated child component,
src/components/ContentNode/Reference.vue,
whose entire template just picks a concrete leaf component via a computed refComponent:
<template>
<component :is="refComponent" :url="urlWithParams" :is-active="isActiveComputed">
<slot />
</component>
</template>
refComponent({ isInternal, isDisplaySymbol }) {
if (isInternal) {
return isDisplaySymbol ? ReferenceInternalSymbol : ReferenceInternal;
}
return isDisplaySymbol ? ReferenceExternalSymbol : ReferenceExternal;
},
(Reference.vue#L12-L15
and
Reference.vue#L74-L79.)
isInternal is true when the URL starts with / or # and resolves via the
Vue Router to something other than the "not found" route; isDisplaySymbol is true when the
looked-up reference's kind is symbol (and it has no inline-formatted title override)
so the link text should be rendered in code style. That gives four leaf components, all in
src/components/ContentNode/: ReferenceInternal and ReferenceExternal
render a Vue <router-link> or a plain <a> respectively (falling back to
a bare <span> when url is empty or isActive is false);
ReferenceInternalSymbol and ReferenceExternalSymbol wrap those same two in a
CodeVoice component so the link text renders as inline code:
<template>
<ReferenceInternal v-bind="$props">
<CodeVoice>
<slot />
</CodeVoice>
</ReferenceInternal>
</template>
(ReferenceInternalSymbol.vue, full file.) Separately, ContentNode.vue also reads the
reference discriminator directly (not through the dispatch table) inside its
plaintext computed property, again resolving the title via the references map:
if (node.type === InlineType.reference) {
const title = references[node.identifier]?.title ?? '';
return `${text}${title}`;
}
See also: The references map — how this and every other reference-dictionary lookup works across kinds.
2. Example JSON and rendered mockup
A real fixture was found in swift-docc's own test suite (not in DocCArchive's fixtures—grepping
Tests/DocCArchiveTests/Fixtures/ for "type": "reference" in both
ExampleDocs.doccarchive and SampleLibrary.doccarchive only turned up the unrelated
top-level "references" map key, never an actual inline reference node). The
example below combines two real fixtures:
Tests/SwiftDocCTests/Rendering/Rendering Fixtures/term-lists-1.json (a bare inline reference
inside a term list, with no title override) and
Tests/SwiftDocCTests/Rendering/Rendering Fixtures/external-location-custom-url.json (which
demonstrates overridingTitle on a reference node used as a download action). The
paragraph/reference pairing and the matching references entry shown here are assembled from
those two real snippets, not fabricated from scratch.
{
"type": "paragraph",
"inlineContent": [
{ "type": "text", "text": "See " },
{
"type": "reference",
"identifier": "doc://org.swift.docc.example/downloads/sample.zip",
"isActive": true,
"overridingTitle": "Download"
},
{ "type": "text", "text": " for the full project." }
]
}
Matching entry in the RenderNode's top-level references map, keyed by the same identifier:
"references": {
"doc://org.swift.docc.example/downloads/sample.zip": {
"type": "file",
"identifier": "doc://org.swift.docc.example/downloads/sample.zip",
"url": "/downloads/sample.zip",
"title": "sample.zip"
}
}
See Download for the full project.
3. Data sheet
| field | type | required? | enum values / default | note |
|---|---|---|---|---|
type | string | yes | ["reference"] | Discriminator; always the literal string "reference". |
isActive | boolean | yes | — | Whether the reference should render as a live link. When false, DocC-Render's leaf components (ReferenceInternal/ReferenceExternal) fall back to a plain <span> instead of an <a>/<router-link>. |
identifier | string (format: "reference") | yes | — | Key into the RenderNode's top-level references map (a doc:// URI or similar opaque ID); this is where the actual url, kind, role, and default title live, not on this node. |
overridingTitle | string | no | no default (absent = use the resolved reference's own title) | Plain-text override for the link's display title, used e.g. when a symbol link is manually retitled. |
overridingTitleInlineContent | array of RenderInlineContent | no | no default | Formatted-title override (e.g. containing a codeVoice span); takes precedence over overridingTitle for rendering, per swift-docc's decoder, which derives a plain-text overridingTitle from it when only the formatted form is present on the wire. |
Source: Sources/DocCArchive/Vendored/RenderNode.spec.json, the Reference schema
object (line 1302), one of the eleven members of the RenderInlineContent
oneOf discriminated union (line 1190). Cross-checked against the generated Swift type in
Sources/DocCArchive/generated/Types.swift:
public struct Reference: Codable, Hashable, Sendable {
@frozen public enum _TypePayload: String, Codable, Hashable, Sendable, CaseIterable {
case reference = "reference"
}
public var _type: Components.Schemas.Reference._TypePayload
public var isActive: Swift.Bool
public var identifier: Swift.String
public var overridingTitle: Swift.String?
public var overridingTitleInlineContent: [Components.Schemas.RenderInlineContent]?
...
}
This struct is one case (.Reference) of the generated
Components.Schemas.RenderInlineContent indirect enum in the same file (line 1535,
case Reference(Components.Schemas.Reference)). Note the vendored JSON schema's
required array (type, isActive, identifier) matches the
generated struct's non-optional stored properties exactly—the two title fields are optional on both
sides. On the authoring side, swift-docc's Swift model defines the equivalent case as
case reference(identifier: RenderReferenceIdentifier, isActive: Bool, overridingTitle: String?,
overridingTitleInlineContent: [RenderInlineContent]?) in RenderInlineContent.swift
(/Users/joeheck/src/swift-project/swift-docc/Sources/SwiftDocC/Model/Rendering/Content/RenderInlineContent.swift,
line 43), documented there simply as "A reference to another resource." (line 42). Its hand-written
Codable decoder (lines 100–120 of the same file) is notably more permissive than the JSON
schema: it accepts either a plain-text overridingTitle, a formatted
overridingTitleInlineContent, both, or neither, and synthesizes the plain-text field from the
formatted one when only the latter is present—logic the wire-format schema table above does not (and
cannot) express, since JSON Schema only names the two fields as independently optional. No separate
swiftStructSite exists upstream for this case; the wire-level struct only exists in this
repo's OpenAPI-generated code. On the authoring side, this case is what DocC produces from Markdown
documentation links—either symbol links (``MyClass/myProperty``) or general
doc:-scheme links (<doc:MyArticle>)—per
Sources/SwiftDocC/SwiftDocC.docc/SwiftDocC/LinkResolution.md; the retitling behavior
(overridingTitle) corresponds to writing custom link text instead of using the target's
own title.
Within this repository, DocCArchive's own transform layer does not yet do anything specific with this
kind: MyHTMLTransformer and MyMarkdownTransformer
(Sources/DocCArchive/DocCArchive.swift) are still stub placeholders that operate on a whole
RenderNode and return a hardcoded HTML comment or an empty string, respectively—neither
one walks RenderInlineContent case-by-case yet, so reference nodes (and the
references map lookups they depend on) are not yet resolved or rendered by this library.
4. HTML/CSS mapping in DocC-Render output
The rendered DOM depends on three independent booleans computed by Reference.vue
(isInternal, isActiveComputed, and isDisplaySymbol), giving four
possible shapes:
- Internal, active, non-symbol:
<router-link class="inline-link" to="...">…</router-link>(renders as an<a>at runtime). - External, active, non-symbol:
<a class="inline-link" href="...">…</a>. - Either, inactive (or no
url):<span class="inline-link">…</span>. - Symbol-kind reference (
kind === 'symbol', no inline title override): the above, with the slot content additionally wrapped inCodeVoice's<code>element, e.g.<a class="inline-link" href="..."><code>MyClass.myProperty</code></a>.
The inline-link class is applied at the dispatch site in ContentNode.vue
(ContentNode.vue#L483),
not inside Reference.vue itself. Its only styling rule lives in the shared typography partial:
a {
color: var(--colors-link, var(--color-link));
&:link,
&:visited {
text-decoration: none;
}
// Inline links need to be underline under WCAG 2.2 compliance
&:hover, &.inline-link {
@include underline-text;
}
&:active {
text-decoration: none;
}
}
(src/styles/base/_typography.scss#L131-L152.)
So every .inline-link is always underlined (the comment explains this is an explicit WCAG 2.2
choice, since color alone isn't a sufficient link affordance), regardless of hover state. The link color
comes from the CSS custom property --color-link, defined in the color-theme partials
src/styles/core/colors/_light.scss (line 101, --color-link: var(--color-figure-blue))
and its dark-mode counterpart. When the symbol-styled leaf components are used, the nested
CodeVoice element additionally consumes --color-inline-code-background,
--inline-code-padding, and --inline-code-border-radius as documented on the
codeVoice kind page. No SCSS partial targets
ReferenceInternal, ReferenceExternal, or their Symbol variants by
component name—all of their visual styling flows through the generic a/.inline-link
rule above plus whatever CodeVoice contributes when wrapped.
5. Modern CSS-only alternative
Not applicable
Current behavior, precisely: Reference.vue holds no reactive component state of its own
(no data(), no click handlers, no toggled visibility). Its only "logic" is a set of
computed, one-shot decisions made from static props at render time—isInternal
(string prefix check plus a synchronous Vue Router resolve), isDisplaySymbol (a comparison
against the looked-up reference's kind/role), and refComponent
(a plain lookup table over those two booleans that picks which of four leaf components to instantiate).
The four leaf components (ReferenceInternal, ReferenceExternal, and their
Symbol variants) are themselves purely presentational: each renders either a
<router-link>/<a> or a <span> based on a
v-if="url && isActive" template condition—also evaluated once, from props, with
no runtime interaction.
There is nothing here that toggles, discloses, or changes state in response to user interaction after
the initial render: no open/closed state, no tab/panel switching, no focus trap, no modal. The entire
"behavior" is server/build-time-equivalent branching over static data (is this URL internal? is this
reference a symbol? is it active?) that happens to be re-evaluated by Vue's reactivity system if props
change, but nothing in normal DocC-Render usage changes these props after mount. Since there is no
interactive or stateful behavior in this kind to replace, none of the listed native mechanisms
(<details>/<summary>, radio-input :checked + sibling
selectors, :target, the Popover API, <dialog>, :has(),
container queries, CSS anchor positioning, view-transitions) apply—a plain <a href>
(or <span> when inactive) already is the idiomatic, framework-free representation of
what this node produces; there is no client-side state for a CSS mechanism to hold in its place.