Loading...
功能特性
- 确保文档末尾始终存在特定类型的块
手动使用
添加插件
import { TrailingBlockPlugin } from 'platejs';
import { createPlateEditor } from 'platejs/react';
const editor = createPlateEditor({
plugins: [
// ...其他插件
TrailingBlockPlugin,
],
});
配置插件
该插件开箱即用,具有合理的默认配置,但也可以针对特定用例进行配置:
import { TrailingBlockPlugin } from 'platejs';
import { createPlateEditor } from 'platejs/react';
const editor = createPlateEditor({
plugins: [
// ...其他插件
TrailingBlockPlugin.configure({
options: {
type: 'p', // 段落块
exclude: ['blockquote'], // 不在这些类型后添加
},
}),
],
});
配置选项:
type
: 要插入的尾部块类型(默认为段落)exclude
: 不应触发尾部块插入的块类型数组allow
: 允许的块类型数组(与exclude互斥)filter
: 自定义函数用于确定何时添加尾部块
插件
TrailingBlockPlugin
确保在文档末尾或指定嵌套层级始终存在特定块类型的插件。
核心行为:
- 当最后一个节点不符合预期类型时自动添加尾部块
- 通过编辑器规范化机制维护文档结构
- 通过配置
level
选项支持嵌套结构 - 防止空文档,确保至少存在一个块
- 遵循过滤选项控制尾部块的添加时机