Export serializer
HTML for a block that is not in the core map.
Serializers live on the add-on. renderDocument uses them for that call only, including from Node. A second editor does not see them. See Server rendering.
This page's code block is examples/recipes/serializer.ts. pnpm --dir docs typecheck compiles that file and fails if this block drifts.
import type { ReactNode } from "react";
import type { JSONContent } from "@tiptap/core";
import { createBlockcnEditor, defineAddon } from "@/components/editor/preset";
import { renderDocument } from "@/lib/export/serialize";
const banner = defineAddon<ReactNode>({
id: "banner",
extensions: [],
serializers: {
banner: { html: (node) => `<section>${String(node.attrs?.label ?? "")}</section>` },
},
});
export const kit = createBlockcnEditor({ addons: [banner] });
export function bannerHtml(json: JSONContent) {
return renderDocument(json, { addons: [banner] });
}