Agent Native

portable-text-serialization

This skill enables rendering Portable Text content across multiple frameworks and output formats using the @portabletext library family.

by SanityOfficial publisherNot reviewed

Identity proven by GitHub's verified organisation badge (sanity-io)

Agents
Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, OpenCode, claude.ai and API
License
MIT (permissive)
Pin
88d6cdfpinned Oct 9, 2026
Context cost
about 940 tokenswhen the skill loads
GitHub stars
188on sanity-io/agent-toolkit
Scripts
None found

What it does

“Render and serialize Portable Text to React, Svelte, Vue, Astro, HTML, Markdown, and plain text. Use when implementing Portable Text rendering in any frontend framework, building custom serializers for non-standard block types, converting Portable Text to HTML strings server-side, converting Portable Text to Markdown, extracting plain text from Portable Text, or troubleshooting rendering issues with marks, blocks, lists, or custom types.”
The author's description, from SKILL.md

Generated summary from the skill's own text

This skill enables rendering Portable Text content across multiple frameworks and output formats using the @portabletext library family. It provides component-mapping patterns and framework-specific guidance for React, Vue, Svelte, Astro, HTML, Markdown, and plain text serialization. The skill includes rules for handling custom block types, marks, lists, and troubleshooting common rendering issues.

When to use it

  • Rendering Portable Text in React, Vue, Svelte, or Astro projects
  • Building custom serializers for non-standard block and mark types
  • Converting Portable Text to HTML, Markdown, or plain text formats
  • Implementing Portable Text with GROQ queries and reference expansion

When not to

  • Projects not using Portable Text as content format
  • Rendering targets already covered by framework-native solutions
  • When simpler string rendering approaches suffice

Install

These commands install from the publisher's repository and need no account.

skills CLI

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

Installs from the repository's default branch, which may have changed since the commit we checked.

GitHub CLI 2.90 or later

gh skill install sanity-io/agent-toolkit portable-text-serialization@88d6cdfa7cb06c99edd5f376efa4dac21ae3f877

Installs the commit we checked (88d6cdf).

Copy by hand

Download the folder at 88d6cdf and put it in .claude/skills/portable-text-serialization for Claude Code and in .agents/skills/portable-text-serialization for Codex, Cursor, Gemini CLI, GitHub Copilot and OpenCode.

Skill folder on GitHub at 88d6cdf

Claude Code plugin

/plugin install sanity@claude-plugins-official

The publisher's plugin in Claude's official marketplace. It may hold more than this skill, and we have not pinned it.

Copy for your agent

A prompt for any coding agent. It installs this skill from GitHub at the pinned commit, copies the files as they are, and runs nothing unless you ask.

Prompt

Install the agent skill "portable-text-serialization" by Sanity.

Source, pinned to commit 88d6cdfa7cb06c99edd5f376efa4dac21ae3f877:
https://github.com/sanity-io/agent-toolkit/tree/88d6cdfa7cb06c99edd5f376efa4dac21ae3f877/skills/portable-text-serialization

1. Download that folder at exactly this commit. Do not use the default branch.
2. Copy every file unchanged, keeping the folder structure, into .claude/skills/portable-text-serialization/ for Claude Code and .agents/skills/portable-text-serialization/ for Codex, Cursor, Gemini CLI, GitHub Copilot and OpenCode. Create the folders if they do not exist.
3. Do not edit the files, and do not run any script in the folder unless I ask you to.
4. When you are done, list the files you copied and where you put them.

Listing and checks: https://www.agentnative.dev/skills/sanity/portable-text-serialization

SKILL.md at the pin

---
name: portable-text-serialization
description: Render and serialize Portable Text to React, Svelte, Vue, Astro, HTML, Markdown, and plain text. Use when implementing Portable Text rendering in any frontend framework, building custom serializers for non-standard block types, converting Portable Text to HTML strings server-side, converting Portable Text to Markdown, extracting plain text from Portable Text, or troubleshooting rendering issues with marks, blocks, lists, or custom types.
license: MIT
metadata:
  author: sanity
  version: "1.0.0"
---

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

Every `@portabletext/*` library accepts a `components` object with these keys:

| Key | Renders | Props/Data |
|-----|---------|------------|
| `types` | Custom block/inline types (image, code, CTA) | `value` (the block data) |
| `marks` | Decorators + annotations | `children` + `value` (mark data) |
| `block` | Block styles (h1, normal, blockquote) | `children` |
| `list` | List wrappers (ul, ol) | `children` |
| `listItem` | List items | `children` |
| `hardBreak` | Line breaks within a block | — |

## Framework-Specific Rules

Read the rule file matching your framework:

- **React / Next.js**: `rules/react.md` — `@portabletext/react` or `next-sanity`
- **Svelte / SvelteKit**: `rules/svelte.md` — `@portabletext/svelte`
- **Vue / Nuxt**: `rules/vue.md` — `@portabletext/vue`
- **Astro**: `rules/astro.md` — `astro-portabletext`
- **HTML (server-side)**: `rules/html.md` — `@portabletext/to-html`
- **Markdown**: `rules/markdown.md` — `@portabletext/markdown`
- **Plain text extraction**: `rules/plain-text.md` — `@portabletext/toolkit`

### Additional Community Serializers

