npx skills add ...
npx skills add sanity-io/agent-toolkit --skill portable-text-conversion
npx skills add sanity-io/agent-toolkit --skill portable-text-conversion
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.
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:
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.