HTML
The functions to export to HTML are considered "lossy"; some information might be dropped when you export Blocks to HTML.
To serialize Blocks to a non-lossy format (for example, to store the contents of the editor in your backend), simply export the built-in Block format using JSON.stringify(editor.document)
.
Export to BlockNote HTML
Use editor.blocksToFullHTML
to export the entire document with all structure, styles and formatting.
The exported HTML is the same as BlockNote would use to render the editor, and includes all structure for nested blocks.
For example, you an use this for static rendering documents that have been created in the editor. Make sure to include the same stylesheets when you want to render the output HTML (see example).
async blocksToFullHTML(blocks?: Block[]): Promise<string>;
// Usage
const HTMLFromBlocks = await editor.blocksToFullHTML(blocks);
blocks:
The blocks to convert. If not provided, the entire document (all top-level blocks) is used.
returns:
The blocks, exported to an HTML string.
Export to Interoperable HTML
The editor exposes functions to convert Blocks to and from HTML for interoperability with other applications.
Converting Blocks to HTML this way will lose some information such as the nesting of nodes in order to export a simple HTML structure.
Use blocksToHTMLLossy
to export Block
objects to an HTML string:
async blocksToHTMLLossy(blocks?: Block[]): Promise<string>;
// Usage
const HTMLFromBlocks = await editor.blocksToHTMLLossy(blocks);
blocks:
The blocks to convert. If not provided, the entire document (all top-level blocks) is used.
returns:
The blocks, exported to an HTML string.
To better conform to HTML standards, children of blocks which aren't list items are un-nested in the output HTML.
Demo