How AI is powering better personalization in e-commerce [with Vercel]. Sign up now

Converting Markdown to Sanity: HTML intermediary vs direct conversion?

32 repliesLast updated: Nov 30, 2025

yeah the markdown process is quite daunting. Working on that now myself. I’m considering generating html from the markdown, then to Sanity but not quite sure if that’s better or not than trying to convert markdown directly. This is getting me much of the way: https://www.sanity.io/guides/how-to-migrate-your-html-blog-content-from-ghost
AI Update

I hear you—the markdown migration process can definitely be tricky! You're actually on a good path, and there are multiple approaches depending on your content structure.

Markdown → HTML → Portable Text vs. Direct Markdown → Portable Text

Both approaches work, but here's what to consider:

Going the HTML route (what you're exploring):

Direct markdown route:

My recommendation: Stick with the HTML approach you're exploring. Here's why:

Quick implementation pattern:

import {htmlToBlocks} from '@sanity/block-tools'
import {JSDOM} from 'jsdom'
import {marked} from 'marked' // or your preferred markdown parser

// Convert markdown to HTML first
const html = marked(yourMarkdownContent)

// Then to Portable Text
const blocks = htmlToBlocks(html, blockContentType, {
  parseHtml: html => new JSDOM(html).window.document
})

Pro tips:

The two-step process (markdown → HTML → Portable Text) gives you more control and better debugging when things don't convert perfectly. Good luck with your migration!

Show original thread
32 replies

Was this answer helpful?

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.

Related contributions