Hello.

article

Convert markdown stories to richtext through the Storyblok MCP, and diff every push

2026-11-06 · Storyblok, Astro and Cloudflare Workers

TL;DR Stories whose text is markdown inside blocks can be converted to Storyblok richtext offline and pushed as drafts through Storyblok's MCP server. The MCP has no file input, so every payload is retyped and slips happen: compare each draft with the converter output and re-push until there are 0 differences. Turn markdown-it's typographer off.

Moving 20 stories through the Storyblok MCP produced typing slips in two of them. One was a URL that came out as api.github.com/repos/… instead of github.com/…. The text still read fine.

The migration is five steps, and only one needs a human

The old blog was a Nuxt 2 static export with URLs of the form /a/<slug>/. Its space held 16 articles and 4 pages (home, about, license, legal notice). The old Article kept its text in a body field of nested bloks: ArticleText held markdown, ArticleCode a code string, ArticleImage an image with a caption and ArticleQuote a quote with a link. The new Article has one richtext field, content, and a short list of allowed interactive bloks.

From markdown bloks to richtext

Every story saved as JSON before any write.

1 / 5

The same flow as text:

  1. Save each original story, using a field subset or stripping preview_token from full responses.

  2. Convert the saved JSON to richtext on disk.

  3. Push the result as a draft. The live story stays up.

  4. Read the draft back from the CDN and compare it with the file from step 2.

  5. Publish only what compares clean, then compare again.

Markdown converts with a library, minus its typographer

Storyblok publishes @storyblok/richtext with markdownToStoryblokRichtext and htmlToStoryblokRichtext, so there is no markdown parser to write. One option inside it has to go.

const md = new MarkdownIt({ html: false, linkify: true, typographer: false, breaks: true });
const markdownToStoryblokRichtext = (src) => htmlToStoryblokRichtext(md.render(src));

The other mappings are small:

The check compares text, not layout: plain text from the old side (rendered with marked) against plain text from the new richtext, all whitespace stripped. 20 of 20 passed. That proves text and order, not nesting or heading levels, so open the pages too. In caching-in-ga the site's heading normalization (smallest heading becomes h2, jumps clamped to one level) turned sibling sections into parent and child, because the article opens with a deeper heading than it later uses.

The MCP retypes every payload, so every push needs a diff

The MCP has no file input. The converted stories, about 277 KB together, had to be typed into the calls, so each one is retyped. Slips came out of two of the 20 stories:

The defence is a fixed order. Step through it and note where each slip would have gone live without the diff.

Step 1 of 5

Back up the originals

Save every story as JSON before any write. 19 were saved as a field subset and one in full with preview_token stripped.

The _editable strip matters. The draft CDN adds a <!--#storyblok#...--> marker to blok bodies, and 9 of the 20 stories differed from the converter output on that alone. The mechanical diff caught the slips in a/github-actions-context, and only versions with 0 differences were published.

Dates fell back to the wrong field for 7 of 16 articles

A story has three date candidates: a date field, created_at and first_published_at. The first version of the new site fell back to first_published_at when date was missing. That was wrong for 7 of the 16 articles, and production showed those dates for a while after the cutover.

It looked like a timezone bug, because a preview and a production render of the same article were one day apart. It was not. Datetime fields in this space come back in UTC and the site renders the calendar day in Europe/Vienna. Migrated dates are stored as YYYY-MM-DD 00:00, which is 01:00 or 02:00 in Vienna, the same day.

Old URLs keep working with a middleware

The old URLs were /a/<slug>/ with a trailing slash, and /a/<slug> answered with a 301 to the slash form. A middleware keeps both (part 2 explains why it is not Astro's trailingSlash: 'always'). On the first deployment /a/adb-tricks/ returned 200 and /a/adb-tricks returned 301. Series have their own pages, /s/<series>/, and series parts are listed under the series, not individually on the index.

Deleting the old components is its own stage

With the content moved, the old body field and its components could go. Deleting components is destructive, so it ran in two stages, the second only after an explicit go from me. First, without touching the schema:

Then the schema change: re-check that none of the eight old components is used at any depth, remove only the body field from Article and Page, and delete the eight components one at a time, re-listing after each. A read-only listing confirms the result:

listManagementComponents after the cleanup
⏺ execute_readonly operation="listManagementComponents" parameters={"space_id":93903} fields=["components.name"] region="eu"
{"components":[{"name":"Article"},{"name":"Callout"},{"name":"CodeTab"},{"name":"CodeTabs"},{"name":"EdgeProbe"},{"name":"Figure"},{"name":"FlowNode"},{"name":"page"},{"name":"Page"},{"name":"RequestFlow"},{"name":"Series"},{"name":"Step"},{"name":"Steps"},{"name":"Terminal"},{"name":"TermLine"}]}

ArticleCode, ArticleImage, ArticleQuote, ArticleReferences, ArticleText, intro, Newsletter and TextSection are gone. Lowercase page stays.

The schema backup was typed from MCP output, so the same no-file-input risk applies to it, and it misses the preview_field that intro had.

Try it yourself

Paste this into Claude Code with the Storyblok MCP connected. It converts offline, pushes drafts and diffs them, and leaves publishing and schema changes to you.

Convert Storyblok stories to richtext, push drafts, diff to 0

Convert my Storyblok stories from markdown bloks to a richtext field and push them as drafts. Space <space-id>, region <region>, stories <list of full_slugs>, target field <richtext-field>.

Rules:
- Never print, log or commit a token. Read STORYBLOK_PREVIEW_TOKEN and STORYBLOK_REGION from the environment and report only counts and status codes.
- Drafts only: updateStory with publish: false. Do not publish, unpublish, delete or change the schema.
- Use search, then describe, before every MCP operation, and pass fields to keep responses small.

Steps. Finish each one and show the result before the next:
1. Back up every story as JSON to <backup-dir> (strip preview_token). Write nothing to Storyblok yet.
2. Convert the saved markdown to richtext JSON in <out-dir> with @storyblok/richtext. Build markdown-it with typographer: false and pass its HTML to htmlToStoryblokRichtext. Check that plain text, whitespace stripped, equals the old side. Tell me which stories failed.
3. Ask me before the first push. Then push each story as a draft. The MCP has no file input, so you retype each payload: expect slips.
4. Write a read-only script that fetches each draft from the CDN with ?version=draft, removes _uid, attrs.id and _editable, and compares it with the file in <out-dir>. Print the number of differences per story and the first differing path.
5. Re-push every story with differences and diff again until all report 0. Do not publish.
6. List the stories ready to publish and what you did not verify.

Requirements: the Storyblok MCP (OAuth, no token), a preview access token in your environment, and the source content on disk.

Good to know

Run your diff on one story before you push the other nineteen.