portable-text-conversion
Converts HTML and Markdown content into Portable Text blocks for Sanity using markdownToPortableText, htmlToBlocks, or manual construction.
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 510 tokenswhen the skill loads
- GitHub stars
- 188on sanity-io/agent-toolkit
- Scripts
- None found
What it does
“Convert HTML and Markdown content into Portable Text blocks for Sanity. Use when migrating content from legacy CMSs, importing HTML or Markdown into Sanity, building content pipelines that ingest external content, converting rich text between formats, or programmatically creating Portable Text documents. Covers @portabletext/markdown (markdownToPortableText), @portabletext/block-tools (htmlToBlocks), custom deserializers, and the Portable Text specification for manual block construction.”
Generated summary from the skill's own text
Converts HTML and Markdown content into Portable Text blocks for Sanity using markdownToPortableText, htmlToBlocks, or manual construction. Useful for migrating content from legacy systems, importing external rich text formats, or building content pipelines that ingest diverse sources into Sanity.
When to use it
- Migrating content from legacy CMS platforms to Sanity
- Importing existing HTML or Markdown documents into Sanity projects
- Building pipelines that ingest external content from APIs or databases
- Converting rich text between different formats for Sanity compatibility
When not to
- Working with Sanity content already in native Portable Text format
- Projects that do not use Sanity as the content management system
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-conversionInstalls 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-conversion@88d6cdfa7cb06c99edd5f376efa4dac21ae3f877Installs the commit we checked (88d6cdf).
Copy by hand
Download the folder at 88d6cdf and put it in .claude/skills/portable-text-conversion for Claude Code and in .agents/skills/portable-text-conversion for Codex, Cursor, Gemini CLI, GitHub Copilot and OpenCode.
Claude Code plugin
/plugin install sanity@claude-plugins-officialThe 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-conversion" by Sanity. Source, pinned to commit 88d6cdfa7cb06c99edd5f376efa4dac21ae3f877: https://github.com/sanity-io/agent-toolkit/tree/88d6cdfa7cb06c99edd5f376efa4dac21ae3f877/skills/portable-text-conversion 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-conversion/ for Claude Code and .agents/skills/portable-text-conversion/ 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-conversion
SKILL.md at the pin
---
name: portable-text-conversion
description: Convert HTML and Markdown content into Portable Text blocks for Sanity. Use when migrating content from legacy CMSs, importing HTML or Markdown into Sanity, building content pipelines that ingest external content, converting rich text between formats, or programmatically creating Portable Text documents. Covers @portabletext/markdown (markdownToPortableText), @portabletext/block-tools (htmlToBlocks), custom deserializers, and the Portable Text specification for manual block construction.
license: MIT
metadata:
author: sanity
version: "1.0.0"
---
# 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:
```json
[
{
"_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"}
}
]
```
**Key rules:**
- Every block and span needs `_key` (unique within the array)
- `_type: "block"` is for text blocks; custom types use their own `_type`
- `markDefs` holds annotation data; `marks` on spans reference `markDefs[*]._key` or are decorator strings
- Lists use `listItem` ("bullet" | "number") and `level` (1, 2, 3...) on regular blocks
## Conversion Rules
Read the rule file matching your source format:
- **Markdown → Portable Text**: `rules/markdown-to-pt.md` — `@portabletext/markdown` with `markdownToPortableText` (recommended)
- **HTML → Portable Text**: `rules/html-to-pt.md` — `@portabletext/block-tools` with `htmlToBlocks`
- **Manual PT Construction**: `rules/manual-construction.md` — build blocks programmatically from any source
> **Note:** `@sanity/block-tools` is the legacy package name. Always use `@portabletext/block-tools` for new projects. The API is the same.
From sanity-io/agent-toolkit at 88d6cdf, shown as plain text under its license: MIT (permissive). The license text is in skills/portable-text-conversion/SKILL.md.
View SKILL.md on GitHub at 88d6cdfFiles
- SKILL.md2.7 KB · 6dc622dff286
- rules/
- html-to-pt.md7.1 KB · c7b0991acae5
- manual-construction.md5.0 KB · dac88b1c2f50
- markdown-to-pt.md5.6 KB · 2bf6aded4d88
4 files, 20 KB in total. Each file has a sha256 in the pin's manifest; the first 12 characters are shown.
Skill folder on GitHub at 88d6cdfMore 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-serialization
This skill enables rendering Portable Text content across multiple frameworks and output formats using the @portabletext library family.
Claude Code, Codex, Cursor +4 · about 940 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
Related in Coding workflow
planning
This skill orchestrates multi-workflow projects with dependencies and shared data tables by creating a task graph in the orchestrator via the create-tasks tool.
by n8nOfficial publisher
Claude Code, Codex, Cursor +3 · about 2.4K tokens · pinned 6 days ago
progressive-building
This skill implements incremental workflow development for agents building or extending workflows.
by n8nOfficial publisher
Claude Code, Codex, Cursor +3 · about 1.4K tokens · pinned 6 days ago
workflow-builder
Builds and edits n8n workflows using the TypeScript SDK.
by n8nOfficial publisher
Claude Code, Codex, Cursor +3 · about 14.2K tokens · pinned 6 days ago
remotion-upgrade
This skill upgrades Remotion and its related packages to the latest stable version.
by RemotionOfficial publisher
Claude Code, Codex, Cursor +3 · about 460 tokens · pinned 6 days ago
remotion-upgrade
This skill upgrades Remotion and related packages across a project, automatically detecting the package manager and workspaces.
by RemotionOfficial publisher
Claude Code, Codex, Cursor +3 · about 460 tokens · pinned 6 days ago
final-release-review
Audits Python SDK release candidates or plans against the previous release, comparing diffs for regressions, API changes, and version compatibility.
by OpenAIOfficial publisher
Contains scripts
Claude Code, Codex, Cursor +3 · about 5.4K tokens · pinned 6 days ago