storytelling
Realm
Location profiles for worldbuilding with geography and notable features
Install
- Add the package:
npm install @refrakt-md/storytelling - Add it to the
pluginsarray inrefrakt.config.json:"plugins": ["@refrakt-md/storytelling"]
Source
import Markdoc from '@markdoc/markdoc';
import type { RenderableTreeNode } from '@markdoc/markdoc';
const { Tag } = Markdoc;
import {
createComponentRenderable,
createContentModelSchema,
bodyOnly,
asNodes,
renderNodes,
RenderableNodeCursor,
SplitLayoutModel,
buildLayoutMetas,
} from '@refrakt-md/runes';
import { extractScene, buildStoryContent } from './common.js';
export const realmSectionSections = { body: 'body' } as const;
export const realmSection = createContentModelSchema({
sections: realmSectionSections,
provides: ['prose'],
attributes: {
name: { type: String, required: true },
},
contentModel: bodyOnly(),
transform(resolved, attrs, config) {
const nameTag = new Tag('span', {}, [attrs.name ?? '']);
const body = renderNodes(resolved.body, config).wrap('div');
return createComponentRenderable({
rune: 'realm-section',
tag: 'div',
refs: { name: nameTag, body: body.tag('div') },
children: [nameTag, body.next()],
});
},
});
export const realmSections = {
preamble: 'preamble',
name: 'title',
scene: 'media',
body: 'body',
} as const;
export const realmMediaSlots = { scene: 'cover' } as const;
export const realmSchema = {
type: 'Place',
properties: { name: 'name', realmType: 'additionalType', sceneImage: 'image' },
} as const;
export const realm = createContentModelSchema({
registers: {
entity: { idFrom: 'name', data: ['realmType', 'scale', 'tags', 'parent', 'name'] },
},
schema: realmSchema,
sections: realmSections,
provides: ['prose'],
mediaSlots: realmMediaSlots,
base: SplitLayoutModel,
attributes: {
name: { type: String, required: true, description: 'Display name shown in the realm header.' },
type: {
type: String,
required: false,
description: 'Kind of location (e.g. city, forest, dungeon, plane, continent).',
},
scale: {
type: String,
required: false,
description: 'Geographic scope of the realm (e.g. room, district, region, world).',
},
tags: {
type: String,
required: false,
description: 'Comma-separated keywords for filtering and cross-referencing.',
},
parent: {
type: String,
required: false,
description: 'Name of the containing realm for hierarchical nesting.',
},
},
contentModel: () => ({
type: 'sections' as const,
sectionHeading: 'heading',
emitTag: 'realm-section',
emitAttributes: { name: '$heading' },
fields: [
{ name: 'scene', match: 'paragraph', optional: true },
{ name: 'description', match: 'paragraph', optional: true, greedy: true },
{ name: 'items', match: 'tag', optional: true, greedy: true },
],
sectionModel: {
type: 'sequence' as const,
fields: [{ name: 'body', match: 'any', optional: true, greedy: true }],
},
}),
transform(resolved, attrs, config) {
const allItems = [...asNodes(resolved.items), ...asNodes(resolved.sections)];
const sectionNodes = new RenderableNodeCursor(
Markdoc.transform(allItems, config) as RenderableTreeNode[],
);
const nameTag = new Tag('span', {}, [attrs.name ?? '']);
const realmTypeMeta = new Tag('meta', { content: attrs.type ?? 'place' });
const scaleMeta = new Tag('meta', { content: attrs.scale ?? '' });
const tagsMeta = new Tag('meta', { content: attrs.tags ?? '' });
const parentMeta = new Tag('meta', { content: attrs.parent ?? '' });
const { metas: layoutMetas } = buildLayoutMetas(attrs);
const {
mediaPosition: mediaPositionMeta,
mediaRatio: mediaRatioMeta,
valign: valignMeta,
collapse: collapseMeta,
} = layoutMetas;
const { sceneDiv, sceneImgTag, extraDescription } = extractScene(resolved.scene, config);
const { bodyDiv, sectionsContainer, sections, hasSections } = buildStoryContent(
extraDescription,
resolved.description,
sectionNodes,
'RealmSection',
config,
);
const children: any[] = [];
if (sceneDiv) children.push(sceneDiv.next());
children.push(nameTag);
if (bodyDiv) children.push(bodyDiv.next());
if (sectionsContainer) children.push(sectionsContainer.next());
return createComponentRenderable({
rune: 'realm',
tag: 'article',
properties: {
realmType: realmTypeMeta,
scale: scaleMeta,
tags: tagsMeta,
parent: parentMeta,
'media-position': mediaPositionMeta,
'media-ratio': mediaRatioMeta,
valign: valignMeta,
collapse: collapseMeta,
...(hasSections ? { section: sections } : {}),
},
refs: {
name: nameTag,
scene: sceneDiv,
sceneImage: sceneImgTag,
body: bodyDiv,
sections: sectionsContainer,
},
children,
});
},
});
Location and place profiles for worldbuilding. For a person, use character; for an order, guild or other group, faction.
Basic usage
Describe a location with sections for geography, features, or history.
{% realm name="Hollowmere" type="sanctuary" scale="settlement" media-position="start" %}

