1. How swift-docc-render consumes this
Grepping src/components/ for the literal string 'table' lands on
src/components/ContentNode.vue's wire-constant table
(ContentNode.vue#L37-L54),
whose table key holds BlockType.table = 'table'. That constant is matched in the
renderNode() factory function's switch (node.type) dispatch table:
case BlockType.table: {
const children = renderTableChildren(
node.rows, node.header, node.extendedData, node.alignments,
);
if (node.metadata && node.metadata.abstract) {
const { title } = node.metadata;
const position = title ? CaptionPosition.leading : CaptionPosition.trailing;
const tag = CaptionTag.caption;
children.unshift(createElement(Caption, {
props: { title, position, tag },
}, (
renderChildren(node.metadata.abstract)
)));
}
return createElement(Table, {
attrs: { id: node.metadata && node.metadata.anchor },
props: { spanned: !!node.extendedData },
}, (
children
));
}
(ContentNode.vue#L314-L344.)
Unlike most other block kinds, table's actual cell layout is not produced inline in this switch arm — it is
built by a dedicated helper, renderTableChildren(), defined earlier in the same file
(ContentNode.vue#L146-L218),
which switches on node.header (one of the four TableHeaderStyle values
both/column/row/none, defined at
ContentNode.vue#L100-L105)
to decide, per cell, whether to emit a native <th> or <td>, and whether
to wrap the first row/rows in a <thead>. A second helper,
renderTableCell()
(ContentNode.vue#L132-L144),
looks up any extendedData entry keyed by "{rowIndex}_{cellIndex}", forwards
colspan/rowspan as real HTML attributes, returns null for the cell
entirely if either value is 0 (meaning this cell is "spanned over" by a previous cell and must
not be rendered at all), and adds a left-cell/right-cell/center-cell
class from the per-column alignments array (constants at
ContentNode.vue#L107-L112).
If node.metadata.abstract is present, a <caption> element (via the shared
Caption child component,
src/components/ContentNode/Caption.vue,
imported at
ContentNode.vue#L20)
is unshifted onto the children array so it becomes the table's first child (HTML requires
<caption> to be the table's first child element). Finally the whole thing is wrapped by the
Table child component
(src/components/ContentNode/Table.vue,
imported at
ContentNode.vue#L23),
which receives node.metadata.anchor as a plain id attribute and a boolean
spanned prop that is simply !!node.extendedData — true whenever any cell in the
table carries colspan/rowspan data.
Table.vue's own template is a thin wrapper:
<div class="table-wrapper">
<table :class="{ spanned }">
<slot />
</table>
</div>
(Table.vue#L11-L17.)
There is no client-side interactive state anywhere in this path: every table is rendered once, server/build
time semantics aside, straight from the wire JSON into a static <table> element tree.
2. Example JSON and rendered mockup
Real fixture: Tests/SwiftDocCTests/Rendering/Rendering Fixtures/tables.json in the swift-docc
repository, a primaryContentSections content array containing one table node with
header: "row", a metadata block (title/abstract/anchor), and a single row with two
cells. Reproduced (trimmed to the table node itself) below:
{
"type": "table",
"metadata": {
"title": "Figure 1",
"abstract": [
{ "type": "text", "text": "Tabulur data" }
],
"anchor": "anchor"
},
"header": "row",
"rows": [
[
[
{
"type": "paragraph",
"inlineContent": [
{ "type": "text", "text": "cell 1:1" }
]
}
],
[
{
"type": "paragraph",
"inlineContent": [
{ "type": "text", "text": "cell 1:2" }
]
}
]
]
]
}
| cell 1:1 | cell 1:2 |
|---|
mockup: this fixture's single row is entirely consumed as the header row because
header: "row" selects the TableHeaderStyle.row branch of
renderTableChildren(), which puts the first (and, here, only) row inside
<thead> with every cell rendered as <th scope="col">, leaving
<tbody> empty. The <caption> is synthesized from
metadata.title + metadata.abstract and, because a title is present,
positioned above the table (CaptionPosition.leading) rather than below.
3. Data sheet
Source: Sources/DocCArchive/Vendored/RenderNode.spec.json, schema object
#/components/schemas/Table (lines 999–1057), one arm of the RenderBlockContent
discriminated union (oneOf entry at line 468), plus the separate
#/components/schemas/TableExtendedData object (lines 1058–1067) referenced by
extendedData's additionalProperties. Cross-checked against
Components.Schemas.Table and Components.Schemas.TableExtendedData in
Sources/DocCArchive/generated/Types.swift (lines 4519–4609 and 4610–4632
respectively); the enclosing union case is Components.Schemas.RenderBlockContent.Table at line
3625.
| Field | Type | Required | Enum values / default | Note |
|---|---|---|---|---|
type |
string | yes | "table" (single-value enum) |
Generated as _TypePayload: String, Codable, Hashable, Sendable, CaseIterable { case table = "table"
}, mapped from the Swift property _type back onto the wire key "type" via
CodingKeys._type = "type" — the underscore-prefixed name exists because
type collides with a reserved/ambiguous identifier in the generator's output style. |
header |
string enum | yes | "row" | "column" | "both" | "none", no wire-schema default (swift-docc's authoring model
defaults absent values to .none via RenderBlockContent.HeaderType, but the JSON
schema itself does not declare a default) |
Generated as HeaderPayload: String, Codable, Hashable, Sendable, CaseIterable with the four
cases. Selects which of four layouts renderTableChildren() builds (see Section 1). |
alignments |
array of string enum | no | items: "left" | "right" | "center" | "unset" |
Generated as AlignmentsPayload = [AlignmentsPayloadPayload], optional. One entry per column,
indexed positionally against each row's cells; a missing or "unset" entry adds no alignment
class. swift-docc's own encoder additionally suppresses this key entirely on the wire when every alignment
value is .unset (see Section 3's swift-docc note below) — that squashing happens before
the JSON is written, so by the time DocCArchive decodes it, alignments is simply either absent
or a fully meaningful array. |
rows |
array of array of array of RenderBlockContent |
yes | — (no minimum-count constraint in the wire schema) | Generated as [[[Components.Schemas.RenderBlockContent]]]: outer array is rows, middle array
is cells within a row, inner array is the block-content nodes making up that cell's content (typically a
single paragraph, but any block content is legal, since cells recursively admit the full
RenderBlockContent union — including nested tables). |
extendedData |
object (map) | no | keys match pattern "{row}_{column}" (zero-based); values are TableExtendedData
objects |
Generated as an ExtendedDataPayload wrapper struct holding
additionalProperties: [String: Components.Schemas.TableExtendedData], since OpenAPI has no
native "dynamic key" map type. swift-docc's own encoder (see below) only emits this key at all when the set
is non-empty. |
extendedData values: colspan |
integer | no (optional in the wire schema) | — | Generated as Swift.Int?. A value of 0 tells DocC-render this cell is "spanned
over" by an earlier cell and must not be rendered at all (see renderTableCell(), Section 1);
swift-docc's authoring-side TableCellExtendedData struct documents 1 as the
implicit default when absent. |
extendedData values: rowspan |
integer | no (optional in the wire schema) | — | Generated as Swift.Int?. Same "0 means spanned-over, else HTML rowspan attribute" semantics
as colspan, but along the row axis. |
metadata |
RenderContentMetadata object |
no | — | Fields anchor/title/abstract/deviceFrame (all
optional). Only anchor (used as the table's DOM id) and
title/abstract (used to synthesize a <caption>, only when
abstract is present) are consulted by the table renderer; deviceFrame is ignored
for this kind. |
On the swift-docc production side (secondary/flavor source, not authoritative for wire shape), the enclosing
enum case is case table(Table)
(Sources/SwiftDocC/Model/Rendering/Content/RenderBlockContent.swift, line 63), and the nested
struct is declared at the same file, lines 551–585:
public struct Table {
public var header: HeaderType
public var alignments: [ColumnAlignment]?
public var rows: [TableRow]
public var extendedData: Set<TableCellExtendedData>
public var metadata: RenderContentMetadata?
}
This matches the wire schema field-for-field, but note the model-layer shapes differ slightly from the raw
JSON layout: extendedData is a Swift Set<TableCellExtendedData> (each element
carrying its own rowIndex/columnIndex) rather than a dictionary keyed by a composite
string, and Table has a hand-written Codable conformance
(RenderBlockContent.swift lines 911–995) specifically because "the encoding of
extendedData does not follow from the struct layout" — it builds a
DynamicIndexCodingKey whose stringValue is "{row}_{column}" to produce
exactly the wire shape the JSON schema describes. That same encoder also suppresses the alignments
key on the wire whenever every alignment is .unset
(RenderBlockContent.swift line 979), and suppresses extendedData entirely when the
set is empty (line 985) — both are swift-docc production behaviors, not wire-schema requirements, which
is why the data sheet above lists both fields as merely optional rather than describing this omission logic
as part of the schema itself. An author produces a table simply by writing a standard GitHub-Flavored-Markdown
pipe table in a documentation comment or article; swift-docc's Markdown parser (swift-markdown) turns the
leading ---/:--/--:/:-: separator row into header and alignments, and
there is no dedicated @Table-style DocC directive or catalog article describing bespoke
authoring syntax for this kind, unlike, say, @TabNavigator.
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 table node
parsed via Components.Schemas.Table 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 table node, in context:
div.table-wrapper(with anoverflow: autoscroll container for wide tables) — the component root, fromTable.vue.table(with modifier classspannedwhenextendedDatais present) — the actual table element, given the optionalidattribute fromnode.metadata.anchor.caption(only present whennode.metadata.abstractis set), with modifier classtrailingwhen there is notitle— produced by the sharedCaptioncomponent and always the table's first child, as HTML requires.thead>tr> oneth[scope=col]per column (present only forheader: "row"or"both"), and/or a per-rowth[scope=row]as the first cell of each body row (present only forheader: "column"or"both").tbody> onetrper remaining row > onetd(or, for header-column/both styles, one leadingth[scope=row]plus trailingtds) per cell, each optionally carryingcolspan/rowspanattributes copied straight fromextendedData, and an alignment modifier class ofleft-cell,right-cell, orcenter-cellfrom thealignmentsarray.
SCSS: Table.vue carries its own scoped <style> block
(Table.vue#L31-L71):
.table-wrapper { overflow: auto; -webkit-overflow-scrolling: touch; @include space-out-between-siblings(var(--spacing-stacked-margin-xlarge)); }— horizontal scroll on narrow viewports plus vertical spacing from sibling content blocks via a shared mixin.table { border-style: hidden; }— the outer table border is suppressed so only cell borders (below) are visible, avoiding doubled edges.:deep() { th { font-weight: $font-weight-semibold; word-break: keep-all; hyphens: auto; } }— header cells get semibold weight and controlled line-breaking, penetrating into the slotted<thead>/<tbody>content via Vue's:deep()combinator (this component only renders a wrapper<table>around a<slot />, so its scoped styles must explicitly pierce into slotted children).td, th { border-color: var(--color-fill-gray-tertiary); border-style: solid; border-width: var(--table-border-width, 1px 1px); padding: rem(10px); }plus&.left-cell { text-align: left; },&.right-cell { text-align: right; },&.center-cell { text-align: center; }— the actual cell grid lines and the column-alignment classes emitted byrenderTableCell().
The synthesized <caption> is styled by Caption.vue's own scoped block
(Caption.vue#L61-L83),
notably caption.trailing { caption-side: bottom; } — a comment in that file explains this
override exists specifically because a native <caption> element must be the table's first
child in the DOM even when it is visually pinned to the bottom via caption-side.
CSS custom properties consumed: --color-fill-gray-tertiary for cell border color,
--table-border-width (falling back to 1px 1px) for the border thickness, and the
shared --spacing-stacked-margin-xlarge/--spacing-stacked-margin-large spacing
tokens used by the wrapper and caption respectively; the caption's typography comes from the generic
font-styles(documentation-caption) mixin rather than a raw custom property.
5. Modern CSS-only alternative
Not applicable
Current behavior in play: there is none to replace. ContentNode.vue's table path
(renderTableChildren()/renderTableCell(), Section 1) and Table.vue
(Section 4) together do nothing but a one-time, build/render-time transformation of wire JSON into a plain,
static <table><caption><thead><tbody><tr><th><td> DOM
tree. There is no component data(), no v-model, no click handler, no
v-show/v-if toggling, and no watcher anywhere in this kind's rendering path — every
piece of markup that ends up on the page is exactly the markup produced the first and only time
renderNode() runs over the node. The only thing resembling "behavior" is the CSS-only horizontal
scrollbar on .table-wrapper { overflow: auto; } for tables wider than their container, which is
already a plain CSS mechanism today, not a JavaScript one needing replacement. Since this kind is stateless
and has no interactive behavior in the current implementation, there is no state-holding mechanism (radio
input, :target, <details>, or otherwise) to name as a "modern CSS equivalent"
— the current implementation already is the CSS/HTML equivalent.