Learning›HowTo

learning

HowTo

Step-by-step how-to guide with tools and instructions

Install

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

About the plugin and its runes

Source

import Markdoc from '@markdoc/markdoc';
import type { RenderableTreeNode } from '@markdoc/markdoc';
const { Tag } = Markdoc;
import {
	createContentModelSchema,
	createComponentRenderable,
	asNodes,
	renderNodes,
	RenderableNodeCursor,
	pageSectionProperties,
	unwrapParagraphImages,
} from '@refrakt-md/runes';

const difficultyType = ['easy', 'medium', 'hard'] as const;

const bodyFields = [
	{ name: 'header', match: 'heading|paragraph|image' as const, greedy: true, optional: true },
	{ name: 'body', match: 'list|tag' as const, greedy: true, optional: true },
];

export const howToSections = {
	preamble: 'preamble',
	headline: 'title',
	blurb: 'description',
} as const;

export const howToSchema = {
	type: 'HowTo',
	properties: { headline: 'name', blurb: 'description', estimatedTime: 'totalTime' },
	children: {
		tool: { type: 'HowToTool', property: 'tool', text: { tool: 'name' }, textTag: 'p' },
		step: { type: 'HowToStep', property: 'step', text: { step: 'text' }, textTag: 'p' },
	},
} as const;

export const howto = createContentModelSchema({
	schema: howToSchema,
	sections: howToSections,
	attributes: {
		estimatedTime: {
			type: String,
			required: false,
			default: '',
			description: 'Estimated total time to complete all steps (e.g. "30 min")',
		},
		difficulty: {
			type: String,
			required: false,
			matches: difficultyType.slice(),
			description: 'Skill level: easy, medium, or hard',
		},
	},
	contentModel: {
		type: 'sequence',
		fields: bodyFields,
	},
	transform(resolved, attrs, config) {
		const header = new RenderableNodeCursor(
			unwrapParagraphImages(
				Markdoc.transform(asNodes(resolved.header), config) as RenderableTreeNode[],
			),
		);
		const body = renderNodes(resolved.body, config);

		const estimatedTimeMeta = new Tag('meta', { content: attrs.estimatedTime });
		const difficultyMeta = new Tag('meta', { content: attrs.difficulty ?? '' });

		const allNodes = body.toArray();
		const tools: any[] = [];
		const steps: any[] = [];

		for (const node of allNodes) {
			if (Markdoc.Tag.isTag(node)) {
				if (node.name === 'ul') {
					tools.push(...(node.children || []));
				} else if (node.name === 'ol') {
					steps.push(...(node.children || []));
				}
			}
		}

		for (const li of tools) {
			if (Markdoc.Tag.isTag(li)) li.attributes['data-name'] = 'tool';
		}
		for (const li of steps) {
			if (Markdoc.Tag.isTag(li)) li.attributes['data-name'] = 'step';
		}

		const sectionProps = pageSectionProperties(header);
		const toolsList = new Tag('ul', {}, tools);
		const stepsList = new Tag('ol', {}, steps);

		const children: any[] = [
			...header.toArray(),
			...(tools.length > 0 ? [toolsList] : []),
			stepsList,
		];

		return createComponentRenderable({
			rune: 'how-to',
			tag: 'article',
			properties: {
				estimatedTime: estimatedTimeMeta,
				difficulty: difficultyMeta,
			},
			refs: {
				...sectionProps,
				tools: toolsList,
				steps: stepsList,
			},
			children,
		});
	},
});

View plugins/learning/src/tags/howto.ts on GitHub

Instructions for a task: what it needs, and the steps to follow, published as structured data.

Basic usage

A how-to guide with required tools and numbered steps.

{% howto estimatedTime="PT1H" difficulty="medium" %}
# How to Set Up a Development Environment

Get a local development environment running from scratch.

- Node.js 18+
- Git
- A code editor (VS Code recommended)

