Moving a CMS from CKEditor to Tiptap without losing old content

· 2 min read

On a CMS I work on, we replaced CKEditor with Tiptap across several content types, such as articles and events. Putting a new editor on the screen is the straightforward part. The part that needs care is everything already saved.

CKEditor stores HTML. Tiptap works with a JSON document that follows its schema. You can feed Tiptap HTML and it will parse it, but storing JSON gives you content the editor fully understands, so we converted the existing HTML to JSON.

Converting stored HTML

Tiptap's @tiptap/html package has generateJSON, which parses HTML with the same extensions your editor uses:

import { generateHTML, generateJSON } from "@tiptap/html";
import StarterKit from "@tiptap/starter-kit";
import Link from "@tiptap/extension-link";
import Image from "@tiptap/extension-image";

// The exact list the editor uses, shared in one module
export const extensions = [StarterKit, Link, Image];

export function toTiptap(html: string) {
  return generateJSON(html, extensions);
}

The important word is same. The editor and the conversion have to share one list of extensions. If the editor supports images and the conversion doesn't, images vanish during the migration and nobody notices until a page looks empty.

The thing to check: what the schema drops

Tiptap is built on ProseMirror, and ProseMirror only keeps what its schema knows. Any tag without a matching extension is dropped while parsing: an embed, a table, a <span> with inline styles. CKEditor content tends to collect exactly those over the years.

So before converting anything for real, it's worth running the conversion over every stored record and comparing a rough measure of content before and after:

function visibleText(html: string) {
  return html.replace(/<[^>]+>/g, " ").replace(/\s+/g, " ").trim();
}

function lostContent(html: string) {
  const before = visibleText(html);
  const after = visibleText(generateHTML(toTiptap(html), extensions));
  return after.length < before.length * 0.98 ? { before, after } : null;
}

Any record this flags either needs an extension added (tables are a common one) or a deliberate decision that the dropped markup doesn't matter. Text length won't catch a missing image, so count <img> and <iframe> tags the same way.

Everything else that touches the content

The editor isn't the only thing that reads stored content. In our case the export and import feature had to learn the new format too. Anything that renders, searches, exports or imports the field needs the same update, and it's easy to miss one because it isn't on the editing screen.

If I did it again

I'd write the extension list first and treat it as the contract: the editor, the conversion, the rendering on the website and the import/export all use that one list. Most migration surprises come from two of those quietly disagreeing.