Storytelling›Character

storytelling

Character

Rich character profiles with sections for backstory, abilities, and more

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,
} from '@refrakt-md/runes';
import { taxonomyAttributes, buildStoryContent } from './common.js';

export const characterSectionSections = { body: 'body' } as const;

export const characterSection = createContentModelSchema({
	sections: characterSectionSections,
	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: 'character-section',
			tag: 'div',
			refs: { name: nameTag, body: body.tag('div') },
			children: [nameTag, body.next()],
		});
	},
});

const roleType = ['protagonist', 'antagonist', 'supporting', 'minor'] as const;
const statusType = ['alive', 'dead', 'unknown', 'missing'] as const;

export const characterSections = {
	preamble: 'preamble',
	name: 'title',
	portrait: 'media',
	body: 'body',
} as const;
export const characterMediaSlots = { portrait: 'portrait' } as const;

export const characterSchema = {
	type: 'Person',
	properties: { name: 'name', role: 'jobTitle' },
} as const;

export const character = createContentModelSchema({
	registers: {
		entity: {
			idFrom: 'name',
			data: ['role', 'status', 'aliases', 'tags', 'name'],
			aliases: { from: 'aliases', separator: ',' },
		},
	},
	schema: characterSchema,
	sections: characterSections,
	provides: ['prose'],
	mediaSlots: characterMediaSlots,
	base: taxonomyAttributes,
	attributes: {
		name: {
			type: String,
			required: true,
			description: 'Display name shown in the character header.',
		},
		role: {
			type: String,
			required: false,
			matches: roleType.slice(),
			description: 'Narrative importance: protagonist, antagonist, supporting, or minor.',
		},
		status: {
			type: String,
			required: false,
			matches: statusType.slice(),
			description: 'Whether the character is alive, dead, unknown, or missing.',
		},
		aliases: {
			type: String,
			required: false,
			description: 'Comma-separated alternate names or titles for this character.',
		},
	},
	contentModel: () => ({
		type: 'sections' as const,
		sectionHeading: 'heading',
		emitTag: 'character-section',
		emitAttributes: { name: '$heading' },
		fields: [
			{ name: 'portrait', match: 'image', 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 roleMeta = new Tag('meta', { content: attrs.role ?? 'supporting' });
		const statusMeta = new Tag('meta', { content: attrs.status ?? 'alive' });
		const aliasesMeta = new Tag('meta', { content: attrs.aliases ?? '' });
		const tagsMeta = new Tag('meta', { content: attrs.tags ?? '' });

		const portraitNodes = renderNodes(resolved.portrait, config);
		const portrait = portraitNodes.tag('img').limit(1);
		const hasPortrait = portrait.count() > 0;
		const portraitDiv = hasPortrait ? portrait.wrap('div') : undefined;

		const { bodyDiv, sectionsContainer, sections, hasSections } = buildStoryContent(
			[],
			resolved.description,
			sectionNodes,
			'CharacterSection',
			config,
		);

		const children: any[] = [];
		if (portraitDiv) children.push(portraitDiv.next());
		children.push(nameTag);
		if (bodyDiv) children.push(bodyDiv.next());
		if (sectionsContainer) children.push(sectionsContainer.next());

		return createComponentRenderable({
			rune: 'character',
			tag: 'article',
			properties: {
				role: roleMeta,
				status: statusMeta,
				aliases: aliasesMeta,
				tags: tagsMeta,
				...(hasSections ? { section: sections } : {}),
			},
			refs: {
				name: nameTag,
				portrait: portraitDiv,
				body: bodyDiv,
				sections: sectionsContainer,
			},
			children,
		});
	},
});

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

Character profiles for worldbuilding and storytelling. For a place, use realm; for an order, guild or other group, faction.

Basic usage

{% character name="Veshra" role="antagonist" status="alive" aliases="The Bone Witch" tags="magic-user" %}
## Backstory

Raised in the shadow of the Ashen Spire, Veshra discovered her gift for necromancy at a young age.

## Abilities

- Bone conjuration
- Spirit binding
- Plague whisper
{% /character %}
<article data-rune="character" data-rune-fields="{&quot;role&quot;:&quot;antagonist&quot;,&quot;status&quot;:&quot;alive&quot;,&quot;aliases&quot;:&quot;The Bone Witch&quot;,&quot;tags&quot;:&quot;magic-user&quot;}" typeof="Person">
  <span data-name="name" property="name">Veshra</span>
  <div data-name="sections">
    <div data-rune="character-section" data-field="section">
      <span data-name="name">Backstory</span>
      <div data-name="body">
        <p>Raised in the shadow of the Ashen Spire, Veshra discovered her gift for necromancy at a young age.</p>
      </div>
    </div>
    <div data-rune="character-section" data-field="section">
      <span data-name="name">Abilities</span>
      <div data-name="body">
        <ul>
          <li>Bone conjuration</li>
          <li>Spirit binding</li>
          <li>Plague whisper</li>
        </ul>
      </div>
    </div>
  </div>
  <meta property="jobTitle" content="antagonist">
</article>
Veshra
Backstory

Raised in the shadow of the Ashen Spire, Veshra discovered her gift for necromancy at a young age.

Abilities
  • Bone conjuration
  • Spirit binding
  • Plague whisper
<article class="rf-character rf-character--antagonist rf-character--alive rf-character--The Bone Witch rf-character--magic-user" typeof="Person" data-role="antagonist" data-status="alive" data-aliases="The Bone Witch" data-tags="magic-user" data-elevation="flat" data-rune="character" data-density="full">
  <div data-name="content" class="rf-character__content">
    <header data-name="preamble" class="rf-character__preamble" data-section="preamble">
      <span data-name="name" property="name" class="rf-character__name" data-section="title">Veshra</span>
    </header>
    <dl data-name="metadata" data-zone="metadata" data-zone-layout="definition-list" class="rf-character__metadata">
      <div data-name="row" data-field="role" class="rf-character__row">
        <dt data-meta-label="">Role</dt>
        <dd>
          <span data-meta-type="category">antagonist</span>
        </dd>
      </div>
      <div data-name="row" data-field="status" class="rf-character__row">
        <dt data-meta-label="">Status</dt>
        <dd>
          <span data-meta-type="status" data-meta-sentiment="positive">alive</span>
        </dd>
      </div>
    </dl>
    <div data-name="sections" class="rf-character__sections">
      <div class="rf-character-section" data-field="section" data-rune="character-section" data-density="full">
        <span data-name="name" class="rf-character-section__name">Backstory</span>
        <div data-name="body" class="rf-character-section__body" data-section="body">
          <p>Raised in the shadow of the Ashen Spire, Veshra discovered her gift for necromancy at a young age.</p>
        </div>
      </div>
      <div class="rf-character-section" data-field="section" data-rune="character-section" data-density="full">
        <span data-name="name" class="rf-character-section__name">Abilities</span>
        <div data-name="body" class="rf-character-section__body" data-section="body">
          <ul>
            <li>Bone conjuration</li>
            <li>Spirit binding</li>
            <li>Plague whisper</li>
          </ul>
        </div>
      </div>
    </div>
  </div>
  <meta property="jobTitle" content="antagonist" />
</article>

How Markdown is read

You writeIt becomes
An image before everything elseThe character's portrait
Paragraphs before the first headingThe description
A headingA named section; the content up to the next heading of that level is its body

Role and status

role sets how prominent a character is in the story — protagonist, antagonist, supporting or minor — and status records where they stand now: alive, dead, unknown or missing. Both change the profile's styling.

{% character name="Elena" role="protagonist" status="missing" %}
## Background

A scholar of the Ashen Spire, raised in Thornwall by its warden, Lord Ashford. Last seen taking the cliff road out of Hollowmere.
{% /character %}
<article data-rune="character" data-rune-fields="{&quot;role&quot;:&quot;protagonist&quot;,&quot;status&quot;:&quot;missing&quot;,&quot;aliases&quot;:&quot;&quot;,&quot;tags&quot;:&quot;&quot;}" typeof="Person">
  <span data-name="name" property="name">Elena</span>
  <div data-name="sections">
    <div data-rune="character-section" data-field="section">
      <span data-name="name">Background</span>
      <div data-name="body">
        <p>A scholar of the Ashen Spire, raised in Thornwall by its warden, Lord Ashford. Last seen taking the cliff road out of Hollowmere.</p>
      </div>
    </div>
  </div>
  <meta property="jobTitle" content="protagonist">
</article>
Elena
Background

A scholar of the Ashen Spire, raised in Thornwall by its warden, Lord Ashford. Last seen taking the cliff road out of Hollowmere.

<article class="rf-character rf-character--protagonist rf-character--missing" typeof="Person" data-role="protagonist" data-status="missing" data-aliases="" data-tags="" data-elevation="flat" data-rune="character" data-density="full">
  <div data-name="content" class="rf-character__content">
    <header data-name="preamble" class="rf-character__preamble" data-section="preamble">
      <span data-name="name" property="name" class="rf-character__name" data-section="title">Elena</span>
    </header>
    <dl data-name="metadata" data-zone="metadata" data-zone-layout="definition-list" class="rf-character__metadata">
      <div data-name="row" data-field="role" class="rf-character__row">
        <dt data-meta-label="">Role</dt>
        <dd>
          <span data-meta-type="category">protagonist</span>
        </dd>
      </div>
      <div data-name="row" data-field="status" class="rf-character__row">
        <dt data-meta-label="">Status</dt>
        <dd>
          <span data-meta-type="status" data-meta-sentiment="caution">missing</span>
        </dd>
      </div>
    </dl>
    <div data-name="sections" class="rf-character__sections">
      <div class="rf-character-section" data-field="section" data-rune="character-section" data-density="full">
        <span data-name="name" class="rf-character-section__name">Background</span>
        <div data-name="body" class="rf-character-section__body" data-section="body">
          <p>A scholar of the Ashen Spire, raised in Thornwall by its warden, Lord Ashford. Last seen taking the cliff road out of Hollowmere.</p>
        </div>
      </div>
    </div>
  </div>
  <meta property="jobTitle" content="protagonist" />
</article>

Attributes

AttributeTypeRequiredDescription
namestring✓Display name shown in the character header.
role"protagonist" | "antagonist" | "supporting" | "minor"—Narrative importance: protagonist, antagonist, supporting, or minor.
status"alive" | "dead" | "unknown" | "missing"—Whether the character is alive, dead, unknown, or missing.
aliasesstring—Comma-separated alternate names or titles for this character.

Inherited from the storytelling taxonomy preset

AttributeTypeRequiredDescription
tagsstring—Comma-separated keywords for filtering and cross-referencing.

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

character-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