Skip to content
sanity-io avatar

Portable Text Serialization

Portable Text rendering and serialization across React, Svelte, Vue, Astro, HTML, Markdown, and plain text targets.

CCM score
67 of 100
skills.sh installs
3.2K
GitHub stars
203
last updated
Aug 21, 2026
View on GitHub

Own this skill? Claim it

What it does

  • Covers rendering Portable Text blocks, marks, lists, and custom types across frontend frameworks and server-side outputs
  • Includes per-framework rule files for React, Svelte, Vue, Astro, HTML, Markdown, and plain text, plus a table of community serializers
  • Requires explicit component mappings for custom types and a stable components object to avoid re-renders
  • Designed for developers implementing Portable Text rendering or troubleshooting marks, blocks, and lists in Sanity-backed projects

Install

$ npx -y skills add sanity-io/agent-toolkit --skill portable-text-serialization -y

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

Files

Portable Text Serialization

Render Portable Text content across frameworks using the @portabletext/* library family. Each library follows the same component-mapping pattern: you provide a components object that maps PT node types to framework-specific renderers.

Portable Text Structure (Quick Reference)

PT is an array of blocks. Each block has _type, optional style, children (spans), markDefs, listItem, and level.

Root array
├── block (_type: "block")
│   ├── style: "normal" | "h1" | "h2" | "blockquote" | ...
│   ├── children: [span, span, ...]
│   │   └── span: { _type: "span", text: "...", marks: ["strong", "<markDefKey>"] }
│   ├── markDefs: [{ _key, _type: "link", href: "..." }, ...]
│   ├── listItem: "bullet" | "number" (optional)
│   └── level: 1, 2, 3... (optional, for nested lists)
├── custom block (_type: "image" | "code" | any custom type)
└── ...more blocks

Marks come in two forms:

  • Decorators: string values in marks[] like "strong", "em", "underline", "code"
  • Annotations: keys in marks[] referencing entries in markDefs[] (e.g., links, internal references)

Component Mapping Pattern (All Frameworks)

Details

Repository
github.com/sanity-io/agent-toolkit
Categories
Frontend & UI Code, Technical Documentation
First seen
Jun 3, 2026

More from sanity-io/agent-toolkit

All 7

Similar to Portable Text Serialization

More Frontend & UI Code