┌───────────────────────────────────────────────────────────────────────────┐ │ 📄 shadcn/directory/udecode/plate/(plugins)/(elements)/horizontal-rule.cn │ └───────────────────────────────────────────────────────────────────────────┘
╔══════════════════════════════════════════════════════════════════════════════════════════════╗
║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║
title: 水平分隔线 docs:
---) 可自动转换为水平分隔线<hr> HTML 元素添加水平分隔线插件最快的方式是使用 BasicBlocksKit,该套件包含预配置的 HorizontalRulePlugin 以及其他基础块元素及其 Plate UI 组件。
HrElement: 渲染水平分隔线元素将套件添加到你的插件中:
import { createPlateEditor } from 'platejs/react';
import { BasicBlocksKit } from '@/components/editor/plugins/basic-blocks-kit';
const editor = createPlateEditor({
plugins: [
// ...其他插件
...BasicBlocksKit,
],
});
</Steps>
npm install @platejs/basic-nodes
在创建编辑器时,将 HorizontalRulePlugin 包含到 Plate 插件数组中。
import { HorizontalRulePlugin } from '@platejs/basic-nodes/react';
import { createPlateEditor } from 'platejs/react';
const editor = createPlateEditor({
plugins: [
// ...其他插件
HorizontalRulePlugin,
],
});
你可以配置 HorizontalRulePlugin 的自动格式化规则,将输入的特定模式(如 ---)自动转换为水平分隔线。
import { insertNodes, setNodes, KEYS } from 'platejs';
import { AutoformatPlugin } from '@platejs/autoformat';
import { HorizontalRulePlugin } from '@platejs/basic-nodes/react';
import { createPlateEditor } from 'platejs/react';
const editor = createPlateEditor({
plugins: [
// ...其他插件
HorizontalRulePlugin,
AutoformatPlugin.configure({
options: {
rules: [
{
mode: 'block',
type: KEYS.hr,
match: ['---', '—-', '___ '],
format: (editor) => {
setNodes(editor, { type: KEYS.hr });
insertNodes(editor, {
type: KEYS.p,
children: [{ text: '' }],
});
},
},
],
},
}),
],
});
AutoformatPlugin: 自动将输入的特定模式(如 ---)转换为水平分隔线你可以将此项目添加到 插入工具栏按钮 中来插入水平分隔线:
{
icon: <MinusIcon />,
label: '分隔线',
value: KEYS.hr,
}
</Steps>
HorizontalRulePlugin用于插入水平分隔线来分隔内容的插件。水平分隔线是 void 元素,默认渲染为 <hr> 标签。
║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║
╚══════════════════════════════════════════════════════════════════════════════════════════════╝