Join us live Sept. 27 – How Sanity and Vercel powered Morning Brew's transformation –>

Best way to convert HTML to a PortableText object?

5 replies
Last updated: Dec 3, 2020

Hi folks! Does anyone know a simple way of converting HTML to a PortableText object? A library of some sorts? Im trying to import some data from an old site into Sanity, and smdm of the content has been built with a wysiwyg editor saving it as html...

Dec 3, 2020, 9:31 AM

sanity have their own lib for it πŸ™‚ https://www.npmjs.com/package/@sanity/block-tools

Dec 3, 2020, 9:36 AM

Amazing! I have no idea how i managed to miss that - only found libs for going the other way around πŸ˜„ Thanks a lot

user V
!

Dec 3, 2020, 9:37 AM

no problem! it also support custom rules if you want to convert some tags to a custom block type. quite handy πŸ‘Œ

Dec 3, 2020, 9:39 AM

Might be useful to read through a higher-level guide like https://www.sanity.io/guides/how-to-migrate-your-html-blog-content-from-ghost β€” even if it’s not the same source as for your migration it probably covers relevant issues πŸ™‚

Dec 3, 2020, 9:39 AM

It looks great - both the library and the post - i was going to run the import through the api, but converting all the data to ndjson and using the cli seems like a better idea! Thank you both! ❀️

Dec 3, 2020, 9:43 AM

Sanity.io: Get the most out of your content

Sanity.io is a platform to build websites and applications. It comes with great APIs that let you treat content like data. Give your team exactly what they need to edit and publish their content with the customizable Sanity Studio. Get real-time collaboration out of the box. Sanity.io comes with a hosted datastore for JSON documents, query languages like GROQ and GraphQL, CDNs, on-demand asset transformations, presentation agnostic rich text, plugins, and much more.

Don't compromise on developer experience. Join thousands of developers and trusted companies and power your content with Sanity.io. Free to get started, pay-as-you-go on all plans.