🚀 BlockNote AI is here! Access the early preview.
BlockNote Docs/Foundations/Storage Formats

Storage Formats

BlockNote is compatible with a few different storage formats, each with its own advantages and disadvantages. This guide will show you how to use each of them.

Overview

When it comes to editors, formats can be tricky. The editor needs to be able to both read and write to each format.

If elements are not preserved in this transformation, we call the conversion lossy. While we'd ideally support every format, other formats may not support all BlockNote content.

See the table below for a summary of the formats we support and their lossiness:

FormatImportExportPro Only
BlockNote JSON (editor.document)
BlockNote HTML (blocksToFullHTML)
Standard HTML (blocksToHTMLLossy)✅ (lossy)✅ (lossy)
Markdown (blocksToMarkdownLossy)✅ (lossy)✅ (lossy)
PDF (@blocknote/xl-pdf-exporter)
DOCX (@blocknote/xl-docx-exporter)
ODT (@blocknote/xl-odt-exporter)
Email (@blocknote/xl-email-exporter)

Tip: It's recommended to use BlockNote JSON (editor.document) for storing your documents, as it's the most durable format & guaranteed to be lossless.

Working with Blocks (JSON)

BlockNote uses a JSON structure (an array of Block objects) as its native format. This is the recommended way to store documents as it's lossless, preserving the exact structure and all attributes of your content.

Saving Blocks

The best way to get the latest content is to use the editor.onChange callback if using vanilla JS or useEditorChange hook if using React. This function is called every time the editor's content changes.

import React from "react";
import { ,  } from "@blocknote/react";
import {  } from "@blocknote/mantine";


export default function () {
  const  = ();

  (() => {
    // The current document content as a string
    const  = .(.);

    ();
  }, );

  return < ={} />;
}

Loading Blocks

To load content, you can use the initialContent prop when creating the editor. You can pass the array of Block objects you previously saved.

import { useCreateBlockNote } from "@blocknote/react";
import type { Block } from "@blocknote/core";
import { BlockNoteView } from "@blocknote/mantine";

export default function App({
  initialContent,
}: {
  initialContent?: Block<any, any, any>[];
}) {
  const editor = useCreateBlockNote({
    initialContent,
  });

  return <BlockNoteView editor={editor} />;
}

Working with HTML

BlockNote provides utilities to convert content between Block objects and HTML. Note that converting to standard HTML can be lossy.

Saving as HTML

To convert the document to an HTML string, you can use editor.blocksToFullHTML(blocks: Block[]):

import React from "react";
import { ,  } from "@blocknote/react";
import {  } from "@blocknote/mantine";


export default function () {
  const  = ();

  (async () => {
    const  = await .(.);
    // You can now save this HTML string
    ();
  }, );

  return < ={} />;
}

The editor.blocksToFullHTML method will output HTML in the BlockNote internal format. If you want to export to standard HTML, you can use editor.blocksToHTMLLossy instead.

Loading from HTML

To load HTML content, you first need to convert it to an array of Block objects using editor.tryParseHTMLToBlocks(). Then, you can insert it into the editor.

import React from "react";
import {  } from "react";
import {  } from "@blocknote/react";
import {  } from "@blocknote/mantine";

const  = "<p>This is a paragraph.</p>";

export default function () {
  const  = ();

  (() => {
    // Replaces the blocks on initialization
    // But, you can also call this before rendering the editor
    async function () {
      const  = await .();
      .(., );
    }
    ();
  }, []);

  return < ={} />;
}

Working with Markdown

BlockNote also supports converting to and from Markdown. However, converting to and from Markdown is a lossy conversion.

Saving as Markdown

To convert the document to a Markdown string, you can use editor.blocksToMarkdownLossy():

import React from "react";
import { ,  } from "@blocknote/react";
import {  } from "@blocknote/mantine";


export default function () {
  const  = ();

  (async () => {
    const  = await .(.);
    // You can now save this Markdown string
    ();
  }, );

  return < ={} />;
}

Loading from Markdown

To load Markdown content, you first need to convert it to an array of Block objects using editor.tryParseMarkdownToBlocks(). Then, you can insert it into the editor.

import React from "react";
import {  } from "react";
import {  } from "@blocknote/react";
import {  } from "@blocknote/mantine";

const  = "This is a paragraph with **bold** text.";

export default function () {
  const  = ();

  (() => {
    async function () {
      const  = await .();
      .(., );
    }
    ();
  }, []);

  return < ={} />;
}

Export Only

BlockNote can also export to these additional formats: