Sections & blocks›Deflist

core

Deflist

Block-level definition list — stacked dt/dd pairs that flow into multiple columns on wider screens

Source

import Markdoc from '@markdoc/markdoc';
import type { RenderableTreeNode, Node } from '@markdoc/markdoc';
const { Ast, Tag } = Markdoc;
import { createContentModelSchema, asNodes } from '../lib/index.js';

function extractTermPrefix(
	itemNode: Node,
): { term: Node[]; rest: Node[]; restBlocks: Node[] } | null {
	const children = itemNode.children ?? [];
	if (children.length === 0) return null;

	let inlineNode: Node | undefined;
	let restBlockChildren: Node[];

	const first = children[0];
	if (first?.type === 'inline') {
		inlineNode = first;
		restBlockChildren = children.slice(1);
	} else if (first?.type === 'paragraph') {
		inlineNode = first.children?.[0];
		restBlockChildren = children.slice(1);
	} else {
		return null;
	}

	if (!inlineNode || inlineNode.type !== 'inline') return null;

	const inlineKids = inlineNode.children ?? [];
	if (inlineKids.length === 0) return null;

	const head = inlineKids[0];
	if (!head || head.type !== 'strong') return null;

	const strongChildren = head.children ?? [];
	let strongText = '';
	for (const c of strongChildren) {
		if (c.type === 'text' && typeof c.attributes?.content === 'string') {
			strongText += c.attributes.content;
		}
	}
	if (!strongText.endsWith(':')) return null;

	const termText = strongText.slice(0, -1);
	const termNodes: Node[] = [new Ast.Node('text', { content: termText }) as Node];

	const remainingInline = inlineKids.slice(1);
	const trimmed = (() => {
		const first = remainingInline[0];
		if (first?.type === 'text' && typeof first.attributes?.content === 'string') {
			const stripped = first.attributes.content.replace(/^\s+/, '');
			if (stripped === '') return remainingInline.slice(1);
			const clone = new Ast.Node('text', { content: stripped }) as Node;
			return [clone, ...remainingInline.slice(1)];
		}
		return remainingInline;
	})();

	const restInline = trimmed.length > 0 ? [new Ast.Node('inline', {}, trimmed) as Node] : [];

	const restParagraph: Node[] =
		restInline.length > 0 ? [new Ast.Node('paragraph', {}, restInline) as Node] : [];

	return {
		term: termNodes,
		rest: restInline,
		restBlocks: [...restParagraph, ...restBlockChildren],
	};
}

export const deflist = createContentModelSchema({
	attributes: {},
	contentModel: {
		type: 'sequence',
		fields: [{ name: 'list', match: 'list', optional: false }],
	},
	transform(resolved, _attrs, config) {
		const listNodes = asNodes(resolved.list);
		const listNode = listNodes.find((n) => n.type === 'list');
		if (!listNode) {
			return new Tag(
				'dl',
				{
					'data-rune': 'deflist',
					'data-zone-layout': 'definition-list',
				},
				[],
			);
		}

		const items = (listNode.children ?? []).filter((c) => c.type === 'item');
		const rows: RenderableTreeNode[] = [];

		for (const item of items) {
			const extracted = extractTermPrefix(item);
			let dt: RenderableTreeNode;
			let dd: RenderableTreeNode;

			if (extracted) {
				const termRendered = Markdoc.transform(extracted.term, config) as RenderableTreeNode[];
				const valueRendered = Markdoc.transform(
					extracted.restBlocks,
					config,
				) as RenderableTreeNode[];
				dt = new Tag('dt', { 'data-meta-label': '' }, termRendered);
				dd = new Tag('dd', {}, unwrapSingleParagraph(valueRendered));
			} else {
				const fullRendered = Markdoc.transform(item.children ?? [], config) as RenderableTreeNode[];
				dt = new Tag('dt', { 'data-meta-label': '' }, []);
				dd = new Tag('dd', {}, unwrapSingleParagraph(fullRendered));
				warnDeflistUnparsedItem(item);
			}

			rows.push(new Tag('div', { 'data-name': 'row' }, [dt, dd]));
		}

		return new Tag(
			'dl',
			{
				'data-rune': 'deflist',
				'data-zone-layout': 'definition-list',
			},
			rows,
		);
	},
});

function unwrapSingleParagraph(nodes: RenderableTreeNode[]): RenderableTreeNode[] {
	if (nodes.length !== 1) return nodes;
	const only = nodes[0];
	if (!Markdoc.Tag.isTag(only) || only.name !== 'p') return nodes;
	return only.children;
}

