Skip to content
Back to skills

Block Model

ASecurity

The block model cuts the Markdown (MDC) body of a page into blocks, edits the blocks, and writes the text back. It is the base of the visual block editor. The code is pure: it has no Nuxt import. It lives in `shared/utils/blocks/` of `@plutocms/core`. The UI is the [block editor](../block-editor/SKILL.md).

  • 4 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added November 7, 2026
developmentjavascripttypescriptgojavareactvuenodegitapibackend

Works with

  • api

Security analysis

A100/100

Scanned November 24, 2026

npx -y skills add plutocms/pluto --skill block-model --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Block Model?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Block Model
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/plutocms-block-model/badge)](https://www.skillsdirectory.com/skills/plutocms-block-model)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
# Block model

The block model cuts the Markdown (MDC) body of a page into blocks, edits the blocks, and writes
the text back. It is the base of the visual block editor. The code is pure: it has no Nuxt import.
It lives in `shared/utils/blocks/` of `@plutocms/core`. The UI is the [block editor](../block-editor/SKILL.md).

## The rule

The truth is the Markdown string. The model never writes the whole page again from a tree. A block
that is not edited keeps the source text it came from (`original`), and the gaps between the blocks
keep the text too. A save with no edit writes the same bytes. One edit changes only the lines of
that block. A test guards this with the 48 pages of the docs site.

## Files

- `types.ts`: `PlutoBlockDoc`, the four kinds of block, and the types of a block definition.
- `parse.ts`: `parseBlocks(source)`. It uses `remark-parse`, `remark-gfm` and `remark-mdc`.
- `serialize.ts`: `serializeBlocks(doc)`, `renderBlock(block)`.
- `mdc-props.ts`: reads and writes the props: `{a="b" .c #d flag :n='3'}` and the YAML block.
- `operations.ts`: pure, immutable edits. Each returns a new doc.
- `history.ts`: undo and redo over doc snapshots. The clock is a parameter.
- `labels.ts`: `BLOCK_GROUPS`, `BLOCK_KIND_LABELS`, `groupLabelKey`, `HIDDEN_PROP_NAMES`.
- `registry.ts`: `resolveBlockDefinition`, `listPaletteBlocks`, `blockKey`.
- `component-meta.ts`: `blockFromComponentMeta`, `componentBlockName`. It makes a block definition
  from the meta of a Vue component (see "Component meta").
- `preview-protocol.ts`: the `postMessage` types and validators for the preview frame.
- `editor.ts`: helpers for the UI (labels, slot editors, preview blocks, palette).
- `tree.ts`: `flatChildren`, `walkBlocks`, `findBlock`, `pathOf`, `newBlockId`.

## The kinds of block

- `text`: prose. One block for each H1 or H2 section at the top level. In a component, all the
  prose between two other blocks is one block.
- `code`: a fenced code block. `lang`, `filename` (from `[file.ts]`), `meta`, `fence`, `code`.
- `component`: a container component (`::name`). It has `props`, `propsStyle` (`inline` or `yaml`),
  `propOrder`, `slots`, and `gaps`.
- `raw`: Markdown that the editor does not edit. The `reason` is `table`, `html`, `inline-mdc`,
  `footnote`, `task-list` or `unknown`. A raw block is still written back byte for byte.

## How a component is kept

- The children of all slots are in one list in source order. `slots` splits that list by slot name.
  `gaps` has the text before, between and after the children. It holds the `#name` lines.
- `openerText` is the opening line (and the YAML block). While the props are the same, it is
  written as it was. `propSource` has the source text of each prop, so a changed prop does not
  rewrite the others.
- A nested component has more colons than its parent. The model raises the colons when it moves or
  inserts a block into a parent.
- `indent` is the white space before the first line of a block inside a component.

## Operations

`insertBlocks`, `insertBlock`, `removeBlock`, `moveBlock`, `duplicateBlock`, `updateText`,
`updateCode`, `setProp`, `setProps` (some props in one edit), `setSlot`, `replaceWithMarkdown`, `blocksFromMarkdown`, `blockMarkdown`,
and the makers `createTextBlock`, `createComponentBlock`.

- An edit removes `original` from the block and its ancestors. The other blocks keep theirs.
- A move in one list changes only the order of the blocks. The gaps stay in place.
- A no-op edit returns the same doc object.
- Pass plain objects. The functions copy the doc with JSON, so a Vue proxy also works.

## Block definitions

`resolveBlockDefinition(name, { sources, block })` joins the layers into one definition. The order,
low to high:

1. the preset of `sources.presets` (or an automatic entry for an unknown component). With no preset
   registered, every component is an automatic entry,
2. the component layer (`sources.components`), made from the component files,
3. the site override (`sources.overrides`): `plutoBlocks` in `app.config.ts`,
4. the props and slots found in the document (`block`). They fill only what is missing, in the
   Advanced section.

`PlutoBlockSources = { presets?, components?, overrides? }` is the one object that carries the layers. The
palette, the preview, the labels and the editor state all take it. The component layer comes from
the module (see "Discovery").

Rules of the merge:

- A layer is a partial definition. Props and slots join key by key (shallow). A site can change only
  the `label` of a prop that the component layer typed.
- `false` for a prop or a slot removes it. `false` for a whole block hides it (`hidden: true`).
  `{ hidden: false }` in a higher layer shows it again.
- A prop that no layer types is a `string`.
- A prop can have a `default`. It is a hint for the control. It never goes into the Markdown.
- Names: the key is the kebab name (`PlutoHero` is `pluto-hero`, `UPageCTA` is `u-page-c-t-a`).
  `blockKey` makes it. The lookup also takes the Pascal form that a page can use (`::PlutoHero`),
  and a config key in any form.
- Prop keys: a prop of the definition takes the spelling of the block. If the page has
  `star-count` and the meta has `starCount`, the definition key is `star-count`. So an edit changes
  the prop of the page. It never adds a second one.
- `listPaletteBlocks(sources, accepts)` lists the presets, then the names in `components`, then the names that
  only `overrides` has. A component shows in the palette only when it is in one of the layers
  (opt-in). Any other component keeps the automatic entry: it is not in the palette, and a page that
  uses it edits in Advanced. A `hidden` block is not listed, unless its name is in `accepts` (the top level
  of a field with `blocks`, or a slot with `accepts`): `menu-item` is hidden from page palettes and shows in
  a menu.

`definePlutoBlock(def)` is a typed identity helper (`shared/utils/blocks/define.ts`, a file with no
other import). `definePlutoBlock<Props>({...})` checks that the keys of `props` are keys of `Props`. A label or a description is an i18n key
(for example `docs.blocks.<name>.label`) or a plain text.

Definitions never feed `parseBlocks` or `serializeBlocks`. The corpus test does not change when a
layer changes.

## Component meta

`component-meta.ts` is pure. The module (see "Discovery") reads the meta of a component with
`nuxt-component-meta`, and the object of its `definePlutoBlock({...})` call. It then calls
`blockFromComponentMeta(name, meta, macro?)`. The result is `{ name, definition }`: the block key
and the partial definition for the component layer. The macro wins over the meta, key by key.

The type of a prop gives the widget. `undefined` and `null` are removed first.

| Type                                                   | Widget                             |
| ------------------------------------------------------ | ---------------------------------- |
| `string`, named `icon` or ending in `Icon`             | `icon`                             |
| `string` or `RouteLocationRaw`, named `to` or `href`   | `link`                             |
| any other `string`; `string` or `number`               | `string`                           |
| `number`                                               | `number`                           |
| `boolean`                                              | `boolean`                          |
| a union of string literals                             | `select` (options in source order) |
| a union of theme colors                                | `color`                            |
| object, array, function, number literals, other unions | no widget                          |

- The type `media` (an image of the media library) is not from the meta: a definition sets it, with
  `fills` (`{ width, height, alt }`, the props that a choice also sets). See the block editor skill
  ("The Image block").
- A prop with no widget is not in the definition. A page that sets it shows it in Advanced.
- A mapped prop goes in Settings. `advanced: true` in the macro moves it.
- A simple default (`300`, `"normal"`, `false`) becomes `default`.
- The JSDoc text of a prop is its `description`. The label is the shared key
  `pluto.blocks.props.<name>` when a preset has one. Else the control shows the name in words.
- A slot with the `mdcUnwrap` binding (`<slot mdc-unwrap="p">`) gets `content: 'inline'`. Other
  slots get no `content`, so `resolveSlotMode` picks it from the page.
- The label of a block is the macro label, else the name in words. The meta has no description.

## Presets

Core ships no preset. A layer adds blocks with the `blockPresets` bucket of the extension registry:

```ts
definePlutoExtension({
  id: 'my-layer',
  blockPresets: [{ id: 'note', definition: { name: 'note', label: 'my.note', icon: 'i-lucide-info', group: 'callouts' } }],
})
```

`usePlutoBlockSources` joins the entries of every layer into `sources.presets`, keyed by the block
name. The labels are i18n keys or plain text. The shared prop and slot labels are
`pluto.blocks.props.<name>` and `pluto.blocks.slots.<name>` of core. A component-layer prop with the
same name as a preset prop takes that label.

The docs layer registers the Nuxt UI prose and page components (`shared/utils/block-presets.ts`,
`app/plugins/pluto-docs.ts`). To add one there:

1. Add a `block(...)` call to `block-presets.ts` with the group, the icon, the props, the slots, and the
   insert text.
2. Add `label` and `description` to `blocks.<name>` of the docs locale files. A new prop or slot name
   needs a key in `pluto.blocks.props` or `pluto.blocks.slots` of core.
3. `packages/layers/docs/test/blocks-registry.test.ts` checks the keys, the insert text, and unused texts.

## Discovery

The component layer comes from the `pluto-blocks` module of `@plutocms/core` finds the files of
`components/content/` that call `definePlutoBlock(...)`, reads their props and slots from the
TypeScript types, and gives the virtual module `#pluto-blocks`. See the content-components skill of
pluto (`.claude/skills/content-components/SKILL.md`, "Discovery"). The post editor of core uses the
same catalog for its content components.

- `PlutoBlockEditor.vue`, `PlutoBlockMarkdownSplit.vue` and `usePlutoBlocksRender` (the preview and the
  public `PlutoBlocks`) import `#pluto-blocks` and pass it to `usePlutoBlockSources(componentBlocks)`.
- The definition types (`PlutoBlockDefinition`, `PlutoBlockPatch`, the prop types...), `blockKey`,
  `humanizeName`, `mergeBlockPatch`, `BLOCK_COLORS`, the MDC props (`mdc-props.ts`) and the meta
  reader (`component-meta.ts`) sit next to the model in `shared/utils/blocks/`. App code and other
  layers import them with the alias `#layers/pluto/...` (`types.ts` re-exports the types). The
  `vitest.config.ts` of core and of the docs layer give the same alias to plain Vitest.
- **Shared labels:** the meta reader of core gives no label. `resolveBlockDefinition` puts the label of
  a preset prop or slot with the same name (`pluto.blocks.props.icon`, `pluto.blocks.slots.default`) on
  a prop or a slot of the component layer that has no label (`withSharedLabels` in `registry.ts`).
  The label of the macro wins.

## Tests

These tests are in `packages/core/test/`, except the ones that need presets (below).

- `test/blocks-corpus.test.ts`: the 48 pages in `test/fixtures/mdc/` (copied from the docs site)
  write back byte for byte. The fixtures have `-text` in `.gitattributes`, so git keeps the bytes.
- `test/blocks-edit.test.ts`, `test/blocks-operations.test.ts`: one edit changes only that block,
  and every operation leaves a text that parses again and writes the same bytes.
- `test/blocks-parse.test.ts`, `test/blocks-history.test.ts`, `test/blocks-registry.test.ts` (the
  layers, the merge, the names, the palette), `test/blocks-preview-protocol.test.ts`.
- Docs layer: `test/blocks-registry.test.ts` (the presets, the layers, the merge, the names, the
  palette), `test/blocks-component-layer.test.ts` (the shared labels, the kebab props of a page,
  `false` slots), `test/blocks-image.test.ts`. They use `test/helpers/blocks.ts`, which passes the
  docs presets to the core functions.

## Public render

The public site renders the same Markdown with Comark, so what the editor preview shows is what the
site shows.

- `server/utils/pluto-blocks.ts`: `parsePlutoBlocks(text)` gives a Comark `MarkdownDocument`
  (`parseMarkdown` with `autoUnwrap: false`, like the preview, and the `security()` plugin). It blocks
  the tags that the post sanitizer drops (script, style, iframe, frame, frameset, object, embed, base,
  link, meta, the form and its controls, svg, math, audio, video, canvas and more: `PLUTO_BLOCKED_TAGS`),
  except `template`, which Comark uses for a slot. Allowed URL protocols: http, https, mailto, tel and
  relative. Comark also removes `on*` attributes and `javascript:` URLs. An in-memory LRU cache (200
  entries) keys the result by a hash of the text.
- `toPublicData` calls it for the item view of a type whose body field has `widget: 'blocks'`, so every
  backend gets `blocks` in the public API (see the content-model skill). The props in the document
  are text: a React or Svelte site converts them itself.
- `app/components/Pluto/PlutoBlocks.vue` (`<PlutoBlocks :value="item.blocks" />`) renders the document with
  `MarkdownDocument` of `@comark/vue`, on the server too.
- `app/composables/pluto-blocks-render.ts` (`usePlutoBlocksRender`) is shared by `PlutoBlocks` and the
  preview: the component manifest (`#pluto-content-components`), the prop conversion (`coerce`, with the
  block definitions of `#pluto-blocks`) and the tag map.
- `#pluto-blocks` now loads on the server too, because the render converts props there. The public bundle
  holds the definitions of the site components.
- Text styles: `proseClass` is `pluto-prose` when the site has no `ProseP` component, else nothing.
  `PlutoBlocks` puts it on its root (`tag`, default `article`, like `PlutoHtml`), and the preview wraps
  its blocks in a `div` with it only when it is set. So a site with Prose components (a docs site)
  keeps its markup, and a site without them styles the text of a page like a post.
- Core's `nuxt.config.ts` has `build.transpile: ['@comark/vue']`. Without it, the server build keeps
  `@comark/vue` external, it imports the full `vue` build (with the compiler) at run time, and the
  built server does not start (`estree-walker` has no CommonJS export). A second Vue would also break
  the SSR context.
- Tests: `test/pluto-blocks-parse.test.ts`, `test/pluto-blocks-ssr.test.ts`, `test/public-api.test.ts`.

## Pinned versions

`remark-mdc`, `remark-parse`, `remark-gfm` and `unified` are exact dependencies of core, pinned to the
versions that `@nuxtjs/mdc` 0.23 used. The blocks are cut with `remark-mdc`, and the preview renders with
Comark. Change a pin only with a run of the corpus test.

## Limits

- A component whose opening line spans lines, or has `[text]` after the name, or has no closing
  colons, is a raw block.
- A YAML comment between props is lost when that component's props change.
- An edited Text block uses `\n`. A page with `\r\n` keeps its bytes until a block is edited.

## Constraints that the code does not say

These came from code comments. Keep them true when you change the code.

- The truth stays the Markdown string: a block with `original` is written back byte for byte.
- The model copies a doc with a JSON copy, so a reactive proxy works too.
- The parser reads a footnote reference as a text span, so a text span that starts with `[^` is a
  `footnote` block, not an inline component.
- A fenced code with a meta string inside a list or a quote is a raw `unknown` block: only a plain
  language is safe there.
- Content before the first `#name` is `default`. After a section, loose content is a `#default`
  section, because the parser keeps no node for that marker. The children must be in source order,
  inside the component.
- A default slot with no entry goes first. Another missing slot goes last.
- A move in one list changes only the order of the blocks. The gaps stay in place.
- A line of code that looks like the fence needs a longer fence.
- The parser turns prose that the text editor would lose into a raw block. Markdown keeps it as it is.
- The preview messages limit the depth of `children` (16). A real page nests a few levels, and the limit
  stops a message that nests without end.
- `coerceBlockProps` and `coerceNodeProps` (`prop-types.ts`) are pure. They convert the text props of
  a parsed component to the types of its definition, so the public render can reuse them.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.