8 skills · 23 min
Skills
Skill 3 of 8
Convert HTML and Markdown content into Portable Text blocks for Sanity.
1 minute · 147 words · 2 sections
Install
npx skills add sanity-io/agent-toolkit --skill portable-text-conversionnpx skills add sanity-io/agent-toolkit/plugin marketplace add sanity-io/agent-toolkitThe first command installs just this skill, by the name in its SKILL.md; the second installs the whole repository.
Convert external content (HTML, Markdown) into Portable Text for Sanity. Three main approaches:
markdownToPortableText — Convert Markdown directly using @portabletext/markdown (recommended for Markdown)htmlToBlocks — Parse HTML into PT blocks using @portabletext/block-tools (for HTML migration)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": []},
Key rules:
_key (unique within the array)_type: "block" is for text blocks; custom types use their own _typemarkDefs holds annotation data; marks on spans reference markDefs[*]._key or are decorator stringslistItem (“bullet” | “number”) and level (1, 2, 3…) on regular blocksRead the rule file matching your source format:
rules/markdown-to-pt.md — @portabletext/markdown with markdownToPortableText (recommended)rules/html-to-pt.md — @portabletext/block-tools with htmlToBlocksrules/manual-construction.md — build blocks programmatically from any sourceNote:
@sanity/block-toolsis the legacy package name. Always use@portabletext/block-toolsfor new projects. The API is the same.
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.
The verbatim description from this skill’s front matter — the string an agent matches on to decide whether to load it.
skills/portable-text-conversion/SKILL.mdmain, last pushed 16 September 2026.SKILL.md, not by matching a directory convention. One layout observed: skills/*/SKILL.md.h1 and no skipped levels:.claude-plugin/marketplace.json by Sanity, declaring 1 plugin. It is read for editorial metadata only — never as the skill index, which is always the repository tree./sanity-io/agent-toolkit.md, and each skill at its own URL..md3 files · 17 KB
Everything this skill ships beside its prose. All of it is set here, as subchapters of skill 3.
Everything else published alongside the skill.