1. Install Node.js from the official website
2. Clone the repository with `git clone`
3. Run `npm install` to install dependencies
4. Start the dev server with `npm run dev`
{% /howto %}
<article data-rune="how-to" data-rune-fields="{&quot;estimatedTime&quot;:&quot;PT1H&quot;,&quot;difficulty&quot;:&quot;medium&quot;}" typeof="HowTo">
  <h1 id="how-to-set-up-a-development-environment" data-name="headline" property="name">How to Set Up a Development Environment</h1>
  <p data-name="blurb" property="description">Get a local development environment running from scratch.</p>
  <ul data-name="tools">
    <li data-name="tool" typeof="HowToTool" property="tool">
      <p property="name">Node.js 18+</p>
    </li>
    <li data-name="tool" typeof="HowToTool" property="tool">
      <p property="name">Git</p>
    </li>
    <li data-name="tool" typeof="HowToTool" property="tool">
      <p property="name">A code editor (VS Code recommended)</p>
    </li>
  </ul>
  <ol data-name="steps">
    <li data-name="step" typeof="HowToStep" property="step">
      <p property="text">Install Node.js from the official website</p>
    </li>
    <li data-name="step" typeof="HowToStep" property="step">
      <p property="text">
        Clone the repository with
        <code>git clone</code>
      </p>
    </li>
    <li data-name="step" typeof="HowToStep" property="step">
      <p property="text">
        Run
        <code>npm install</code>
        to install dependencies
      </p>
    </li>
    <li data-name="step" typeof="HowToStep" property="step">
      <p property="text">
        Start the dev server with
        <code>npm run dev</code>
      </p>
    </li>
  </ol>
  <meta property="totalTime" content="PT1H">
</article>

How to Set Up a Development Environment

Get a local development environment running from scratch.

  • Node.js 18+

  • Git

  • A code editor (VS Code recommended)

  1. 1

    Install Node.js from the official website

  2. 2

    Clone the repository with git clone

  3. 3

    Run npm install to install dependencies

  4. 4

    Start the dev server with npm run dev

<article class="rf-howto rf-howto--PT1H rf-howto--medium" typeof="HowTo" data-estimated-time="PT1H" data-difficulty="medium" data-elevation="flat" data-rune="how-to" data-density="full">
  <div data-name="content" class="rf-howto__content">
    <header data-name="preamble" class="rf-howto__preamble" data-section="preamble">
      <h1 id="how-to-set-up-a-development-environment" data-name="headline" property="name" class="rf-howto__headline" data-section="title">How to Set Up a Development Environment</h1>
      <p data-name="blurb" property="description" class="rf-howto__blurb" data-section="description">Get a local development environment running from scratch.</p>
    </header>
    <dl data-name="metadata" data-zone="metadata" data-zone-layout="definition-list" class="rf-howto__metadata">
      <div data-name="row" data-field="estimatedTime" class="rf-howto__row">
        <dt data-meta-label="">Est. time</dt>
        <dd>
          <span data-meta-type="temporal">1h</span>
        </dd>
      </div>
      <div data-name="row" data-field="difficulty" class="rf-howto__row">
        <dt data-meta-label="">Difficulty</dt>
        <dd>
          <span data-meta-type="category">medium</span>
        </dd>
      </div>
    </dl>
    <ul data-name="tools" class="rf-howto__tools">
      <li data-name="tool" typeof="HowToTool" property="tool" class="rf-howto__tool">
        <p property="name">Node.js 18+</p>
      </li>
      <li data-name="tool" typeof="HowToTool" property="tool" class="rf-howto__tool">
        <p property="name">Git</p>
      </li>
      <li data-name="tool" typeof="HowToTool" property="tool" class="rf-howto__tool">
        <p property="name">A code editor (VS Code recommended)</p>
      </li>
    </ul>
    <ol data-name="steps" data-sequence="numbered" class="rf-howto__steps">
      <li data-name="step" typeof="HowToStep" property="step" class="rf-howto__step">
        <span data-name="ordinal" data-meta-type="quantity" class="rf-howto__ordinal">1</span>
        <p property="text">Install Node.js from the official website</p>
      </li>
      <li data-name="step" typeof="HowToStep" property="step" class="rf-howto__step">
        <span data-name="ordinal" data-meta-type="quantity" class="rf-howto__ordinal">2</span>
        <p property="text">
          Clone the repository with 
          <code>git clone</code>
        </p>
      </li>
      <li data-name="step" typeof="HowToStep" property="step" class="rf-howto__step">
        <span data-name="ordinal" data-meta-type="quantity" class="rf-howto__ordinal">3</span>
        <p property="text">
          Run 
          <code>npm install</code>
           to install dependencies
        </p>
      </li>
      <li data-name="step" typeof="HowToStep" property="step" class="rf-howto__step">
        <span data-name="ordinal" data-meta-type="quantity" class="rf-howto__ordinal">4</span>
        <p property="text">
          Start the dev server with 
          <code>npm run dev</code>
        </p>
      </li>
    </ol>
  </div>
  <meta property="totalTime" content="PT1H" />
</article>

How Markdown is read

You writeIt becomes
A short paragraph, then a heading and a paragraph, before the listsThe eyebrow, headline and blurb (Page sections)
A bulleted listThe tools and materials needed
A numbered listThe steps

Attributes

AttributeTypeRequiredDescription
estimatedTimestring—Estimated total time to complete all steps (e.g. "30 min")
difficulty"easy" | "medium" | "hard"—Skill level: easy, medium, or hard

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