BlockNote DocsFeaturesExportTypst

Typst Export

It's possible to export BlockNote documents to Typst markup — for example to post-process documents in a Typst workflow, or to compile them to PDF with your own Typst toolchain (including server-side). This exporter is also the foundation of the PDF exporter, which compiles its output to accessible, tagged PDF/UA-1 in the browser.

This feature is provided by the @blocknote/xl-typst-exporter. xl- packages are fully open source, but released under a copyleft license. A commercial license for usage in closed source, proprietary products comes as part of the Business subscription.

First, install the @blocknote/xl-typst-exporter package:

npm install @blocknote/xl-typst-exporter

Then, create an instance of the TypstExporter class:

import {
  TypstExporter,
  typstDefaultSchemaMappings,
} from "@blocknote/xl-typst-exporter";

// Create the exporter
const exporter = new TypstExporter(editor.schema, typstDefaultSchemaMappings);

// Convert the blocks to a Typst source string
const typst = await exporter.toTypst(editor.document, {
  title: "My document",
  lang: "en",
});

// The document's images, keyed by the virtual path referenced in the markup -
// map these into your Typst compiler's filesystem before compiling
const assets = exporter.assetFiles;

toTypst takes the same per-document options as the PDF exporter's export methods (title, author, language, paper size, margins, page header/footer) — see customizing the PDF — and the constructor takes the same exporter options.

Custom mappings

Mappings convert schema elements into Typst markup strings, and they are shared with the PDF exporter — one custom-block mapping serves both formats. See custom mappings on the PDF page; the math and diagram blocks ship ready-made Typst mappings from their typst-exporter subpaths.