Heading 1
This is a top-level heading, typically used for main titles and major section headers.
Heading 2
Secondary headings help organize content into clear sections and subsections.
Heading 3
Third-level headings provide further content structure and hierarchy.
"Blockquotes are perfect for highlighting important information, quotes from external sources, or emphasizing key points in your content."
Use headings to create a clear document structure that helps readers navigate your content effectively. Combine them with blockquotes to emphasize important information.
Horizontal rules help visually separate different sections of your content, creating clear breaks between topics or ideas.
1
100%
Files
'use client';
import * as React from 'react';
import { Plate, usePlateEditor } from 'platejs/react';
import { EditorKit } from '@/components/editor/editor-kit';
import { Editor, EditorContainer } from '@/components/ui/editor';
import { DEMO_VALUES } from './values/demo-values';
export default function Demo({ id }: { id: string }) {
const editor = usePlateEditor({
plugins: EditorKit,
value: DEMO_VALUES[id],
});
return (
<Plate editor={editor}>
<EditorContainer variant="demo">
<Editor />
</EditorContainer>
</Plate>
);
}
Basic block elements like headings, quotes, and code blocks.
basic-blocks-demo


功能特性
- 插入水平线来分隔内容或表示主题转换
- 在新行开头输入三个破折号 (
---) 可自动转换为水平分隔线 - 默认渲染为
<hr>HTML 元素
套件使用
安装
添加水平分隔线插件最快的方式是使用 BasicBlocksKit,该套件包含预配置的 HorizontalRulePlugin 以及其他基础块元素及其 Plate UI 组件。
'use client';
import {
BlockquotePlugin,
H1Plugin,
H2Plugin,
H3Plugin,
HorizontalRulePlugin,
} from '@platejs/basic-nodes/react';
import { ParagraphPlugin } from 'platejs/react';
import { BlockquoteElement } from '@/components/ui/blockquote-node';
import { H1Element, H2Element, H3Element } from '@/components/ui/heading-node';
import { HrElement } from '@/components/ui/hr-node';
import { ParagraphElement } from '@/components/ui/paragraph-node';
export const BasicBlocksKit = [
ParagraphPlugin.withComponent(ParagraphElement),
H1Plugin.configure({
node: {
component: H1Element,
},
rules: {
break: { empty: 'reset' },
},
shortcuts: { toggle: { keys: 'mod+alt+1' } },
}),
H2Plugin.configure({
node: {
component: H2Element,
},
rules: {
break: { empty: 'reset' },
},
shortcuts: { toggle: { keys: 'mod+alt+2' } },
}),
H3Plugin.configure({
node: {
component: H3Element,
},
rules: {
break: { empty: 'reset' },
},
shortcuts: { toggle: { keys: 'mod+alt+3' } },
}),
BlockquotePlugin.configure({
node: { component: BlockquoteElement },
shortcuts: { toggle: { keys: 'mod+shift+period' } },
}),
HorizontalRulePlugin.withComponent(HrElement),
];
HrElement: 渲染水平分隔线元素
添加套件
将套件添加到你的插件中:
import { createPlateEditor } from 'platejs/react';
import { BasicBlocksKit } from '@/components/editor/plugins/basic-blocks-kit';
const editor = createPlateEditor({
plugins: [
// ...其他插件
...BasicBlocksKit,
],
});手动使用
安装
pnpm add @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,
}插件
HorizontalRulePlugin
用于插入水平分隔线来分隔内容的插件。水平分隔线是 void 元素,默认渲染为 <hr> 标签。