πŸ‘‹ Next.js Conf 2024: Come build, party, run, and connect with us! See all events

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– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?