Skip to content
sanity-io avatar

Portable Text Conversion

Convert HTML and Markdown into Portable Text blocks for Sanity during migrations and content pipelines.

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

Own this skill? Claim it

What it does

  • Covers three conversion paths: markdownToPortableText for Markdown, htmlToBlocks for HTML, and manual block construction from any source
  • Includes the Portable Text block structure, with required _key fields, markDefs, and listItem and level for lists
  • Provides separate rule files for Markdown, HTML, and manual construction, each covering its own conversion behavior
  • Designed for teams migrating content from legacy CMSs or building pipelines that ingest external content into Sanity

Install

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

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

Files

Portable Text Conversion

Convert external content (HTML, Markdown) into Portable Text for Sanity. Three main approaches:

  1. markdownToPortableText — Convert Markdown directly using @portabletext/markdown (recommended for Markdown)
  2. htmlToBlocks — Parse HTML into PT blocks using @portabletext/block-tools (for HTML migration)
  3. Manual construction — Build PT blocks directly from any source (APIs, databases, etc.)

Portable Text Specification

Understand the target format before converting. PT is an array of blocks:

[
  {
    "_type": "block",
    "_key": "abc123",
    "style": "normal",
    "children": [
      {"_type": "span", "_key": "def456", "text": "Hello ", "marks": []},
      {"_type": "span", "_key": "ghi789", "text": "world", "marks": ["strong"]}
    ],
    "markDefs": []
  },
  {
    "_type": "block",
    "_key": "jkl012",
    "style": "h2",
    "children": [
      {"_type": "span", "_key": "mno345", "text": "A heading", "marks": []}
    ],
    "markDefs": []
  },
  {
    "_type": "image",
    "_key": "pqr678",
    "asset": {"_type": "reference", "_ref": "image-abc-200x200-png"}
  }
]

Details

Repository
github.com/sanity-io/agent-toolkit
Category
Backend & APIs
First seen
Jun 3, 2026

More from sanity-io/agent-toolkit

All 7

Similar to Portable Text Conversion

More Backend & APIs