portable-text-serialization

Portable Text in React, Svelte, Vue, Astro, HTML, Markdown und Klartext rendern und serialisieren. Verwenden Sie dies bei der Implementierung von Portable Text Rendering in einem beliebigen Frontend…

npx skills add https://github.com/sanity-io/agent-toolkit --skill portable-text-serialization

Portable Text Serialization

Render Portable Text content across frameworks using the @portabletext/* library family. Each library follows the same component-mapping pattern: you provide a components object that maps PT node types to framework-specific renderers.

Portable Text Structure (Quick Reference)

PT is an array of blocks. Each block has _type, optional style, children (spans), markDefs, listItem, and level.

Root array
├── block (_type: "block")
│   ├── style: "normal" | "h1" | "h2" | "blockquote" | ...
│   ├── children: [span, span, ...]
│   │   └── span: { _type: "span", text: "...", marks: ["strong", "<markDefKey>"] }
│   ├── markDefs: [{ _key, _type: "link", href: "..." }, ...]
│   ├── listItem: "bullet" | "number" (optional)
│   └── level: 1, 2, 3... (optional, for nested lists)
├── custom block (_type: "image" | "code" | any custom type)
└── ...more blocks

Marks come in two forms:

  • Decorators: string values in marks[] like "strong", "em", "underline", "code"
  • Annotations: keys in marks[] referencing entries in markDefs[] (e.g., links, internal references)

Component Mapping Pattern (All Frameworks)

Every @portabletext/* library accepts a components object with these keys:

KeyRendersProps/Data
typesCustom block/inline types (image, code, CTA)value (the block data)
marksDecorators + annotationschildren + value (mark data)
blockBlock styles (h1, normal, blockquote)children
listList wrappers (ul, ol)children
listItemList itemschildren
hardBreakLine breaks within a block

Framework-Specific Rules

Read the rule file matching your framework:

  • React / Next.js: rules/react.md@portabletext/react or next-sanity
  • Svelte / SvelteKit: rules/svelte.md@portabletext/svelte
  • Vue / Nuxt: rules/vue.md@portabletext/vue
  • Astro: rules/astro.mdastro-portabletext
  • HTML (server-side): rules/html.md@portabletext/to-html
  • Markdown: rules/markdown.md@portabletext/markdown
  • Plain text extraction: rules/plain-text.md@portabletext/toolkit

Additional Community Serializers

These are listed on portabletext.org but don't have dedicated rule files:

TargetPackage
React Native@portabletext/react-native-portabletext
React PDF@portabletext/react-pdf-portabletext
Solidsolid-portabletext
Qwikportabletext-qwik
Shopify Liquidportable-text-to-liquid
PHPsanity-php (SanityBlockContent class)
Pythonportabletext-html
C# / .NETdotnet-portable-text
Dart / Flutterflutter_sanity_portable_text

Common Patterns (All Frameworks)

Custom Types Need Explicit Components

PT renderers only handle standard blocks by default. Custom types (image, code, callToAction, etc.) require explicit component mappings — they won't render otherwise.

Keep Components Object Stable

In React/Vue, define components outside the render function or memoize it. Recreating on every render causes unnecessary re-renders.

Handle Missing Components Gracefully

All libraries accept onMissingComponent to control behavior when encountering unknown types:

  • false — suppress warnings
  • Custom function — log or report

Querying PT with GROQ

Always expand references inside custom blocks:

body[]{
  ...,
  _type == "image" => {
    ...,
    asset->
  },
  markDefs[]{
    ...,
    _type == "internalLink" => {
      ...,
      "slug": @.reference->slug.current
    }
  }
}

Mehr Skills von sanity-io

sanity-migration
sanity-io
Plant, implementiert und überprüft Migrationen von anderen CMS- und Contentsystemen nach Sanity. Verwenden bei Migration oder Replatforming zu Sanity von AEM, Adobe Experience Manager, Contentful, Strapi, Webflow, WordPress, Payload, Drupal, Markdown/MDX/Frontmatter-Dateien, WXR/XML-Exporten, CMS-APIs, Datenbank-Dumps, statischem HTML oder beim Entwerfen von Extraktions-, Transformations-, Portable-Text-Konvertierungs-, Asset-Migrations-, Redirect-, Validierungs- und Cutover-Workflows.
officialdevelopmentdatabase
create-agent-with-sanity-context
sanity-io
Erstelle KI-Agenten mit strukturiertem Zugriff auf Sanity-Inhalte über den Agent Context. Verwende dies beim Einrichten eines Sanity-gestützten Chatbots oder beim Verbinden eines KI-Assistenten mit Sanity…
official
dial-your-context
sanity-io
Interaktive Sitzung zur Erstellung von Inhalten für das Instructions-Feld eines Sanity Agent Context MCP. Verwenden Sie diese Fähigkeit, wenn Benutzer die Optimierung des Agentenkontexts erwähnen, Verbesserung…
official
optimize-agent-prompt
sanity-io
Optimieren Sie Ihren Sanity Agent Context Agent durch geführte Konversation. Wandelt Erkundungsdaten in produktionsreife Anweisungen um und erstellt einen System-Prompt…
official
shape-your-agent
sanity-io
Interaktive Sitzung zur Erstellung eines System-Prompts für einen KI-Agenten, der von Sanity Agent Context MCP betrieben wird. Verwenden Sie diese Fähigkeit, wenn Benutzer die Persönlichkeit des Agenten definieren möchten,…
official
content-experimentation-best-practices
sanity-io
Strukturierte Anleitung für die Konzeption, Durchführung und Analyse von Content-Experimenten zur Verbesserung von Conversion und Engagement. Behandelt Hypothesen-Frameworks, Metrikauswahl, Stichprobengrößenberechnung und statistische Signifikanztests bei A/B- und multivariaten Experimenten. Enthält detaillierte Ressourcen zu p-Werten, Konfidenzintervallen, Power-Analyse und Bayes'schen Methoden zur Ergebnisinterpretation. Bietet CMS-Integrationsmuster für die Verwaltung von Varianten auf Feldebene und die Anbindung externer...
official
content-modeling-best-practices
sanity-io
Strukturierte Content-Modellierungsanleitung für Schema-Design, Wiederverwendbarkeit und Multi-Channel-Auslieferung. Behandelt Kernprinzipien: Behandlung von Inhalten als Daten statt als Seiten, Aufrechterhaltung einzelner Quellen der Wahrheit, Design für zukünftige Kanäle und Optimierung für Redaktionsworkflows. Enthält Entscheidungsrahmen für Referenzen versus eingebettete Objekte, Trennung von Belangen und Content-Wiederverwendungsmuster. Bietet Taxonomie- und Klassifikationsanleitung für flache, hierarchische und facettierte Ansätze. Gilt für...
official
portable-text-conversion
sanity-io
Konvertieren Sie HTML- und Markdown-Inhalte in Portable Text-Blöcke für Sanity. Verwenden Sie dies beim Migrieren von Inhalten aus Legacy-CMS, beim Importieren von HTML oder Markdown in Sanity,…
official