Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
sanity-io avatar

Portable Text Conversion

  • 1.5k installs
  • 171 repo stars
  • Updated July 29, 2026
  • sanity-io/agent-toolkit

Portable Text Conversion is a backend integration toolkit that transforms HTML and Markdown content into Sanity's Portable Text block format for content pipelines and migrations.

About

Portable Text Conversion toolkit enables developers to transform HTML and Markdown content into Sanity's Portable Text format for content migration, pipeline ingestion, and programmatic document creation. Provides three conversion approaches: markdownToPortableText via @portabletext/markdown (recommended for Markdown), htmlToBlocks via @portabletext/block-tools (for HTML migration), and manual block construction from APIs or databases. Covers Portable Text specification including block structure, span annotations, mark definitions, and list handling with proper key generation and type assignment.

  • Three conversion methods: markdownToPortableText, htmlToBlocks, and manual programmatic construction
  • Comprehensive Portable Text specification documentation with JSON structure, key rules, and annotation patterns
  • Supports content migration from legacy CMSs and external data sources via block-tools and markdown packages
  • Convert HTML and Markdown content into Portable Text blocks for content migration and pipeline ingestion
  • Convert HTML and Markdown content into Portable Text blocks for content migration and pipeline ingestion

Portable Text Conversion by the numbers

  • 1,451 all-time installs (skills.sh)
  • +90 installs in the week ending Aug 2, 2026 (Skillselion tracking)
  • Ranked #328 of 4,348 Backend & APIs skills by installs in the Skillselion catalog
  • Security screen: MEDIUM risk (skills.sh audit)
  • Data as of Aug 2, 2026 (Skillselion catalog sync)
At a glance

portable-text-conversion capabilities & compatibility

Capabilities
markdown to portable text · html to portable text · block construction · content migration · format conversion · annotation mapping
Use cases
api development · data analysis · refactoring
Runs
Runs locally
Pricing
Free
From the docs

What portable-text-conversion says 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
skill:sanity-io/agent-toolkit#portable-text-conversion
npx skills add https://github.com/sanity-io/agent-toolkit --skill portable-text-conversion

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs1.5k
repo stars171
Security audit2 / 3 scanners passed
Last updatedJuly 29, 2026
Repositorysanity-io/agent-toolkit

What it does

Convert HTML and Markdown content into Portable Text blocks for content migration and pipeline ingestion

Who is it for?

Migrating content from legacy CMSs, importing HTML or Markdown into Sanity, building content pipelines that ingest external content, converting rich text between formats, programmatically creating Portable Text documents

Skip if: Real-time streaming content transformation at scale, client-side rich text editing, non-structured content formats

When should I use this skill?

You need to ingest external HTML or Markdown content into Sanity, migrate legacy CMS content, or build automated content pipelines with format conversion

What you get

Content is successfully converted from external formats into standardized Portable Text blocks ready for Sanity ingestion and storage

  • Portable Text block JSON
  • migration-ready content arrays

By the numbers

  • Three main conversion approaches: markdownToPortableText, htmlToBlocks, and manual construction
  • PT blocks contain required properties: _type, _key, and format-specific fields like style, children, markDefs
  • Supports hierarchical list nesting via level property (1, 2, 3+) on block listItem types

Files

SKILL.mdMarkdownGitHub ↗

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

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.

Related skills

How it compares

Use portable-text-conversion for HTML-rich legacy exports; switch to @portabletext/markdown when the source is already Markdown.

FAQ

Which conversion method should I use for Markdown content?

Use markdownToPortableText from @portabletext/markdown package - it is the recommended approach for Markdown sources and handles standard Markdown syntax conversion to PT blocks.

What are the key rules for Portable Text block construction?

Every block and span requires a unique _key within the array, _type identifies block category (block for text, or custom types), markDefs holds annotation data, and marks on spans reference markDefs._key or are decorator strings. Lists use listItem (bullet/number) and level prope

Can I manually construct Portable Text blocks from APIs or databases?

Yes, manual construction is the third approach - build PT blocks programmatically from any source by following the Portable Text specification structure and ensuring proper key generation and type assignment.

Is Portable Text Conversion safe to install?

skills.sh reports 2 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.

Backend & APIsbackendintegrationsdevops

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.