const DEFLIST_WARNED = new Set<string>();
function warnDeflistUnparsedItem(item: Node): void {
	const loc = item.location ?? null;
	const key = loc ? `${loc.start?.line ?? '?'}:${loc.start?.character ?? '?'}` : 'unknown';
	if (DEFLIST_WARNED.has(key)) return;
	DEFLIST_WARNED.add(key);
	// eslint-disable-next-line no-console
	console.warn(
		`[refrakt] {% deflist %} item at line ${loc?.start?.line ?? '?'} lacks ` +
			`a \`**Term:**\` prefix — rendered with empty <dt>. Prefix the item ` +
			`with bold term text ending in \`:\` to label it.`,
	);
}

View packages/runes/src/tags/deflist.ts on GitHub

A list of terms and their descriptions. Each list item that starts with **Term:** becomes a term and its description, stacked on a narrow screen and spread into columns where there is room.

Use it for option references, glossaries, attribute tables, recipe details, character stats — any term/description pair set. Composable inside any container rune, identical DOM to a projected metadata zone using the same layout primitive.

Basic usage

A markdown list where each item starts with bold-text-plus-colon.

{% deflist %}
- **Priority:** {% badge sentiment="caution" %}high{% /badge %}
- **Complexity:** moderate
- **Assignee:** @alice
- **Milestone:** v0.18
{% /deflist %}
<dl data-rune="deflist" data-zone-layout="definition-list">
  <div data-name="row">
    <dt data-meta-label="">Priority</dt>
    <dd>
      <span class="rf-badge" data-rune="badge" data-meta-sentiment="caution" data-meta-type="tag">high</span>
    </dd>
  </div>
  <div data-name="row">
    <dt data-meta-label="">Complexity</dt>
    <dd>moderate</dd>
  </div>
  <div data-name="row">
    <dt data-meta-label="">Assignee</dt>
    <dd>@alice</dd>
  </div>
  <div data-name="row">
    <dt data-meta-label="">Milestone</dt>
    <dd>v0.18</dd>
  </div>
</dl>
Priority
high
Complexity
moderate
Assignee
@alice
Milestone
v0.18
<dl data-zone-layout="definition-list" class="rf-deflist" data-rune="deflist" data-density="full">
  <div data-name="row" class="rf-deflist__row">
    <dt data-meta-label="">Priority</dt>
    <dd>
      <span class="rf-badge rf-badge" data-meta-sentiment="caution" data-meta-type="tag" data-rune="badge" data-density="full">high</span>
    </dd>
  </div>
  <div data-name="row" class="rf-deflist__row">
    <dt data-meta-label="">Complexity</dt>
    <dd>moderate</dd>
  </div>
  <div data-name="row" class="rf-deflist__row">
    <dt data-meta-label="">Assignee</dt>
    <dd>@alice</dd>
  </div>
  <div data-name="row" class="rf-deflist__row">
    <dt data-meta-label="">Milestone</dt>
    <dd>v0.18</dd>
  </div>
</dl>

How Markdown is read

You writeIt becomes
A listThe definition list, one term and description per item
**Term:** at the start of an itemThe term; the rest of the item is its description
An item with no bold prefixAn empty term, with the whole item as the description, and a build warning

Inline composition

Inline runes inside the value (after **Term:**) compose naturally. Use {% badge %} for sentiment-colored chips, {% ref %} for entity links, inline code for identifiers.

{% deflist %}
- **Status:** {% badge sentiment="positive" %}accepted{% /badge %}
- **Version:** `v0.16.2`
- **Released:** 2026-01-15
{% /deflist %}
<dl data-rune="deflist" data-zone-layout="definition-list">
  <div data-name="row">
    <dt data-meta-label="">Status</dt>
    <dd>
      <span class="rf-badge" data-rune="badge" data-meta-sentiment="positive" data-meta-type="tag">accepted</span>
    </dd>
  </div>
  <div data-name="row">
    <dt data-meta-label="">Version</dt>
    <dd>
      <code>v0.16.2</code>
    </dd>
  </div>
  <div data-name="row">
    <dt data-meta-label="">Released</dt>
    <dd>2026-01-15</dd>
  </div>
</dl>
Status
accepted
Version
v0.16.2
Released
2026-01-15
<dl data-zone-layout="definition-list" class="rf-deflist" data-rune="deflist" data-density="full">
  <div data-name="row" class="rf-deflist__row">
    <dt data-meta-label="">Status</dt>
    <dd>
      <span class="rf-badge rf-badge" data-meta-sentiment="positive" data-meta-type="tag" data-rune="badge" data-density="full">accepted</span>
    </dd>
  </div>
  <div data-name="row" class="rf-deflist__row">
    <dt data-meta-label="">Version</dt>
    <dd>
      <code>v0.16.2</code>
    </dd>
  </div>
  <div data-name="row" class="rf-deflist__row">
    <dt data-meta-label="">Released</dt>
    <dd>2026-01-15</dd>
  </div>
</dl>

Fallback for items without a bold prefix

If a list item doesn't start with **Term:**, the rune emits an empty <dt> plus the full content in <dd> and prints a build-time warning naming the line. Prefix every item with bold-term-colon to label it properly.

