1. How swift-docc-render consumes this
Like file, link is not a block/inline content
kind that ContentNode.vue's render() switch dispatches on directly—it is a
reference-tier object, an entry in the RenderNode's top-level references dictionary.
Grepping src/components/ for the literal string 'link' only turns up an unrelated
match: ContentNode.vue's InlineType constant table includes a key/value pair
link: 'link'
(ContentNode.vue#L56-L69)
that is a different, explicitly deprecated inline node type ({"type": "link", "destination":
"...", "title": "..."}, handled at
ContentNode.vue#L459-L466
with the comment "Note: InlineType.link has been deprecated, but may still be found in old
JSON"). That is not the LinkRenderReference object this page documents.
The reference-tier link object is reached indirectly, through the generic
InlineType.reference dispatch arm—the same one documented in full on the
reference inline-kind page:
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.)
An inline reference node's identifier is looked up in the references
map; when the resolved object's type happens to be "link" (a
LinkRenderReference, produced for external URLs—see the data sheet below), its
url and title/titleInlineContent feed the same
Reference.vue
component used for internal doc: links. Because LinkRenderReference carries no
kind or role field (those only exist on TopicRenderReference),
Reference.vue's props for a link reference are kind: undefined,
role: undefined:
isSymbolReference() {
return this.kind === 'symbol' && !this.hasInlineFormatting
&& (this.role === TopicRole.symbol || this.role === TopicRole.dictionarySymbol);
},
refComponent({ isInternal, isDisplaySymbol }) {
if (isInternal) {
return isDisplaySymbol ? ReferenceInternalSymbol : ReferenceInternal;
}
return isDisplaySymbol ? ReferenceExternalSymbol : ReferenceExternal;
},
(Reference.vue#L67-L79.)
So isSymbolReference/isDisplaySymbol are always false for a
link reference, and isInternal is computed purely from the URL string
(Reference.vue#L52-L65):
true only if the URL starts with / or # and the Vue Router resolves it to
something other than the "not found" route. In practice a LinkRenderReference's
url is an external absolute URL (it is only ever created for links that are not
doc:-scheme, per swift-docc's compiler—see section 3), so refComponent
resolves to
ReferenceExternal.vue,
whose entire template is:
<template>
<a v-if="url && isActive" :href="url"><slot /></a>
<span v-else><slot /></span>
</template>
(ReferenceExternal.vue#L11-L14,
full file.) So the practical, common-case result of resolving a link reference is a plain
<a href="…" class="inline-link">…</a>—no router integration, no symbol
code-voice wrapping, no special icon; it falls back to a bare <span> only if
url is empty or the enclosing inline node's isActive is false.
See also: The references map — how this and every other reference-dictionary lookup works across kinds.
2. Example JSON and rendered mockup
No literal JSON fixture containing "type": "link" as a reference-tier object was found in
either Tests/DocCArchiveTests/Fixtures/ in this repository (neither
ExampleDocs.doccarchive nor SampleLibrary.doccarchive ships pre-rendered
RenderNode JSON—only the compiled site's JS/HTML assets) or in swift-docc's own
Tests/SwiftDocCTests/ suite (no test file constructs a LinkReference by name,
and no test JSON fixture contains a "type": "link" reference entry). The example below is
hand-written from the schema and from swift-docc's compiler logic in
RenderContentCompiler.visitLink(_:)
(Sources/SwiftDocC/Model/Rendering/RenderContentCompiler.swift:145-172), which is what
actually constructs a LinkReference: given an authored Markdown link whose destination is
not a doc:-scheme URL, it builds a RenderReferenceIdentifier(forExternalLink:
the destination string) and a matching LinkReference keyed by that same string.
{
"type": "paragraph",
"inlineContent": [
{ "type": "text", "text": "See the " },
{
"type": "reference",
"identifier": "https://www.swift.org/documentation/",
"isActive": true
},
{ "type": "text", "text": " for more." }
]
}
Matching entry in the RenderNode's top-level references map, keyed by the same identifier:
"references": {
"https://www.swift.org/documentation/": {
"type": "link",
"identifier": "https://www.swift.org/documentation/",
"title": "Swift Documentation",
"titleInlineContent": [
{ "type": "text", "text": "Swift Documentation" }
],
"url": "https://www.swift.org/documentation/"
}
}
See the Swift Documentation for more.
3. Data sheet
| field | type | required? | enum values / default | note |
|---|---|---|---|---|
type | string | yes | ["link"] | Discriminator; always the literal string "link". Member of the shared RenderReferenceType Swift enum alongside image, video, file, fileType, xcodeRequirement, topic, section, download, link, externalLocation, unresolvable (RenderReference.swift:29). |
identifier | string | yes | — | Key into the RenderNode's top-level references map. For a LinkRenderReference, swift-docc always sets this to the literal external URL string itself (RenderReferenceIdentifier(forExternalLink: destination), RenderContentCompiler.swift:155), so it doubles as the value of url. |
title | string, nullable | no (not in the JSON schema's required array, though swift-docc's own encoder always writes it) | no schema-level default | Plain-text display title. swift-docc's decoder falls back to deriving this from titleInlineContent's plain text, or finally to the raw URL string, if absent (LinkReference.swift:56-65). |
titleInlineContent | array of RenderInlineContent | no (schema does not list it as required; swift-docc's own encoder always writes it) | no schema-level default | Formatted display title. swift-docc's initializer defaults this to [.text(title)] when not supplied programmatically (LinkReference.swift:41). |
url | string | yes | — | The link destination—an absolute external URL in every case swift-docc's compiler produces (a doc:-scheme destination never reaches this path; see below). Not restricted to external URLs by the JSON schema itself, which just types it as a plain string. |
Source: Sources/DocCArchive/Vendored/RenderNode.spec.json, the LinkRenderReference
schema object (lines 1522-1547), one of the nine members of the RenderReference
oneOf discriminated union (lines 1491-1519). Cross-checked against the generated Swift type in
Sources/DocCArchive/generated/Types.swift:
public struct LinkRenderReference: Codable, Hashable, Sendable {
@frozen public enum _TypePayload: String, Codable, Hashable, Sendable, CaseIterable {
case link = "link"
}
public var _type: Components.Schemas.LinkRenderReference._TypePayload
public var identifier: Swift.String
public var title: Swift.String?
public var titleInlineContent: [Components.Schemas.RenderInlineContent]?
public var url: Swift.String
}
(Types.swift:2220-2233.) This struct is one case (.LinkRenderReference) of the
generated Components.Schemas.RenderReference indirect enum in the same file
(Types.swift:2133). The vendored JSON schema's required array
(type, identifier, url) matches the generated struct's
non-optional stored properties exactly.
On the authoring side, swift-docc's Swift model (LinkReference.swift:12, doc comment "A
reference to a URL") is produced by RenderContentCompiler.visitLink(_:)
(Sources/SwiftDocC/Model/Rendering/RenderContentCompiler.swift:145-172) whenever an author
writes a plain Markdown link—[Swift Documentation](https://www.swift.org/documentation/)—whose
destination does not use the doc: URL scheme. (Links that do use the
doc: scheme, e.g. <doc:MyArticle> or a symbol link, resolve instead to a
TopicRenderReference and are out of scope for this page; see swift-docc's
LinkResolution.md catalog article,
Sources/SwiftDocC/SwiftDocC.docc/SwiftDocC/LinkResolution.md, for that authoring path.) The
compiler deduplicates repeat links to the same destination on one page, reusing the same
LinkReference entry and instead emitting an overridingTitle on the inline
reference node when the same URL is linked with different visible text
(RenderContentCompiler.swift:157-163).
Within this repository, DocCArchive's own transform layer does not yet do anything specific 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 or an empty string, respectively—neither
one walks the references map or RenderInlineContent case-by-case yet, so
link reference objects are not yet resolved or rendered by this library.
4. HTML/CSS mapping in DocC-Render output
Because a link reference's url is always external and it never carries a
kind/role, the four-way branching in
Reference.vue collapses to two practical shapes for this
specific reference type:
- Active (
isActivetrue and non-emptyurl):<a class="inline-link" href="…">…</a>, fromReferenceExternal.vue. - Inactive or empty
url:<span class="inline-link">…</span>, same component'sv-elsebranch.
The ReferenceInternalSymbol/ReferenceExternalSymbol (code-voice-wrapped) branches
that the reference inline-kind page documents for symbol links are unreachable for a
link-type reference, since isDisplaySymbol can never be true without a
kind === 'symbol' value that this reference type doesn't carry.
The inline-link class is applied at the dispatch site in ContentNode.vue
(ContentNode.vue#L483),
not inside Reference.vue or ReferenceExternal.vue themselves. 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 a resolved link reference is always rendered underlined (an explicit WCAG 2.2 choice per
the inline comment, since color alone is not a sufficient link affordance), regardless of hover state. Its
color comes from the CSS custom property --color-link, defined in
src/styles/core/colors/_light.scss:101 as --color-link: var(--color-figure-blue),
with a dark-mode override in the counterpart partial. No SCSS partial targets
ReferenceExternal.vue by component name; all of its visual styling flows through this one
generic a/.inline-link rule.
5. Modern CSS-only alternative
Not applicable
Current behavior, precisely: for a link-type reference specifically, Reference.vue
holds no reactive component state (no data(), no click handler, no toggled visibility); its
only "logic" is the one-shot isInternal computed property, which for this reference type is
always false (the URL is an external absolute URL, never a leading / or
#), and isDisplaySymbol, always false (no kind field on
this reference type). Those two static, prop-derived booleans pick ReferenceExternal.vue, whose
template condition v-if="url && isActive" is likewise evaluated once from props at
render time, with no runtime interaction afterward.
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 hover-driven layout change beyond the
browser's native :hover underline (which is already plain CSS, not JS). The entire "behavior"
is one-time branching over static data (is isActive true? is url non-empty?) that
produces either a plain <a href> or a plain <span>. 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) applies—a plain external
<a href> already is the idiomatic, framework-free representation of what a
link reference produces; there is no client-side state for a CSS mechanism to hold in its
place.