portable-text-conversion

द्वारा sanity-io

HTML और Markdown सामग्री को Sanity के लिए Portable Text ब्लॉक में बदलें। लीगेसी CMS से सामग्री माइग्रेट करते समय, Sanity में HTML या Markdown आयात करते समय उपयोग करें,…

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

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.

sanity-io की और Skills

performance-optimization
sanity-io
एप्लिकेशन के प्रदर्शन को अनुकूलित करता है। इसका उपयोग तब करें जब प्रदर्शन आवश्यकताएं हों, जब आपको प्रदर्शन में गिरावट का संदेह हो, या जब कोर वेब वाइटल्स या लोड समय...
official
rxjs-like-a-pro
sanity-io
यह कौशल आपको ऐसा RxJS कोड लिखने में मदद करता है जो स्वाभाविक, संयोजनीय और सामान्य कमियों से मुक्त हो। मुख्य दर्शन: तर्क को ऑब्ज़र्वेबल श्रृंखला में रखें। जब भी आप .subscribe() का उपयोग करने जाएं, तो पूछें कि क्या वह कार्य .pipe() के अंदर एक रूपांतरण के रूप में व्यक्त किया जा सकता है।
official
find-skills
sanity-io
उपयोगकर्ताओं को एजेंट कौशल खोजने और स्थापित करने में मदद करता है जब वे ऐसे प्रश्न पूछते हैं जैसे "मैं X कैसे करूं", "X के लिए कोई कौशल खोजें", "क्या कोई ऐसा कौशल है जो...", या व्यक्त करते हैं...
official
next-cache-components
sanity-io
Next.js 16 कैश घटक - PPR, use cache निर्देश, cacheLife, cacheTag, updateTag
official
vercel-react-best-practices
sanity-io
React और Next.js प्रदर्शन अनुकूलन दिशानिर्देश Vercel Engineering से। इस कौशल का उपयोग React/Next.js को लिखने, समीक्षा करने या रीफैक्टर करते समय किया जाना चाहिए…
official
frontend-design
sanity-io
उच्च डिज़ाइन गुणवत्ता के साथ विशिष्ट, उत्पादन-स्तर के फ्रंटएंड इंटरफ़ेस बनाएं। इस कौशल का उपयोग तब करें जब उपयोगकर्ता वेब घटकों, पृष्ठों या... बनाने के लिए कहे।
official
plugin-transfer
sanity-io
एजेंटों को कॉपी-प्लगइन जनरेटर वर्कफ़्लो के साथ मौजूदा प्लगइन को इस मोनोरिपो में स्थानांतरित करने का मार्गदर्शन देता है।
official
test-studio-script-runner
sanity-io
dev/test-studio स्क्रिप्ट रनर टूल की व्याख्या करता है। इसका उपयोग तब करें जब dev/test-studio/src/script-runner में स्क्रिप्ट जोड़ना, संपादित करना, चलाना या दस्तावेज़ीकरण करना हो, या जब...
official