Do I need to build a Portable Text editor from scratch?

1 replies
Last updated: May 27, 2020
So if I understand correctly, Portable Text was published as an open standard, with some open source tools to convert Portable Text to other formats. But if I wanted build a rich text editor that spits out Portable Text, I have to write that from scratch, correct?
AI Update

Good news - you don't have to build everything from scratch! While the Portable Text specification itself is published as an open standard, there are also open-source editor components you can use.

The @portabletext/editor package is available on npm and provides the core editing functionality for creating Portable Text. This is the modern, actively maintained editor package that powers the rich text editing experience in Sanity Studio.

Important context:

The editor is primarily designed for use within the Sanity ecosystem, so using it standalone requires some integration work:

  • You'll need to handle your own schema definitions and validation
  • Storage and persistence logic is up to you
  • It's built for React environments
  • Documentation focuses mainly on Studio integration and customization
  • You'll be working with lower-level primitives rather than a plug-and-play solution

Alternative approaches to consider:

  1. Embed Sanity Studio - Since Studio is just a React app distributed as an npm package, you can embed it directly in your application if you want the full editing experience with everything wired up

  2. Use Sanity as your editor - Many teams use Sanity Studio as their editing interface (even if their content is consumed elsewhere) because it handles all the complexity of schema validation, real-time collaboration, and content management

  3. Adapter approach - Some developers have built adapters for other rich text editors (like TipTap) to output Portable Text format, though these are typically community efforts

The broader ecosystem:

For rendering Portable Text (not editing), there are well-maintained libraries like @portabletext/react and similar packages for other frameworks. Tools like @sanity/block-tools help convert HTML and other formats into Portable Text.

So while you can build an editor that outputs Portable Text using the open-source packages, it's definitely more straightforward within the Sanity ecosystem where all the pieces integrate seamlessly. If you're building a custom CMS or editing interface, @portabletext/editor is your starting point, but expect to do significant integration work.

Show original thread
1 reply
Per today, yes, probably.
Here’s a crude proof of concept
https://codesandbox.io/s/portable-text-on-slate-proof-of-concept-l6xmo
That being said. We have just refactored Sanity’s rich text editor, and if I'm of the correct impression, it's not that far from being able to be used outside of the studio as well. It’s at least an ambition that we have.

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?