Storytelling›Faction

storytelling

Faction

Organizations and groups with ranks, holdings, and alignment

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 factionSectionSections = { body: 'body' } as const;

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

export const factionSections = {
	preamble: 'preamble',
	name: 'title',
	scene: 'media',
	body: 'body',
} as const;
export const factionMediaSlots = { scene: 'cover' } as const;

export const factionSchema = {
	type: 'Organization',
	properties: { name: 'name', sceneImage: 'image' },
} as const;

export const faction = createContentModelSchema({
	registers: {
		entity: { idFrom: 'name', data: ['factionType', 'alignment', 'size', 'tags', 'name'] },
	},
	schema: factionSchema,
	sections: factionSections,
	provides: ['prose'],
	mediaSlots: factionMediaSlots,
	base: SplitLayoutModel,
	attributes: {
		name: {
			type: String,
			required: true,
			description: 'Display name shown in the faction header.',
		},
		type: {
			type: String,
			required: false,
			description: 'Classification of the group (e.g. guild, kingdom, cult, order).',
		},
		alignment: {
			type: String,
			required: false,
			description: 'Moral or political stance of the faction (e.g. lawful, chaotic, neutral).',
		},
		size: {
			type: String,
			required: false,
			description: 'Approximate scale of the faction (e.g. small, medium, large, massive).',
		},
		tags: {
			type: String,
			required: false,
			description: 'Comma-separated keywords for filtering and cross-referencing.',
		},
	},
	contentModel: () => ({
		type: 'sections' as const,
		sectionHeading: 'heading',
		emitTag: 'faction-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 factionTypeMeta = new Tag('meta', { content: attrs.type ?? '' });
		const alignmentMeta = new Tag('meta', { content: attrs.alignment ?? '' });
		const sizeMeta = new Tag('meta', { content: attrs.size ?? '' });
		const tagsMeta = new Tag('meta', { content: attrs.tags ?? '' });

		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,
			'FactionSection',
			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: 'faction',
			tag: 'article',
			properties: {
				factionType: factionTypeMeta,
				alignment: alignmentMeta,
				size: sizeMeta,
				tags: tagsMeta,
				'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/faction.ts on GitHub

Organizations, guilds, orders, and groups for worldbuilding. For a single person, use character; for a place, realm.

Basic usage

Describe a faction with sections that break down its structure.

{% faction name="The Silver Order" type="knightly order" alignment="lawful" size="large" media-position="start" %}
![Knights of the Silver Order in formation](https://assets.refrakt.md/faction-the-silver-order.png)

Knights sworn to hold the Eastern March for three centuries.

## Ranks

- Initiate
- Knight
- Commander
- Grand Master

## Holdings

Their fortress overlooks Thornwall from the northern cliffs.
{% /faction %}
<article data-rune="faction" data-rune-fields="{&quot;factionType&quot;:&quot;knightly order&quot;,&quot;alignment&quot;:&quot;lawful&quot;,&quot;size&quot;:&quot;large&quot;,&quot;tags&quot;:&quot;&quot;,&quot;media-position&quot;:&quot;start&quot;}" typeof="Organization">
  <div data-name="scene">
    <img src="https://assets.refrakt.md/faction-the-silver-order.png" alt="Knights of the Silver Order in formation" data-name="sceneImage" property="image">
  </div>
  <span data-name="name" property="name">The Silver Order</span>
  <div data-name="body">
    <p>Knights sworn to hold the Eastern March for three centuries.</p>
  </div>
  <div data-name="sections">
    <div data-rune="faction-section" data-field="section">
      <span data-name="name">Ranks</span>
      <div data-name="body">
        <ul>
          <li>Initiate</li>
          <li>Knight</li>
          <li>Commander</li>
          <li>Grand Master</li>
        </ul>
      </div>
    </div>
    <div data-rune="faction-section" data-field="section">
      <span data-name="name">Holdings</span>
      <div data-name="body">
        <p>Their fortress overlooks Thornwall from the northern cliffs.</p>
      </div>
    </div>
  </div>
</article>
Knights of the Silver Order in formation
The Silver Order

Knights sworn to hold the Eastern March for three centuries.

Ranks
  • Initiate
  • Knight
  • Commander
  • Grand Master
Holdings

Their fortress overlooks Thornwall from the northern cliffs.

<article class="rf-faction rf-faction--knightly order rf-faction--lawful rf-faction--large" typeof="Organization" data-faction-type="knightly order" data-alignment="lawful" data-size="large" data-tags="" data-media-position="start" data-elevation="flat" data-rune="faction" data-density="full">
  <div data-name="scene" class="rf-faction__scene" data-section="media" data-media="cover" data-guest-fit="clip">
    <img src="https://assets.refrakt.md/faction-the-silver-order.png" alt="Knights of the Silver Order in formation" data-name="sceneImage" property="image" class="rf-faction__sceneImage" />
  </div>
  <div data-name="content" class="rf-faction__content">
    <header data-name="preamble" class="rf-faction__preamble" data-section="preamble">
      <span data-name="name" property="name" class="rf-faction__name" data-section="title">The Silver Order</span>
    </header>
    <dl data-name="metadata" data-zone="metadata" data-zone-layout="definition-list" class="rf-faction__metadata">
      <div data-name="row" data-field="factionType" class="rf-faction__row">
        <dt data-meta-label="">Type</dt>
        <dd>
          <span data-meta-type="category">knightly order</span>
        </dd>
      </div>
      <div data-name="row" data-field="alignment" class="rf-faction__row">
        <dt data-meta-label="">Alignment</dt>
        <dd>
          <span data-meta-type="category" data-meta-sentiment="neutral">lawful</span>
        </dd>
      </div>
      <div data-name="row" data-field="size" class="rf-faction__row">
        <dt data-meta-label="">Size</dt>
        <dd>
          <span data-meta-type="quantity">large</span>
        </dd>
      </div>
    </dl>
    <div data-name="body" class="rf-faction__body" data-section="body">
      <p>Knights sworn to hold the Eastern March for three centuries.</p>
    </div>
    <div data-name="sections" class="rf-faction__sections">
      <div class="rf-faction-section" data-field="section" data-rune="faction-section" data-density="full">
        <span data-name="name" class="rf-faction-section__name">Ranks</span>
        <div data-name="body" class="rf-faction-section__body" data-section="body">
          <ul>
            <li>Initiate</li>
            <li>Knight</li>
            <li>Commander</li>
            <li>Grand Master</li>
          </ul>
        </div>
      </div>
      <div class="rf-faction-section" data-field="section" data-rune="faction-section" data-density="full">
        <span data-name="name" class="rf-faction-section__name">Holdings</span>
        <div data-name="body" class="rf-faction-section__body" data-section="body">
          <p>Their fortress overlooks Thornwall from the northern cliffs.</p>
        </div>
      </div>
    </div>
  </div>
</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

Classify a faction

type, alignment and size are free text shown in the faction's header: a thieves' guild might be type="thieves guild" alignment="chaotic" size="medium", a royal court type="kingdom" alignment="lawful" size="massive".

Place the scene

A faction'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 faction header.
typestring—Classification of the group (e.g. guild, kingdom, cult, order).
alignmentstring—Moral or political stance of the faction (e.g. lawful, chaotic, neutral).
sizestring—Approximate scale of the faction (e.g. small, medium, large, massive).
tagsstring—Comma-separated keywords for filtering and cross-referencing.

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

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