These are listed on [portabletext.org](https://www.portabletext.org/integrations/serializers/) but don't have dedicated rule files:

| Target | Package |
|--------|---------|
| React Native | `@portabletext/react-native-portabletext` |
| React PDF | `@portabletext/react-pdf-portabletext` |
| Solid | `solid-portabletext` |
| Qwik | `portabletext-qwik` |
| Shopify Liquid | `portable-text-to-liquid` |
| PHP | `sanity-php` (SanityBlockContent class) |
| Python | `portabletext-html` |
| C# / .NET | `dotnet-portable-text` |
| Dart / Flutter | `flutter_sanity_portable_text` |

## Common Patterns (All Frameworks)

### Custom Types Need Explicit Components

PT renderers only handle standard blocks by default. Custom types (`image`, `code`, `callToAction`, etc.) require explicit component mappings — they won't render otherwise.

### Keep Components Object Stable

In React/Vue, define `components` outside the render function or memoize it. Recreating on every render causes unnecessary re-renders.

### Handle Missing Components Gracefully

All libraries accept `onMissingComponent` to control behavior when encountering unknown types:
- `false` — suppress warnings
- Custom function — log or report

### Querying PT with GROQ

Always expand references inside custom blocks:

```groq
body[]{
  ...,
  _type == "image" => {
    ...,
    asset->
  },
  markDefs[]{
    ...,
    _type == "internalLink" => {
      ...,
      "slug": @.reference->slug.current
    }
  }
}
```

From sanity-io/agent-toolkit at 88d6cdf, shown as plain text under its license: MIT (permissive). The license text is in skills/portable-text-serialization/SKILL.md.

View SKILL.md on GitHub at 88d6cdf

Files

8 files, 25 KB in total. Each file has a sha256 in the pin's manifest; the first 12 characters are shown.

Skill folder on GitHub at 88d6cdf
All 24 skills from Sanity

More from Sanity

  • sanity-live-cache-components

    Integrates Sanity Live with Next.js Cache Components in next-sanity v13+ apps, setting up shared cached data fetching through sanityFetch, live content…

    Claude Code, Codex, Cursor +4 · about 4K tokens · pinned 6 days ago

  • content-experimentation-best-practices

    This skill provides guidance for designing and running content experiments using A/B and multivariate testing.

    Claude Code, Codex, Cursor +4 · about 360 tokens · pinned 6 days ago

  • content-modeling-best-practices

    Guides agents through structured content modeling principles for headless CMSes like Sanity, covering schema design, content reuse strategies, and field…

    Claude Code, Codex, Cursor +4 · about 340 tokens · pinned 6 days ago

  • portable-text-conversion

    Converts HTML and Markdown content into Portable Text blocks for Sanity using markdownToPortableText, htmlToBlocks, or manual construction.

    Claude Code, Codex, Cursor +4 · about 510 tokens · pinned 6 days ago

  • sanity-best-practices

    This skill provides best practices for Sanity headless CMS development across schema design, GROQ queries, framework integrations (Next.js, Nuxt, Astro…

    Claude Code, Codex, Cursor +4 · about 1.1K tokens · pinned 6 days ago

  • sanity-migration

    This skill plans, executes, and validates migrations from various content management systems and data sources into Sanity.

    Claude Code, Codex, Cursor +4 · about 1.2K tokens · pinned 6 days ago

  • stitch::extract-design-md

    Extracts a comprehensive design system document (DESIGN.md) by analyzing frontend source code including component files, stylesheets, Tailwind configs, and…

    by GoogleOfficial publisher

    Claude Code, Codex, Cursor +4 · about 3.3K tokens · pinned 6 days ago

  • create-site

    Guides users through building a complete Power Pages code site using React, Angular, Vue, or Astro, from initial requirements discovery through deployment.

    by MicrosoftOfficial publisher

    Contains scripts

    Claude Code · about 29.1K tokens · pinned 6 days ago

  • mapbox-web-integration-patterns

    Provides production-ready integration patterns for Mapbox GL JS v3.x across React, Vue, Svelte, Angular, Next.js, and vanilla JavaScript.

    by MapboxOfficial publisher

    Claude Code, Codex, Cursor +4 · about 3.1K tokens · pinned 6 days ago

  • crxjs

    CRXJS is a Vite plugin for Chrome extension development that provides true hot-module reloading for popups, options pages, content scripts, and side panels.

    by samberCommunity

    Claude Code · about 2.3K tokens · pinned 6 days ago

  • remotion-saas

    This skill helps build video generation applications using Remotion, a React framework for programmatic video creation.

    by RemotionOfficial publisher

    Claude Code, Codex, Cursor +3 · about 240 tokens · pinned 6 days ago

  • stitch::code-to-design

    This skill converts existing frontend code (React, Vue, Angular, etc.) into a Stitch Design by extracting HTML, analyzing design systems, and uploading both…

    by GoogleOfficial publisher

    Claude Code, Codex, Cursor +4 · about 760 tokens · pinned 6 days ago

The skills listed here are third-party software, collected from public GitHub repositories as a catalog of recent skills and provided as is. Agent Native does not write or control them and is not responsible for any harm, loss or damage caused by installing or using them. Labels and checks describe what we saw at one commit and are not a guarantee. Read a skill's files before you run it. Terms of use