sanity-io avatar

Portable Text Conversion

If you're migrating content into Sanity or building ingestion pipelines, this handles the conversion work. It covers three approaches: markdownToPortableText from @portabletext/markdown for direct Markdown conversion, htmlToBlocks from @portabletext/block-tools for HTML migration, and manual block construction when you need full control. The guides break down the Portable Text spec (blocks, spans, keys, markDefs) and show concrete conversion patterns for each source format. Handy reference if you've ever stared at a legacy CMS export wondering how to turn it into proper PT blocks without writing a parser from scratch.

skills.sh installs
2.9K
GitHub stars
197
last updated
Aug 21, 2026

Install

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

Installs into .claude/skills of the current project.

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"}
  }
]

Sponsors

Details

Repository
github.com/sanity-io/agent-toolkit
Categories
Frontend Development, AI & Agent Building, Marketing & SEO
First seen
Jun 3, 2026

More from sanity-io/agent-toolkit

All 7
1nexu-io avatardocnexu-io/open-designRead, create, and edit .docx documents with formatting and layout fidelity via OpenAI's document skill.2.9Kskills.sh installs
2github avatardraw-io-diagram-generatorgithub/awesome-copilotUse when creating, editing, or generating draw.io diagram files (.drawio, .drawio.svg, .drawio.png). Covers mxGraph XML authoring, shape libraries, style string2.9Kskills.sh installs
3antfu avatarnitroantfu/skillsNitro is the framework-agnostic server toolkit (powering Nuxt) for building and deploying web servers anywhere. Use when working with nitro.config, server route2.9Kskills.sh installs
4actionbook avataractive-researchactionbook/actionbookDeep research and analysis tool. Generates comprehensive HTML reports on any topic, domain, paper, or technology. Enhanced with advanced browser automation — SP2.9Kskills.sh installs
5nexu-io avatarfal-video-editnexu-io/open-designEdit existing videos using AI — remix style, upscale, remove background, and add audio via fal.ai's hosted video models.2.8Kskills.sh installs
6nexu-io avatarsoranexu-io/open-designGenerate, remix, and manage short video clips via OpenAI's Sora API. Useful for cinematic shots, b-roll, and rapid concept video iteration.2.8Kskills.sh installs