The last refuge of the scholars who fled the Ashen Spire.
## Geography
A hidden valley at the head of the Eastern March, reachable only by a single cliff road.
## Notable Features
- The Lantern Hall
- A bridge of living stone
- Libraries carved into the gorge
{% /realm %}<article data-rune="realm" data-rune-fields="{"realmType":"sanctuary","scale":"settlement","tags":"","parent":"","media-position":"start"}" typeof="Place">
<div data-name="scene">
<img src="https://assets.refrakt.md/realm-rivendell.png" alt="The terraced halls of Hollowmere above a river gorge" data-name="sceneImage" property="image">
</div>
<span data-name="name" property="name">Hollowmere</span>
<div data-name="body">
<p>The last refuge of the scholars who fled the Ashen Spire.</p>
</div>
<div data-name="sections">
<div data-rune="realm-section" data-field="section">
<span data-name="name">Geography</span>
<div data-name="body">
<p>A hidden valley at the head of the Eastern March, reachable only by a single cliff road.</p>
</div>
</div>
<div data-rune="realm-section" data-field="section">
<span data-name="name">Notable Features</span>
<div data-name="body">
<ul>
<li>The Lantern Hall</li>
<li>A bridge of living stone</li>
<li>Libraries carved into the gorge</li>
</ul>
</div>
</div>
</div>
<meta property="additionalType" content="sanctuary">
</article>
The last refuge of the scholars who fled the Ashen Spire.
A hidden valley at the head of the Eastern March, reachable only by a single cliff road.
- The Lantern Hall
- A bridge of living stone
- Libraries carved into the gorge
<article class="rf-realm rf-realm--sanctuary rf-realm--settlement" typeof="Place" data-realm-type="sanctuary" data-scale="settlement" data-tags="" data-parent="" data-media-position="start" data-elevation="flat" data-rune="realm" data-density="full">
<div data-name="scene" class="rf-realm__scene" data-section="media" data-media="cover" data-guest-fit="clip">
<img src="https://assets.refrakt.md/realm-rivendell.png" alt="The terraced halls of Hollowmere above a river gorge" data-name="sceneImage" property="image" class="rf-realm__sceneImage" />
</div>
<div data-name="content" class="rf-realm__content">
<header data-name="preamble" class="rf-realm__preamble" data-section="preamble">
<span data-name="name" property="name" class="rf-realm__name" data-section="title">Hollowmere</span>
</header>
<dl data-name="metadata" data-zone="metadata" data-zone-layout="definition-list" class="rf-realm__metadata">
<div data-name="row" data-field="realmType" class="rf-realm__row">
<dt data-meta-label="">Type</dt>
<dd>
<span data-meta-type="category">sanctuary</span>
</dd>
</div>
<div data-name="row" data-field="scale" class="rf-realm__row">
<dt data-meta-label="">Scale</dt>
<dd>
<span data-meta-type="category">settlement</span>
</dd>
</div>
</dl>
<div data-name="body" class="rf-realm__body" data-section="body">
<p>The last refuge of the scholars who fled the Ashen Spire.</p>
</div>
<div data-name="sections" class="rf-realm__sections">
<div class="rf-realm-section" data-field="section" data-rune="realm-section" data-density="full">
<span data-name="name" class="rf-realm-section__name">Geography</span>
<div data-name="body" class="rf-realm-section__body" data-section="body">
<p>A hidden valley at the head of the Eastern March, reachable only by a single cliff road.</p>
</div>
</div>
<div class="rf-realm-section" data-field="section" data-rune="realm-section" data-density="full">
<span data-name="name" class="rf-realm-section__name">Notable Features</span>
<div data-name="body" class="rf-realm-section__body" data-section="body">
<ul>
<li>The Lantern Hall</li>
<li>A bridge of living stone</li>
<li>Libraries carved into the gorge</li>
</ul>
</div>
</div>
</div>
</div>
<meta property="additionalType" content="sanctuary" />
</article>How Markdown is read
| You write | It becomes |
|---|---|
| An image before everything else | The scene illustration (Place the scene) |
| Paragraphs before the first heading | The description |
| A heading | A named section; the content up to the next heading of that level is its body |
Nest realms
parent names the realm a place sits inside, so a district can belong to its city and a city to its region. type and scale are free text — city, forest, dungeon; room, district, region, world.
{% realm name="The Undercroft" type="dungeon" scale="district" parent="Thornwall" media-position="start" %}

