Index of every page on this site: llms.txt
All skills
sanity-io avatar

/portable-text-conversion

@828641f official
by Sanitysanity-io/agent-toolkit201 stars
32
Run it yourself

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.

Use this Skill: https://skilld.dev/gh/sanity-io/agent-toolkit/portable-text-conversion

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

SKILL.md

≈130 tokens for metadata: the name and description. ≈517 when used: this file. ≈4.4k more on demand in 3 files.

Description uses 6.5% of example budget

Before choosing a Skill, your Agent reads its name and description. All available Skills share that space.

  • A shorter description leaves more room for other Skills. This entry exceeds our 1% size suggestion.

In our Claude Code example, all Skill names and descriptions share 8,000 characters. This Skill uses ≈519 characters, or 6.5%.

The 1% threshold is a size suggestion. Longer descriptions can still fit.

Your model, settings, and other Skills decide how much text your Agent can read.

Example settings and source

The example uses a 200k-token context and default Claude Code settings. The count includes the name, description, separators, and when_to_use when present. Codex also counts local file paths.

Skit's source and limits: Codex 0.160.1, Claude Code 2.1.292.

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.

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts2mo4 checks · Risk SAFE
  • Gen Agent Trust Hub2mo

    This skill provides documentation and code examples for converting HTML and Markdown content into Sanity's Portable Text format using official and well-known libraries.

  • Socket2mo

    No alerts

  • Snyk2mo

    Risk: LOW · No issues

  • ZeroLeaks7mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 828641f. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated 9 months ago
metadata
{
  "author": "sanity",
  "version": "1.0.0"
}
  • sanity
  • portable-text
  • html
  • markdown
  • content-migration
  • cms
  • portabletext
  • block-tools

README badge

README badge for sanity-io/agent-toolkit/portable-text-conversion

Converts HTML and Markdown content into Portable Text blocks for Sanity using @portabletext/markdown and @portabletext/block-tools. Useful for migrating content from legacy CMSs, importing external rich text into Sanity, or programmatically building Portable Text documents from various sources.

Generated from the current SKILL.md.

Does this skill work with HTML and Markdown, or just one format?
It covers both. Use @portabletext/markdown for Markdown sources, @portabletext/block-tools for HTML sources, or manually construct blocks from any other format.
What is Portable Text?
Portable Text is Sanity's JSON-based rich text format. It represents content as an array of typed blocks (text blocks, images, custom types) with annotations, marks, and nested structures.
Can I convert from APIs or databases, not just HTML/Markdown?
Yes. The skill includes manual block construction rules for building Portable Text blocks programmatically from any data source.
Is @sanity/block-tools the correct package to use?
No. Use @portabletext/block-tools instead; @sanity/block-tools is the legacy package name. The API is the same.

Generated from the current SKILL.md. These answers refresh after source changes.