文档结构
了解文档(富文本编辑器的内容)是如何结构化的,以便最大限度利用 BlockNote。
块(Blocks)
每个 BlockNote 文档由一个块列表组成。
块是一段内容,如段落、标题、列表项或图片。用户可以在编辑器中拖动块。块包含一段内容,并且可选地包含嵌套(子)块:

块对象(Block Objects)
Block
类型用于描述编辑器中的任意块:
type Block = {
id: string;
type: string;
props: Record<string, boolean | number | string>;
content: InlineContent[] | TableContent | undefined;
children: Block[];
};
id:
块的 ID。多个块不能共享同一个 ID,且块在创建到移除之前保持不变。
type:
块的类型,例如段落、标题或列表项。内置块类型概览请参见默认块。
props:
块的属性,是一组键值对,用以进一步指定块的外观和行为。不同块类型拥有不同的属性 - 详见默认块。
content:
块的富文本内容,通常表示为一组 InlineContent
对象的数组。不包括任何嵌套块的内容。更多内容请参阅内联内容。
children:
该块内嵌套的任何块。嵌套块同样用 Block
对象表示。
列块(Column Blocks)
@blocknote/xl-multi-column
包允许你在列中并排组织块。它引入了两种额外的块类型:列和列列表:
type ColumnBlock = {
id: string;
type: "column";
props: { width: number };
content: undefined;
children: Block[];
};
type ColumnListBlock = {
id: string;
type: "columnList";
props: {};
content: undefined;
children: ColumnBlock[];
};
尽管这两者都表现为普通块,使用时须注意以下额外限制:
- 列的子块必须是普通块
- 列列表的子块必须是列
- 列列表中至少必须有两个列
内联内容(Inline Content)
块的 content
字段包含块的富文本内容,定义为一组 InlineContent
对象的数组。内联内容可以是带样式的文本,也可以是链接(或者如果你自定义编辑器模式,则可能是自定义的内联内容类型)。
内联内容对象(Inline Content Objects)
InlineContent
类型描述一段内联内容:
type Link = {
type: "link";
content: StyledText[];
href: string;
};
type StyledText = {
type: "text";
text: string;
styles: Styles;
};
type InlineContent = Link | StyledText;
styles
属性将在下文解释。
其它类型的块内容
多数块使用一组 InlineContent
对象描述内容(例如:段落、标题、列表项)。
一些块,如图片,不包含任何富文本内容,因此其 content
字段为 undefined
。
表格 则不同,其包含 TableContent
。在此,每个表格单元格表示为一组 InlineContent
对象的二维数组:
type TableContent = {
type: "tableContent";
rows: {
cells: InlineContent[][];
}[];
};
样式和富文本
StyledText
对象的 styles
属性用以描述富文本样式(例如:加粗、斜体、颜色)或其它文本属性。它是一组指定应用于文本的样式键值对。
查看默认模式以了解 BlockNote 默认包含的样式。
文档 JSON
下面演示展示编辑器内容(文档)为 JSON。它是一个不断更新的 Block
对象数组,随你在编辑器内输入而变化: