Storytelling›Realm

storytelling

Realm

Location profiles for worldbuilding with geography and notable features

Install

  1. Add the package: npm install @refrakt-md/storytelling
  2. Add it to the plugins array in refrakt.config.json: "plugins": ["@refrakt-md/storytelling"]

About the plugin and its runes

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,
		});
	},
});

View plugins/storytelling/src/tags/realm.ts on GitHub

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 terraced halls of Hollowmere above a river gorge](https://assets.refrakt.md/realm-rivendell.png)

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="{&quot;realmType&quot;:&quot;sanctuary&quot;,&quot;scale&quot;:&quot;settlement&quot;,&quot;tags&quot;:&quot;&quot;,&quot;parent&quot;:&quot;&quot;,&quot;media-position&quot;:&quot;start&quot;}" 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 terraced halls of Hollowmere above a river gorge
Hollowmere

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
<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 writeIt becomes
An image before everything elseThe scene illustration (Place the scene)
Paragraphs before the first headingThe description
A headingA 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" %}
![Flooded stone tunnels lit by a single lantern](https://assets.refrakt.md/realm-the-undercroft.png)

## 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="{&quot;realmType&quot;:&quot;dungeon&quot;,&quot;scale&quot;:&quot;district&quot;,&quot;tags&quot;:&quot;&quot;,&quot;parent&quot;:&quot;Thornwall&quot;,&quot;media-position&quot;:&quot;start&quot;}" 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>
Flooded stone tunnels lit by a single lantern
The Undercroft
Overview

A sprawling network of tunnels beneath Thornwall, home to the Whispering Hand and worse.

Dangers
  • 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

AttributeTypeRequiredDescription
namestring✓Display name shown in the realm header.
typestring—Kind of location (e.g. city, forest, dungeon, plane, continent).
scalestring—Geographic scope of the realm (e.g. room, district, region, world).
tagsstring—Comma-separated keywords for filtering and cross-referencing.
parentstring—Name of the containing realm for hierarchical nesting.

Inherited from the split layout preset

AttributeTypeRequiredDescription
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.

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)
dropcap

Per-instance drop-cap opt-in.

AttributeTypeRequiredDescription
dropcapboolean—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.

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)
frame

Surface chrome: a named preset from the theme registry with inline `frame-*` overrides layered on top.

AttributeTypeRequiredDescription
framestring—Named frame preset presenting this block's media surface
frame-anchorstring—Crop focal point when the guest is cut (object-position)
frame-aspectstring—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-oversizestring—How far the guest exceeds its slot (scale factor)
frame-placestring—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.

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)
prominence

Header emphasis. Scales a rune's header, or its featured quotation; the theme decides the type size for each step.

AttributeTypeRequiredDescription
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.

AttributeTypeRequiredDescription
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.

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

realm-section

AttributeTypeRequiredDescription
namestring✓

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)
dropcap

Per-instance drop-cap opt-in.

AttributeTypeRequiredDescription
dropcapboolean—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.

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)
reading

Editorial register for body text. You pick the register; the theme decides how it looks.

AttributeTypeRequiredDescription
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.

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
framethis rune declares neither a `frameTarget` nor a media section
prominencethis rune has no page-section header or featured quotation