Back to Plate

强制布局

docs/(plugins)/(functionality)/(utils)/forced-layout.cn.mdx

1.0.01.0 KB
Original Source
<PackageInfo>

功能特性

  • 自动确保使用指定元素以维持文档结构(例如,第一个块必须是H1元素)。
  • 如需强制尾部块为特定类型,请参阅尾部块
</PackageInfo>

使用方法

tsx
import { NormalizeTypesPlugin } from 'platejs';

const plugins = [
  // ...其他插件
  NormalizeTypesPlugin.configure({
    options: {
      rules: [{ path: [0], strictType: 'h1' }],
    },
  }),
];

插件

NormalizeTypesPlugin

<API name="NormalizeTypesPlugin"> <APIOptions> <APIItem name="rules" type="Rule[]" optional> 用于规范化类型的规则对象数组。
  • 默认值: [] </APIItem>
</APIOptions> <APIOptions type="Rule"> <APIItem name="path" type="Path"> 规则应用的路径。 </APIItem> <APIItem name="strictType" type="string" optional> 强制指定路径节点的类型。 </APIItem> <APIItem name="type" type="string" optional> 如果未提供`strictType`,则插入节点的类型。 </APIItem> </APIOptions> </API>