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 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?