## Overview
A sprawling network of tunnels beneath Thornwall, home to the Whispering Hand and worse.
## Dangers
- Flooded passages
- Collapsing ceilings
- Cave spiders
{% /realm %}<article data-rune="realm" data-rune-fields="{"realmType":"dungeon","scale":"district","tags":"","parent":"Thornwall","media-position":"start"}" typeof="Place">
<div data-name="scene">
<img src="https://assets.refrakt.md/realm-the-undercroft.png" alt="Flooded stone tunnels lit by a single lantern" data-name="sceneImage" property="image">
</div>
<span data-name="name" property="name">The Undercroft</span>
<div data-name="sections">
<div data-rune="realm-section" data-field="section">
<span data-name="name">Overview</span>
<div data-name="body">
<p>A sprawling network of tunnels beneath Thornwall, home to the Whispering Hand and worse.</p>
</div>
</div>
<div data-rune="realm-section" data-field="section">
<span data-name="name">Dangers</span>
<div data-name="body">
<ul>
<li>Flooded passages</li>
<li>Collapsing ceilings</li>
<li>Cave spiders</li>
</ul>
</div>
</div>
</div>
<meta property="additionalType" content="dungeon">
</article>
A sprawling network of tunnels beneath Thornwall, home to the Whispering Hand and worse.
- Flooded passages
- Collapsing ceilings
- Cave spiders
<article class="rf-realm rf-realm--dungeon rf-realm--district rf-realm--Thornwall" typeof="Place" data-realm-type="dungeon" data-scale="district" data-tags="" data-parent="Thornwall" data-media-position="start" data-elevation="flat" data-rune="realm" data-density="full">
<div data-name="scene" class="rf-realm__scene" data-section="media" data-media="cover" data-guest-fit="clip">
<img src="https://assets.refrakt.md/realm-the-undercroft.png" alt="Flooded stone tunnels lit by a single lantern" data-name="sceneImage" property="image" class="rf-realm__sceneImage" />
</div>
<div data-name="content" class="rf-realm__content">
<header data-name="preamble" class="rf-realm__preamble" data-section="preamble">
<span data-name="name" property="name" class="rf-realm__name" data-section="title">The Undercroft</span>
</header>
<dl data-name="metadata" data-zone="metadata" data-zone-layout="definition-list" class="rf-realm__metadata">
<div data-name="row" data-field="realmType" class="rf-realm__row">
<dt data-meta-label="">Type</dt>
<dd>
<span data-meta-type="category">dungeon</span>
</dd>
</div>
<div data-name="row" data-field="scale" class="rf-realm__row">
<dt data-meta-label="">Scale</dt>
<dd>
<span data-meta-type="category">district</span>
</dd>
</div>
</dl>
<div data-name="sections" class="rf-realm__sections">
<div class="rf-realm-section" data-field="section" data-rune="realm-section" data-density="full">
<span data-name="name" class="rf-realm-section__name">Overview</span>
<div data-name="body" class="rf-realm-section__body" data-section="body">
<p>A sprawling network of tunnels beneath Thornwall, home to the Whispering Hand and worse.</p>
</div>
</div>
<div class="rf-realm-section" data-field="section" data-rune="realm-section" data-density="full">
<span data-name="name" class="rf-realm-section__name">Dangers</span>
<div data-name="body" class="rf-realm-section__body" data-section="body">
<ul>
<li>Flooded passages</li>
<li>Collapsing ceilings</li>
<li>Cave spiders</li>
</ul>
</div>
</div>
</div>
</div>
<meta property="additionalType" content="dungeon" />
</article>Place the scene
A realm's scene field (the image at the top of each section) is the media zone; media-position controls where it sits relative to the content. Beside layouts (start/end) collapse to a stack at narrow widths.
media-ratio, valign and collapse tune a side-by-side split, as on card.
Attributes
| Attribute | Type | Required | Description |
|---|---|---|---|
name | string | ✓ | Display name shown in the realm header. |
type | string | — | Kind of location (e.g. city, forest, dungeon, plane, continent). |
scale | string | — | Geographic scope of the realm (e.g. room, district, region, world). |
tags | string | — | Comma-separated keywords for filtering and cross-referencing. |
parent | string | — | Name of the containing realm for hierarchical nesting. |
Inherited from the split layout preset
| Attribute | Type | Required | Description |
|---|---|---|---|
media-position | "top" | "bottom" | "start" | "end" | "cover" | — | Where the media zone sits relative to the content: above (top), below (bottom), or beside (start/end) |
media-ratio | "1/3" | "2/5" | "1/2" | "3/5" | "2/3" | — | Media zone’s share of the row width when media is beside content (start/end) |
valign | "top" | "center" | "bottom" | "stretch" | — | Cross-axis alignment when media is beside content (start/end); applies to the shorter zone |
collapse | "sm" | "md" | "lg" | "never" | — | Breakpoint at which side-by-side layouts collapse to a single stacked column |
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.
| Attribute | Type | Required | Description |
|---|---|---|---|
bg | string | — | Background preset applied to this block |
bg-from | string | — | 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-to | string | — | Gradient end colour — a semantic token name |
bg-via | string | — | 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) |
dropcap
Per-instance drop-cap opt-in.
| Attribute | Type | Required | Description |
|---|---|---|---|
dropcap | boolean | — | Style the opening letter of a prose body as a drop cap. Honoured only when the body reads as prose; ignored otherwise. |
elevation
How far the rune sits off the page, from sunken to overlay. The theme decides what each step looks like.
| Attribute | Type | Required | Description |
|---|---|---|---|
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) |
frame
Surface chrome: a named preset from the theme registry with inline `frame-*` overrides layered on top.
| Attribute | Type | Required | Description |
|---|---|---|---|
frame | string | — | Named frame preset presenting this block's media surface |
frame-anchor | string | — | Crop focal point when the guest is cut (object-position) |
frame-aspect | string | — | Aspect ratio of the framed media, e.g. "16/9" |
frame-displace | "top" | "bottom" | "end" | "bottom-end" | "top-end" | "both" | — | Edge/corner the framed guest moves toward |
frame-displace-mode | "peek" | "bleed" | — | How displacement renders: `peek` (default) translates the guest visually inside its frame target; `bleed` uses negative margin on the media zone so following layout pulls up — extends past a section like a hero without leaving a gap above |
frame-offset | "none" | "sm" | "md" | "lg" | "xl" | "2xl" | "3xl" | "4xl" | — | Displacement distance (non-linear named scale: sm…xl ride the block-spacing tokens, 2xl/3xl/4xl step up to section-spacing for bleed-mode displacements that clear a section edge) |
frame-overflow | "clip" | "bleed" | — | How the frame handles a guest whose content is wider than it: `clip` (default) keeps it inside the rounded frame; `bleed` runs an overflowing guest out to the layout edge on a narrow viewport so it reads as cropped by the screen (a bleed host only — hero/feature) |
frame-oversize | string | — | How far the guest exceeds its slot (scale factor) |
frame-place | string | — | Guest-box alignment in the slot (e.g. "left top") |
frame-shadow | "none" | "sm" | "md" | "lg" | — | Silhouette drop-shadow strength for the framed media |
inset
Internal padding override.
| Attribute | Type | Required | Description |
|---|---|---|---|
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.
| Attribute | Type | Required | Description |
|---|---|---|---|
reveal | "none" | "fade" | "slide" | "scale" | "blur" | — | Scroll-reveal entrance character (none|fade|slide|scale|blur); the theme owns the choreography |
stagger | boolean | — | Cascade this block's items in as it reveals (no-op on single-child runes) |
prominence
Header emphasis. Scales a rune's header, or its featured quotation; the theme decides the type size for each step.
| Attribute | Type | Required | Description |
|---|---|---|---|
prominence | "quiet" | "normal" | "prominent" | "display" | "marquee" | — | Emphasis of a page-section header or a featured quotation (only on runes that have one) |
reading
Editorial register for body text. You pick the register; the theme decides how it looks.
| Attribute | Type | Required | Description |
|---|---|---|---|
reading | "fine" | "ui" | "prose" | — | Reading register for this block’s body: fine | ui | prose. The theme sets how each one looks. |
spacing
Block-level rhythm override.
| Attribute | Type | Required | Description |
|---|---|---|---|
spacing | "flush" | "tight" | "default" | "loose" | "breathe" | — | Vertical spacing above and below this block |
substrate
Generated pattern fills behind the content, drawn by the theme.
| Attribute | Type | Required | Description |
|---|---|---|---|
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.
| Attribute | Type | Required | Description |
|---|---|---|---|
tint | string | — | 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.
| Attribute | Type | Required | Description |
|---|---|---|---|
width | "compact" | "narrow" | "content" | "wide" | "full" | — | Maximum width constraint for this block |
realm-section
| Attribute | Type | Required | Description |
|---|---|---|---|
name | string | ✓ |
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.
| Attribute | Type | Required | Description |
|---|---|---|---|
bg | string | — | Background preset applied to this block |
bg-from | string | — | 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-to | string | — | Gradient end colour — a semantic token name |
bg-via | string | — | 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) |
dropcap
Per-instance drop-cap opt-in.
| Attribute | Type | Required | Description |
|---|---|---|---|
dropcap | boolean | — | Style the opening letter of a prose body as a drop cap. Honoured only when the body reads as prose; ignored otherwise. |
elevation
How far the rune sits off the page, from sunken to overlay. The theme decides what each step looks like.
| Attribute | Type | Required | Description |
|---|---|---|---|
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.
| Attribute | Type | Required | Description |
|---|---|---|---|
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.
| Attribute | Type | Required | Description |
|---|---|---|---|
reveal | "none" | "fade" | "slide" | "scale" | "blur" | — | Scroll-reveal entrance character (none|fade|slide|scale|blur); the theme owns the choreography |
stagger | boolean | — | Cascade this block's items in as it reveals (no-op on single-child runes) |
reading
Editorial register for body text. You pick the register; the theme decides how it looks.
| Attribute | Type | Required | Description |
|---|---|---|---|
reading | "fine" | "ui" | "prose" | — | Reading register for this block’s body: fine | ui | prose. The theme sets how each one looks. |
spacing
Block-level rhythm override.
| Attribute | Type | Required | Description |
|---|---|---|---|
spacing | "flush" | "tight" | "default" | "loose" | "breathe" | — | Vertical spacing above and below this block |
substrate
Generated pattern fills behind the content, drawn by the theme.
| Attribute | Type | Required | Description |
|---|---|---|---|
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.
| Attribute | Type | Required | Description |
|---|---|---|---|
tint | string | — | 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.
| Attribute | Type | Required | Description |
|---|---|---|---|
width | "compact" | "narrow" | "content" | "wide" | "full" | — | Maximum width constraint for this block |
| Not available | Why |
|---|---|
| frame | this rune declares neither a `frameTarget` nor a media section |
| prominence | this rune has no page-section header or featured quotation |