block

heading

Wire value: "heading"

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

1. How swift-docc-render consumes this

Grepping src/components/ for the literal string 'heading' lands, as with every other block/inline content kind on this reference site, on src/components/ContentNode.vue's wire-constant table (ContentNode.vue#L37-L54), whose heading key holds BlockType.heading = 'heading'. That constant is matched in the renderNode() factory function's switch (node.type) dispatch table:

case BlockType.heading: {
  const props = {
    anchor: node.anchor,
    level: node.level,
  };
  return createElement(LinkableHeading, { props }, node.text);
}

(ContentNode.vue#L290-L295.) Unlike paragraph, a heading node is not turned into a bare native element inline — it delegates to a dedicated child component, src/components/ContentNode/LinkableHeading.vue, imported at the top of ContentNode.vue (ContentNode.vue#L15). Only two of the node's four wire fields are forwarded as props — anchor and level — while text is passed as the component's default slot content (a plain string, not run through renderChildren(), since Heading.text is a bare string on the wire, not an array of inline-content nodes). The type discriminator itself is consumed only by the switch, never forwarded.

LinkableHeading.vue's template resolves the actual tag dynamically from the level prop:

<component :id="anchor" :is="`h${level}`">
  <router-link v-if="shouldLink" :to="linkWithAnchor" ... class="header-anchor"
    @click="handleFocusAndScroll(anchor)">
    <slot />
    <LinkIcon class="icon" aria-hidden="true" />
  </router-link>
  <template v-else><slot /></template>
</component>

(LinkableHeading.vue#L11-L30.) The level prop defaults to 2 and is validated to the range 1–6 (LinkableHeading.vue#L42-L51), matching the native h1–h6 range it maps onto via Vue's dynamic :is binding. Whether the heading text is wrapped in a <router-link> (producing the clickable "paragraph-style" anchor link with a chained LinkIcon) is a computed property, shouldLink: true only when an anchor string is present and the app is not running in "minimized" mode (enableMinimized, an injected flag used for embedded/quick-help presentations) and not targeting an IDE host (isTargetIDE) (LinkableHeading.vue#L61-L67). Clicking the anchor link calls handleFocusAndScroll from the shared scrollToElement mixin (src/mixins/scrollToElement.js), which focuses the heading element and then smooth-scrolls the viewport to it, compensating for the fixed navigation bar's height.

LinkableHeading is not a heading-block-only helper — the same component is reused directly (bypassing ContentNode.vue's dispatch table) by several other section-level components that need a linkable section title, including ContentTableSection.vue, TopicsTable.vue, ContentTable.vue, and the REST/symbol primary-content partials (PropertyTable.vue, Attributes.vue, Mentions.vue, Parameters.vue, and others). Those call sites are not RenderBlockContent.heading nodes — they are page-chrome section titles the Vue app builds itself — but they confirm LinkableHeading is the single canonical "anchored heading" primitive across DocC-render, of which the heading block kind documented on this page is one producer.

2. Example JSON and rendered mockup

Real fixture: Tests/DocCArchiveTests/Fixtures/ExampleDocs.doccarchive/data/documentation/exampledocs/examplearticle.json, field primaryContentSections[0].content[0] — the first of two heading nodes in that article's rendered content array. This is the RenderNode swift-docc produced for an authored Markdown ## Overview heading.

{
  "type": "heading",
  "text": "Overview",
  "level": 2,
  "anchor": "Overview"
}
Overview

mockup: level: 2 becomes an <h2 id="Overview"> element (via LinkableHeading's dynamic :is="`h${level}`" binding); the presence of anchor wraps the text in an in-page <router-link> whose href resolves to #Overview, with a link-icon glyph revealed on hover/focus (see Section 4). If anchor were omitted, the same <h2> would render as plain unlinked text.

3. Data sheet

Source: Sources/DocCArchive/Vendored/RenderNode.spec.json, schema object #/components/schemas/Heading (lines 760–782), cross-checked against Components.Schemas.Heading in Sources/DocCArchive/generated/Types.swift (lines 4177–4214). Heading is one arm of the RenderBlockContent discriminated union (referenced at spec line 453) that makes up the content array of a ContentRenderSection and of any other block-content-bearing container.

FieldTypeRequiredEnum values / defaultNote
type string yes "heading" (single-value enum) Generated as _TypePayload: String, Codable, Hashable, Sendable, CaseIterable { case heading = "heading" }, decoded/encoded under the Swift property name _type via an explicit CodingKeys mapping (case _type = "type").
level integer yes — (no schema-level range constraint) Generated as plain Swift.Int, unconstrained. The JSON schema places no min/max on it, though the consuming Vue component (LinkableHeading's prop validator) clamps rendering to 1–6 to match native h1–h6. swift-docc's Swift-side Heading.level: Int doc comment (see below) says level 1 is "the most prominence" and level 6 "the least," mirroring HTML semantics, but the wire schema itself does not enforce that range.
text string yes — Plain string, not an inline-content array — a heading's title is flattened to text by swift-docc before being placed on the wire; it cannot contain nested formatting/links at this level.
anchor string no — (absent when not linkable) Generated as Swift.String?. When present, DocC-render treats the heading as linkable (see Section 1); when absent, the heading renders as static text with no anchor id and no link wrapper.

On the swift-docc production side (secondary/flavor source, not authoritative for wire shape), the enclosing enum case is case heading(Heading) (Sources/SwiftDocC/Model/Rendering/Content/RenderBlockContent.swift, line 47), and the nested struct is declared at the same file, lines 439–456:

public struct Heading: Equatable {
    public var level: Int
    public var text: String
    public var anchor: String?
    public init(level: Int, text: String, anchor: String?) { ... }
}

This matches the wire schema field-for-field (level, text, anchor); the only asymmetry is that the Swift model's init requires an explicit anchor argument (nilable, but not defaulted), whereas the generated wire type defaults it to nil when omitted from JSON. Authoring-side, a heading node is what swift-docc emits for any Markdown ATX heading (## Overview, ### Section header, etc.) inside an article's or extension's body content; the heading level in the rendered node corresponds to the number of # characters written, and the anchor is a slug swift-docc derives from the heading text for in-page linking (subject to the heading-level-sequencing diagnostics swift-docc emits when authors skip levels, e.g. jumping from a level-2 to a level-4 heading).

DocCArchive's own transform layer does not yet do anything with this kind: MyHTMLTransformer and MyMarkdownTransformer (Sources/DocCArchive/DocCArchive.swift, lines 242–254) are still stub placeholders that return a hardcoded HTML comment and an empty string respectively for an entire RenderNode, with no per-block-kind switch reached yet — so a heading node parsed via Components.Schemas.Heading is available on the decoded model today, 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 heading node, in context:

SCSS: LinkableHeading.vue carries its own scoped <style> block (LinkableHeading.vue#L72-L104), scoped to the .header-anchor class:

Beyond the component's own scoped rules, a rendered heading also inherits the site-wide heading rules in src/styles/base/_typography.scss (lines 72–91), which apply to every h1– h6 regardless of whether they came from a heading RenderBlockContent node or from static template markup:

h1, h2, h3, h4, h5, h6 {
  color: var(--colors-header-text, var(--color-header-text));
  + * { margin-top: var(--spacing-stacked-margin-large); }
  p + &, ul + &, ol + & { margin-top: 1.6em; }
}

CSS custom properties consumed: --colors-header-text (falling back to --color-header-text) for text color, and the generic stacking-spacing variables --spacing-stacked-margin-large; the icon geometry instead comes from the Sass constants $icon-size-default (16px, src/styles/core/_vars.scss line 40) and a local $icon-margin: 7px compiled directly into the scoped stylesheet, not exposed as runtime custom properties.

See also: Localization fallback — how $t()/locale-key lookup works across every kind that uses it.

5. Modern CSS-only alternative

Partial

Current behavior in play: LinkableHeading.vue has exactly one piece of interactive, non-navigational UI state — the link icon's hover/focus reveal — and it is already implemented with plain CSS :hover/:focus selectors toggling display (.header-anchor:hover .icon, .header-anchor:focus .icon { display: inline; }), so there is nothing to port there; it is already a "modern CSS" mechanism in the sense that no JavaScript drives it. The one piece of behavior that is JavaScript-driven is the click handler, @click="handleFocusAndScroll(anchor)", which calls element.focus({ preventScroll: true }) followed by an async, offset-compensated scrollIntoView() that accounts for the app's fixed navigation bar height (src/mixins/scrollToElement.js).

That scroll/focus behavior overlaps substantially with what the native :target pseudo-class plus the browser's built-in fragment-navigation already provides for free: a plain <a href="#Overview"> pointing at an element with id="Overview" would, on click, let the browser jump to and (as of Scroll-to-Text/anchor-navigation focus semantics) make that element the document's active scroll target with no JS at all, and #Overview:target { ... } could apply a highlight style keyed on the URL fragment matching the element's id — this is the "one specific native mechanism" that could absorb part of the current behavior. It would not, however, replicate the fixed-nav-bar scroll offset compensation or the deliberate element.focus() call for keyboard-accessibility purposes that handleFocusAndScroll performs; CSS has no mechanism to call Element.focus(), and scroll-margin-top (a CSS property that could statically reserve space for a fixed header during native anchor scrolling) is not currently set anywhere in this component or its stylesheet, so the offset math would need to move into a CSS custom property consumed by scroll-margin-top rather than disappearing outright. The verdict is "partial": the hover-reveal is already CSS-only, and fragment navigation via :target/native anchor scrolling could replace the bulk of the click-triggered scroll, but the explicit focus-management call is behavior a CSS-only page cannot reproduce.