LearnOS docs
Authoring

Interactive blocks

Reference for data-only fences that render as interactive lesson widgets

Interactive blocks

Lessons can include interactive widgets through fenced code blocks and callout blockquotes. All blocks are data-only: you write JSON or markdown, and LearnOS owns the markup and behavior. This keeps lesson content portable and secure — no raw HTML, no script injection.

BlockSyntaxWhat it renders
Generative UI```uiCheckpoint questions, worked examples, choice reveals, re-explain cards, citation chips
Quiz```quizA graded knowledge check; misses go to the learner's review deck
Chart```chartBar, stacked-bar, line, area, or donut chart with a data table
Callouts> [!TYPE]Note, tip, definition, important, takeaway, warning, caution, commands, and data callouts; aside types can fold
Mermaid```mermaidFlowcharts, sequence diagrams, and other Mermaid diagrams
Runnable code```js-run ```ts-run ```py-runAn editable snippet with a Run button and output pane

Where a block renders depends on the surface:

Surfaceui, quiz, chartCalloutsMermaid, runnable code
Lessons, review guide sections, presentation slides, citation-rail previews✓✓✓
Chat answers (including review chat and review model answers)plain code blockplain blockquote✓
Blog postsplain code blockplain blockquote✓

The Preview panes on this page are the one docs exception. They run the lesson renderer so you can see each block as learners do. Other docs pages show fences as code.

The examples below share one running scenario, a lesson on web sessions and HTTP, so you can see how the blocks work together. Each one opens on Preview, which is the real lesson renderer, so you can click through quizzes, tabs, and runnable code. Switch to Code for the markdown to paste into a lesson.

Security model

Authors emit JSON; LearnOS owns markup. Every spec passes through a strict Zod schema before rendering. Invalid or unknown specs render nothing (with a dev-only console error).

  • ui, quiz, and chart blocks reject any text field that contains an HTML tag at parse time (the same rule as generative UI).
  • Quiz prompts and options also allow inline `code`. The check treats any < followed by a letter, /, or ! as a tag, even inside inline code, so `<p>`, `Promise<void>`, and a<b are rejected. Comparisons with a space or a digit after the <, like a < b or 2<3, are fine. To quiz on HTML or generics, name the element in words ("the paragraph element") or write Promise of void.

Generative UI components

Generative UI blocks use the ```ui fence. Each one names a component and carries 1–8 citations that ground it in course content (see Common fields). Citation chips that point back to the lesson the learner is already reading are hidden.

checkpoint-question

An inline comprehension check with confidence calibration. Renders radio options and a confidence slider. After Check, it marks the learner's pick, reveals the correct answer, and shows the explanation alongside the confidence they reported.

Loading preview…
PropTypeRequiredDescription
idslugyesStable identifier for this question
titlestringyesCard header (max 120 chars)
promptstringyesThe question (max 600 chars)
optionsarrayyes2-6 answer choices, each with text
correct_indexintyes0-based index of the correct option
explanationstringyesShown after checking (max 1200 chars)
initial_confidenceintnoDefault confidence % (0-100, default 50)

worked-example

A step-by-step walkthrough with prev/next navigation. Shows one step at a time, with dots that jump to any step. On the last step, Next is disabled and the optional why_it_matters panel appears.

Loading preview…
PropTypeRequiredDescription
titlestringyesCard header (max 120 chars)
stepsarrayyes2-12 steps, each with title and body
steps[].titlestringyesStep title (max 120 chars)
steps[].bodystringyesStep content (max 2000 chars)
why_it_mattersstringnoSummary shown on the last step (max 600 chars)

choice-reveal

A tabbed interface where tapping an option reveals its panel, and tapping it again collapses it. Arrow keys, Home, and End move between tabs. Good for comparisons or "choose your path" scenarios.

Loading preview…
PropTypeRequiredDescription
optionsarrayyes2-6 options, each with label, title, body
options[].labelstringyesTab button text (max 80 chars)
options[].titlestringyesPanel heading (max 120 chars)
options[].bodystringyesPanel content (max 2000 chars)
default_indexintno0-based index of initially revealed option

re-explain-card

Shows an alternative explanation when a learner struggles with a concept. The header names the persona and format it is tuned for, and the card quotes the learner's answer next to the misconception it addresses. Still unclear and Got it, retry let the learner respond.

Loading preview…
PropTypeRequiredDescription
titlestringyesCard header (max 120 chars)
personastringyesTarget learner type (max 80 chars)
formatenumyesanalogy, plain-language, or worked-example
explanationstringyesThe alternative explanation (max 4000 chars)
previous_answerstringyesWhat the learner said (max 600 chars)
misconceptionstringyesShort label for the misconception (max 160 chars)

citation-chip

A standalone inline citation. Clicking the chip opens a popover with the section title, the cited excerpt, the anchor, and an Open section link. Every component above renders the same chip for each of its citations; use this component to place one on its own.

Loading preview…
PropTypeRequiredDescription
citation_idslugyesThe id of one of this spec's citations

Common fields

All generative UI components share these top-level fields:

FieldTypeRequiredDescription
spec_versionliteral 1yesSchema version (always 1 for now)
componentstringyesComponent name from the registry
citationsarrayyes1-8 source citations for grounding

Each citation object:

FieldTypeRequiredDescription
idslugyesUnique within this spec (used by citation_id)
lesson_iduuidyesThe lesson containing the source
anchorslugyesHeading anchor within the lesson
labelstringyesDisplay label like L3#tools-call
titlestringyesHeading text (max 200 chars)
excerptstringyesQuoted source text (max 2000 chars)

Citation title and excerpt are author-attested: the schema checks length and rejects HTML, but does not verify that the excerpt matches the live lesson section. Grounding is enforced by author review (and by adaptive flows that resolve chunks server-side when they exist).

