1. How swift-docc-render consumes this
Grepping src/components/ for the literal string 'subscript' lands, as with
every other block/inline content kind on this reference site, on
src/components/ContentNode.vue's wire-constant table. subscript is one of the
entries in the InlineType map
(ContentNode.vue#L56-L69):
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',
};
That constant is matched in the renderNode() factory function's switch (node.type)
dispatch table. subscript gets its own case, immediately after the sibling
superscript case:
case InlineType.superscript:
return createElement('sup', renderChildren(node.inlineContent));
case InlineType.subscript:
return createElement('sub', renderChildren(node.inlineContent));
case InlineType.strikethrough:
return createElement(StrikeThrough, renderChildren(node.inlineContent));
(ContentNode.vue#L499-L504.)
Unlike strikethrough a line below it — which is delegated to a dedicated child
component, StrikeThrough.vue — subscript (like superscript
immediately above it) is turned directly into a bare native <sub> element via Vue's
createElement, with no wrapper component and no class/attrs
argument at all. The node's only payload field, inlineContent (an array of nested
RenderInlineContent nodes), is recursively rendered through the same module-local
renderChildren helper
(ContentNode.vue#L122-L124)
used by every other inline/block wrapper kind, so arbitrary nesting (for example a reference
link inside a subscript) is rendered correctly by recursion rather than any special-casing.
The type discriminator itself is consumed only by the switch and never
forwarded into the DOM.
ContentNode.vue also has a tree-walking utility API (map, forEach,
reduce) used elsewhere in the app to traverse a content tree without rendering it (for
example, to build the plain-text abstract for search indexing or social-preview metadata). Both
map and forEach explicitly list InlineType.subscript alongside
superscript, strikethrough, emphasis, strong,
inlineHead, and newTerm as "wrapper" kinds whose inlineContent
array must be recursed into
(ContentNode.vue#L564-L575,
ContentNode.vue#L619-L628).
No other .vue file under src/components/ or src/views/ matches the
literal string 'subscript'; the DocumentationTopic/ContentNode.vue and
Article/ContentNode.vue files that also exist in the tree handle unrelated section-level
concerns (list indentation, spacing) and do not reference this inline kind.
2. Example JSON and rendered mockup
Real fixture, from swift-docc's test suite:
Tests/SwiftDocCTests/Rendering/Rendering Fixtures/subscript-superscript-elements.json,
pinned at swift-docc@8b8d8268aa. This is a full (trimmed) RenderNode whose
primaryContentSections contains a paragraph with a subscript node
next to its sibling superscript:
{
"type": "paragraph",
"inlineContent": [
{
"type": "text",
"text": "Use "
},
{
"type": "subscript",
"inlineContent": [
{
"type": "text",
"text": "sub"
}
]
},
{
"type": "text",
"text": " and "
},
{
"type": "superscript",
"inlineContent": [
{
"type": "text",
"text": "sup"
}
]
},
{
"type": "text",
"text": " to render attributed text."
}
]
}
Use sub and sup to render attributed text.
3. Data sheet
Field table for the Subscript schema object
(Sources/DocCArchive/Vendored/RenderNode.spec.json, one of the members of the
RenderInlineContent oneOf discriminator), cross-checked against the generated
Components.Schemas.Subscript struct in Sources/DocCArchive/generated/Types.swift:
| Field | Type | Required? | Enum values / default | Note |
|---|---|---|---|---|
type | string | yes | "subscript" | Discriminator. Generated as Subscript._TypePayload, a String-backed enum with a single case. Because subscript is a reserved keyword in Swift, swift-openapi-generator emits it as case _subscript = "subscript" rather than a bare case subscript — the wire string is unaffected, only the generated Swift identifier is escaped with a leading underscore. |
inlineContent | array of RenderInlineContent | yes | — | The nested inline-content children to be rendered subscripted; generated as [Components.Schemas.RenderInlineContent]. Can itself contain further text, codeVoice, reference, etc. nodes. |
Note the asymmetry with swift-docc's authoring-side Swift model: the in-memory
RenderInlineContent Swift enum case at
RenderInlineContent.swift#L52
is case `subscript`(inlineContent: [RenderInlineContent]) (backticked because
subscript is also a Swift keyword at the call site, mirroring the generated type's
_subscript escape for the same underlying reason). It always encodes with
type: "subscript" via the private InlineType Codable helper enum at
RenderInlineContent.swift#L59-L61.
There is exactly one wire spelling, unlike emphasis (which also accepts the legacy alias
"italic").
One honest gap worth flagging: the vendored RenderNode.spec.json's
RenderInlineContent oneOf list (line 1190) enumerates Text,
Emphasis, Strong, CodeVoice, Reference,
Image, InlineHead, NewTerm, Superscript,
Link, and Subscript — eleven members — but is missing
Strikethrough, even though swift-docc's own RenderInlineContent Swift enum has a
strikethrough case and swift-docc-render's ContentNode.vue actively handles the
wire value "strikethrough" (see section 1). This is a drift in the vendored JSON Schema
relative to both ends of the pipeline, not a subscript-specific issue, but it is visible from this same
schema object so it is noted here for anyone cross-referencing the discriminator list.
What an author writes to produce this: unlike emphasis, strong, and
strikethrough, there is no Markdown syntax in swift-docc's own compiler that
produces a subscript node today. RenderContentCompiler.swift
(RenderContentCompiler.swift)
has visitor methods for visitEmphasis, visitStrong, and
visitStrikethrough that walk cmark's parsed Markdown tree, but no
visitSubscript (or visitSuperscript) exists anywhere in that file or elsewhere
in Sources/SwiftDocC/. The .subscript(inlineContent:) case has full
Codable, Equatable, and plain-text-indexing support
(RenderInlineContent.swift#L127-L128),
so the render-tree model and swift-docc-render's presentation layer are both fully wired up for it —
but as of this pinned commit, swift-docc's own Markdown-to-render-tree compiler has no code path that
authors can trigger from a doc comment or .md/.tutorial article to emit it. The
fixture used in section 2 above (subscript-superscript-elements.json) is a hand-built
render-tree fixture used to test the render/decode round trip and the render-render (Vue) presentation, not
a JSON file produced by running swift-docc's Markdown compiler over an authored article.
4. HTML/CSS mapping in DocC-Render output
The rendered output is a bare <sub>...</sub> element with no id,
class, or data-* attribute of its own — the
createElement('sub', renderChildren(node.inlineContent)) call at
ContentNode.vue#L501-L502
passes no class/attrs object at all, unlike sibling cases such as
InlineType.codeVoice (which adds class: 'inline-code') or
InlineType.reference (which adds class: 'inline-link') a few lines away in the
same switch. Grepping src/style/ (and the whole src/ tree) for a
bare sub/sup element selector or a class targeting this kind turns up nothing;
there is no dedicated SCSS partial for either subscript or superscript, in
contrast to strikethrough's dedicated StrikeThrough.vue component (which does
carry its own scoped style block). The subscripted appearance — lowered baseline and reduced font
size — is therefore produced entirely by the browser's built-in user-agent styling for the
<sub> element (vertical-align: sub; font-size: smaller in most engines),
not by any DocC-render-authored CSS rule or custom property.
5. Modern CSS-only alternative
Not applicable
Current behavior, precisely: subscript nodes are rendered as a plain, static
<sub> element via a one-line createElement('sub', renderChildren(...))
call, with no Vue data, no props, no event handlers, and no client-side state of any kind
attached to the element or its rendering path. There is nothing dynamic to reproduce: the "behavior" in
play is simply the HTML semantics of <sub> combined with the browser's default
subscript presentation, which is already the plain, non-JavaScript, non-interactive mechanism in use
today. There is no toggleable, hidden, or otherwise stateful aspect of this kind for a native CSS
mechanism (<details>, :target, the Popover API, :has(),
etc.) to replace.