inline

superscript

Wire value: "superscript"

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

1. How swift-docc-render consumes this

Grepping src/components/ for the literal string 'superscript' lands on src/components/ContentNode.vue's inline wire-constant table, InlineType (ContentNode.vue#L56-L69), whose superscript key holds InlineType.superscript = 'superscript':

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 inside the renderNode() factory function's switch (node.type) dispatch table, immediately alongside the subscript case it mirrors:

case InlineType.superscript:
  return createElement('sup', renderChildren(node.inlineContent));
case InlineType.subscript:
  return createElement('sub', renderChildren(node.inlineContent));

(ContentNode.vue#L499-L502.) Unlike kinds such as heading, aside, or strikethrough, superscript is not delegated to a dedicated child Vue component (there is no Superscript.vue under src/components/ContentNode/). It is turned directly into a bare native <sup> element via Vue's createElement render function, with the node's inlineContent array recursively mapped back through the same renderNode() closure (renderChildren) to produce the element's children. No extra props, classes, or attributes are attached — the type discriminator is consumed only by the switch and never forwarded to the DOM.

The same InlineType.superscript constant also appears in two of ContentNode's tree-walking helper methods exposed to other components: the recursive map() method, which descends into node.inlineContent when rebuilding a superscript node (ContentNode.vue#L564-L575), and the depth-first forEach() walker, which likewise recurses into a superscript node's children when visiting every node in a content tree (ContentNode.vue#L619-L628). Both treat superscript exactly like subscript, emphasis, strong, and newTerm — inline wrapper kinds whose only payload is a nested inlineContent array to recurse into, as opposed to leaf kinds like text or kinds with other payload shapes like reference.

2. Example JSON and rendered mockup

Real fixture: swift-docc's own test suite ships a fixture built specifically to exercise this kind, Tests/SwiftDocCTests/Rendering/Rendering Fixtures/subscript-superscript-elements.json, decoded by SubscriptSuperscriptElementsTests.swift in the same directory. DocCArchive's own test fixtures (ExampleDocs.doccarchive, SampleLibrary.doccarchive) contain no superscript nodes in their RenderNode data files — the only hits there are inside the bundled, minified DocC-render JavaScript assets, not authored content — so this excerpt (the primaryContentSections[0].content[1] paragraph) is used instead:

{
  "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.

mockup: the superscript node's inlineContent (here a single text leaf, "sup") is rendered inside a bare <sup> element, exactly as the sibling subscript node becomes a bare <sub> element. Both inherit the surrounding paragraph's font and color; only <sup> gets the site's reduced-size, raised-baseline typography rule (see Section 4).

3. Data sheet

Source: Sources/DocCArchive/Vendored/RenderNode.spec.json, schema object #/components/schemas/Superscript (lines 1390–1409), cross-checked against Components.Schemas.Superscript in Sources/DocCArchive/generated/Types.swift (lines 1900–1925). Superscript is one arm of the RenderInlineContent discriminated union (the oneOf list starting at spec line 1190, with the $ref to Superscript at line 1217), the same union that backs every inline-content array on the wire (paragraph text runs, list-item text, table-cell text, term-list terms/definitions, and so on).

FieldTypeRequiredEnum values / defaultNote
type string yes "superscript" (single-value enum) Generated as _TypePayload: String, Codable, Hashable, Sendable, CaseIterable { case superscript = "superscript" }, decoded/encoded under the Swift property name _type via an explicit CodingKeys mapping (case _type = "type") — the leading underscore avoids colliding with Swift's own type keyword-adjacent naming conventions in generated code.
inlineContent array of RenderInlineContent yes — (no minItems/maxItems constraint) Generated as [Components.Schemas.RenderInlineContent]. This is the recursive payload: a superscript node wraps zero or more further inline-content nodes (typically plain text, but schema-legally any other RenderInlineContent arm, including nested formatting), matching the "wrapper kind with a child inline-content array" shape shared with emphasis, strong, subscript, strikethrough, newTerm, and inlineHead.

On the swift-docc production side (secondary/flavor source, not authoritative for wire shape), the enclosing enum case is

/// A superscript piece of content.
case superscript(inlineContent: [RenderInlineContent])

(Sources/SwiftDocC/Model/Rendering/Content/RenderInlineContent.swift, lines 53–54), part of the RenderInlineContent enum whose Codable conformance encodes/decodes the discriminator through a private InlineType enum and dispatches on .superscript at lines 129–130 (decode) and 162–163 (encode). Unlike block-tier kinds such as Heading, there is no separately-declared payload struct for superscript in Sources/SwiftDocC/Model/Rendering/Content/ — the associated value is an inline tuple-style enum payload (inlineContent: [RenderInlineContent]) directly on the case, not a nested type, so no distinct swiftStructSite exists to cite beyond the case declaration itself. A companion extension, RenderInlineContent+TextIndexing.swift (lines 50–51), defines rawIndexableTextContent for .superscript by simply recursing into the wrapped inlineContent — superscripted text is indexed as plain text, with no marker distinguishing it from its surrounding prose.

Authoring-side, swift-docc's own RenderInlineContent catalog article (Sources/SwiftDocC/SwiftDocC.docc/SwiftDocC/RenderingModel/RenderInlineContent.md) lists superscript(inlineContent:) as a topic alongside subscript(inlineContent:) but adds no prose beyond the doc comment already quoted above. Markdown has no native superscript syntax (unlike, say, GFM strikethrough's ~~text~~, which swift-docc does translate into the strikethrough kind), and a search of swift-docc's Markup/Semantics conversion code (Sources/SwiftDocC/Model/RenderNodeTranslator.swift and the Markup/Semantics directories) turns up no reference to superscript at all outside the model and indexing files already cited — so, honestly, this pinned commit's Markdown-to-RenderNode translation path does not appear to have an active producer for this case in the sources searched. The most plausible authoring mechanism, given cmark-gfm's raw inline-HTML passthrough (used elsewhere for e.g. inline <br>), would be writing literal <sup>text</sup> in a doc comment, but this could not be confirmed by reading a matching translator branch, so it is reported here as informed speculation rather than a verified fact.

DocCArchive's own transform layer does not yet do anything with this kind: MyHTMLTransformer and MyMarkdownTransformer (Sources/DocCArchive/DocCArchive.swift) are still stub placeholders that return a hardcoded HTML comment and an empty string respectively for an entire RenderNode, with no per-inline-kind switch reached yet — so a superscript node parsed via Components.Schemas.Superscript is available on the decoded model today (nested inside any RenderInlineContent array DocCArchive parses), but nothing in this repository currently converts it into HTML or Markdown output.

4. HTML/CSS mapping in DocC-Render output

Rendered DOM for a superscript node, in context: a bare <sup> element wrapping whatever elements/text its inlineContent children render to. No wrapper <div>, no class, no id, no data attribute — this is the plainest possible mapping among the inline kinds on this reference site.

SCSS: the only rule targeting the element is a site-wide, un-namespaced sup selector in src/styles/base/_typography.scss (_typography.scss#L170-L191), which applies to every <sup> in the document regardless of whether it came from a superscript RenderInlineContent node or static template markup elsewhere in the app:

sup {
  font-size: .6em;
  vertical-align: top;
  position: relative;
  bottom: -.2em;

  h1 &,
  h2 &,
  h3 & {
    font-size: .4em;
  }

  a {
    vertical-align: inherit;
    color: inherit;

    &:hover {
      color: var(--figure-blue);
      text-decoration: none;
    }
  }
}

The sibling rule for sub, two lines below, is far simpler (_typography.scss#L193-L195): just sub { line-height: 1; }, relying on the browser's UA-stylesheet default of vertical-align: sub rather than overriding position/offset the way the sup rule does. Nesting rules inside the sup block further shrink the font-size to .4em when the superscript appears inside an h1/h2/h3, so a superscripted footnote marker in a heading doesn't dominate the heading's visual weight; a nested rule for a descendants normalizes any link placed inside a superscript to inherit the surrounding color and vertical alignment rather than looking like a differently-sized, differently-colored inline link.

CSS custom properties consumed: only --figure-blue, and only in the edge case of a link nested inside a superscript being hovered. No custom properties are consumed by the base sup rule itself — its sizing/offset values (.6em, .4em, -.2em) are hardcoded Sass-file literals, not theme-able runtime variables.

5. Modern CSS-only alternative

Not applicable

Current behavior in play: there is none to replace. ContentNode.vue's renderNode() dispatch for InlineType.superscript is a single, stateless, one-line mapping — createElement('sup', renderChildren(node.inlineContent)) — with no component-local data(), no computed property, no event listener, and no conditional branching beyond the switch case selection itself. The one CSS rule involved (sup { font-size: .6em; vertical-align: top; position: relative; bottom: -.2em; ... }) is already plain, static CSS with no JavaScript reading or writing any of those properties at runtime; it is not a JS-driven visual state being held in Vue data that a native HTML/CSS mechanism like <details>, :target, or the Popover API could take over, because there is no interactive state — hover/focus/open/closed — being tracked at all for a superscript node itself (the only :hover rule in scope belongs to a nested <a> descendant, and that is already native CSS :hover, not JS). This kind is purely a static typographic transform of its children, so the "modern CSS alternative" question has no target to aim at.