Core blocks

Quiz

A graded knowledge check. A question with one correct option renders as single choice; a question with more than one correct option becomes multi-select ("select all that apply"). After Check answer, each picked option shows its why, and the question's explanation appears below. When a signed-in learner misses a question, it is saved to their review deck as a flashcard. The card is rebuilt from the stored lesson, never from what the browser sends.

Loading preview…
FieldTypeRequiredDescription
idslugyesStable per-lesson id: lowercase letters, digits, and hyphens, starting with a letter or digit (2-61 chars). Keep it unchanged after publishing; review-deck cards point at it
titlestringnoCard header (max 80 chars). Hidden when it repeats the heading just above the quiz
questionsarrayyes1-5 questions
questions[].promptstringyesThe question (max 400 chars). Inline `code` is allowed
questions[].optionsarrayyes2-6 options; at least one must be correct
options[].textstringyesOption text (max 200 chars)
options[].correctbooleannoDefaults to false
options[].whystringnoShown under the option after checking (max 300 chars)
questions[].explanationstringnoShown after checking (max 600 chars)

Chart

A data chart with a View data toggle that shows the numbers as a table. Colors come from a fixed five-slot palette that is safe for color-vision deficiencies. You cannot set colors, and series keys never reach the page's CSS.

Loading preview…
FieldTypeRequiredDescription
typeenumyesbar, stacked-bar, line, area, or donut
titlestringyesFigure caption (max 80 chars)
xstringyesKey of the category field in each data row (1-40 chars; slice name for donut)
seriesarrayyes1-5 series, each with key (1-40 chars) and label. A donut takes exactly one
dataarrayyes1-60 rows. Each value is a number or null; a donut has at most 5 slices
formatenumnonumber (default), usd, usd-compact, or percent (values already 0-100)
yLabelstringnoY-axis label for cartesian charts (max 60 chars)
captionstringnoNote under the chart (max 300 chars)

Put a markdown table with the same numbers next to the chart, as in the example above. Chat and search read lesson text, not chart JSON, so without the table the tutor can't quote the figures. pnpm validate-blocks warns when a chart has no table nearby.

Callouts

Callouts are blockquotes with a GitHub-style marker. The text after the marker on the first line becomes an optional title. NOTE through CAUTION also render as alerts on GitHub; DEFINITION, TAKEAWAY and COMMANDS are LearnOS additions.

Loading preview…

The eight types share three visual styles:

StyleTypesLabelUse it for
AsideNOTE, TIP, DEFINITION, COMMANDSNote, Tip, Definition, Show the commandsSupporting detail the reader can skip
EmphasisIMPORTANT, TAKEAWAYImportant, Key takeawayThe points the lesson is about
AlertWARNING, CAUTIONWatch out, CautionMistakes with real consequences

Two data callouts use an emoji lead-in instead of a marker. Start the blockquote with 📌 for a snapshot of real figures, or 📊 for a slot telling the learner what to look up:

Loading preview…

Only put verified figures with a source in a 📌 snapshot.

Foldable callouts

Put - right after the marker to render a callout closed, with its label as the toggle, or + to render it open but collapsible. Only the aside types fold: NOTE, TIP, DEFINITION and COMMANDS. A fold marker on IMPORTANT, TAKEAWAY, WARNING or CAUTION is ignored, so those always render open, and validate-blocks warns about it. The COMMANDS type exists for this: lead with the plain-language instruction or agent prompt, and tuck the exact commands underneath for readers who want them.

Loading preview…

Without a title, a COMMANDS callout is labelled "Show the commands". Every line of the callout, including code fences, starts with > . Folded text is still part of the lesson, so search, chat and quizzes can use it; don't fold anything the reader must see to follow the lesson.

Mermaid

Any Mermaid diagram: flowcharts, sequence, class, and state diagrams. It renders client-side in Mermaid's default theme (its dark theme in dark mode). Clicking the diagram opens it full screen.

Loading preview…

Quote labels that contain parentheses or other Mermaid syntax, as with node B above. A diagram that fails to parse shows "Mermaid diagram failed to render" and its source in place of the diagram.

Runnable code

A ```js-run, ```ts-run, or ```py-run fence becomes an editable snippet with Run, Stop, and Reset controls. Output appears in a pane below the editor. Each run is stopped after 5 seconds, so an infinite loop can't freeze the lesson.

In js-run and ts-run, the snippet runs inside an async function: top-level await works, and a top-level return value is shown after a ⟶.

[!WARNING] ts-run is not transpiled. It runs as plain JavaScript, so TypeScript-only syntax such as type annotations (const n: number = 1) or interface declarations fails with a syntax error. Keep ts-run snippets to JavaScript-compatible code, or use js-run. Objects and arrays are logged as indented JSON. In py-run, output comes from print(), and Python loads its runtime the first time a learner runs a snippet.

Loading preview…

Running this logs the flags array, then shows ⟶ true.

Validation rules

  • ui, quiz, and chart text fields reject HTML tags (<script>, <img>, etc.) at parse time
  • Citation IDs must be unique within a spec
  • citation_id in citation-chip must reference an existing citation
  • correct_index / default_index must be valid array indices
  • Every quiz question needs at least one correct option
  • Every chart row needs the x field (a string or number); series values must be numbers or null
  • Quiz id must be lowercase letters, digits, and hyphens, starting with a letter or digit
  • Steps/options arrays have min and max bounds (see individual components)

Invalid specs render nothing in production; in development, an error is logged to the console with the failing paths.

Check every block in a folder of lessons before importing it. The checker uses the renderer's own schemas:

pnpm validate-blocks <dir>

On this page

Command Palette

Search for a command to run...