{% deflist %}
- **Owner:** Platform team
- Reviewed every quarter
{% /deflist %}
<dl data-rune="deflist" data-zone-layout="definition-list">
  <div data-name="row">
    <dt data-meta-label="">Owner</dt>
    <dd>Platform team</dd>
  </div>
  <div data-name="row">
    <dt data-meta-label=""></dt>
    <dd>Reviewed every quarter</dd>
  </div>
</dl>
Owner
Platform team
Reviewed every quarter
<dl data-zone-layout="definition-list" class="rf-deflist" data-rune="deflist" data-density="full">
  <div data-name="row" class="rf-deflist__row">
    <dt data-meta-label="">Owner</dt>
    <dd>Platform team</dd>
  </div>
  <div data-name="row" class="rf-deflist__row">
    <dt data-meta-label=""></dt>
    <dd>Reviewed every quarter</dd>
  </div>
</dl>

Aliases

The rune is also registered as definitions and terms for authoring preference. All three names produce identical DOM.

{% definitions %}
- **Owner:** Platform team
{% /definitions %}

{% terms %}
- **Owner:** Platform team
{% /terms %}

On narrow screens

A definition list follows the width it has: each term sits above its description on a narrow screen, and the pairs spread into columns where there is room.

Attributes

Universal attributes

bg

The background layer: image, video, gradient, flat overlay wash and legibility scrim, in a single injected layer behind the rune's content.

AttributeTypeRequiredDescription
bgstring—Background preset applied to this block
bg-fromstring—Gradient start colour — a semantic token name (→ var(--rf-color-*))
bg-gradient"to-t" | "to-b" | "to-l" | "to-r" | "to-tr" | "to-br" | "to-bl" | "to-tl"—Gradient direction (bounded named set)
bg-gradient-type"linear" | "radial" | "conic"—Gradient type
bg-tostring—Gradient end colour — a semantic token name
bg-viastring—Optional middle gradient stop — a semantic token name
scrim"top" | "bottom" | "left" | "right" | "none"—Scrim direction (heaviest edge); presence turns the scrim on, "none" opts out of the default cover scrim
scrim-blur"none" | "sm" | "md" | "lg"—Frost scrim blur amount
scrim-strength"sm" | "md" | "lg"—Gradient scrim strength
scrim-tone"dark" | "light"—Whether the scrim darkens (for light text) or lightens (for dark text)
scrim-type"gradient" | "frost"—Scrim treatment: gradient (default) or frost (backdrop blur)
elevation

How far the rune sits off the page, from sunken to overlay. The theme decides what each step looks like.

AttributeTypeRequiredDescription
elevation"sunken" | "flush" | "flat" | "raised" | "floating" | "overlay" | "none" | "sm" | "md" | "lg"—Surface depth, from sunken to overlay. Deprecated: none, sm, md and lg (read as flat, raised, raised and floating)
inset

Internal padding override.

AttributeTypeRequiredDescription
inset"flush" | "tight" | "default" | "loose" | "breathe"—Inner padding of this block
motion

Scroll-reveal entrance. You choose its character; the theme decides how it moves.

AttributeTypeRequiredDescription
reveal"none" | "fade" | "slide" | "scale" | "blur"—Scroll-reveal entrance character (none|fade|slide|scale|blur); the theme owns the choreography
staggerboolean—Cascade this block's items in as it reveals (no-op on single-child runes)
spacing

Block-level rhythm override.

AttributeTypeRequiredDescription
spacing"flush" | "tight" | "default" | "loose" | "breathe"—Vertical spacing above and below this block
substrate

Generated pattern fills behind the content, drawn by the theme.

AttributeTypeRequiredDescription
substrate"dots" | "grid" | "lines" | "cross" | "checker" | "none"—Generated surface pattern
substrate-fill"inherit" | "inset"—Surface fill the pattern sits on (full colour stays with tint)
substrate-opacity"sm" | "md" | "lg"—Pattern ink strength
substrate-size"sm" | "md" | "lg"—Pattern cell size
substrate-target"self" | "media"—Which surface the pattern fills (overrides the rune/theme default)
tint

Per-rune colour override: a named tint from the theme registry, with inline per-token overrides layered on top.

AttributeTypeRequiredDescription
tintstring—Color tint preset applied to this block
tint-mode"auto" | "dark" | "light"—Whether the tint adapts to auto, dark, or light mode
width

The track a block rune occupies.

AttributeTypeRequiredDescription
width"compact" | "narrow" | "content" | "wide" | "full"—Maximum width constraint for this block
Not availableWhy
dropcap, readingthis rune declares no prose body
framethis rune declares neither a `frameTarget` nor a media section
prominencethis rune has no page-section header or featured quotation

See also

  • {% bar %} — sibling composable rune for the bar layout primitive.
  • {% badge %} — the chip primitive used inside sentiment-mapped <dd> cells.