Horizontal rule plugin for the Plate rich text editor framework.
npx @tessl/cli install tessl/npm-udecode--plate-horizontal-rule@49.0.0A horizontal rule plugin for the Plate rich text editor framework. This plugin provides the ability to insert and render horizontal rule (<hr>) elements as void blocks within Slate.js-based editors.
npm install @udecode/plate-horizontal-ruleimport { BaseHorizontalRulePlugin } from "@udecode/plate-horizontal-rule";For React applications:
import { HorizontalRulePlugin } from "@udecode/plate-horizontal-rule/react";CommonJS:
const { BaseHorizontalRulePlugin } = require("@udecode/plate-horizontal-rule");
const { HorizontalRulePlugin } = require("@udecode/plate-horizontal-rule/react");import { createSlateEditor } from "@udecode/plate";
import { BaseHorizontalRulePlugin } from "@udecode/plate-horizontal-rule";
const editor = createSlateEditor({
plugins: [BaseHorizontalRulePlugin]
});import { createPlateEditor } from "@udecode/plate/react";
import { HorizontalRulePlugin } from "@udecode/plate-horizontal-rule/react";
const editor = createPlateEditor({
plugins: [HorizontalRulePlugin]
});The plugin automatically handles HTML deserialization:
<hr> → { type: 'hr', children: [{text: ''}] }And serializes back to HTML:
{ type: 'hr', children: [{ text: '' }] } → <hr>Core Slate.js-compatible plugin that handles horizontal rule elements.
/**
* Base horizontal rule plugin for Slate editors
* Created with createSlatePlugin({ key: KEYS.hr, ... })
*/
const BaseHorizontalRulePlugin: SlatePlugin;React-enhanced version of the base plugin created with toPlatePlugin(BaseHorizontalRulePlugin).
/**
* React-enhanced horizontal rule plugin for Plate editors
* Created with toPlatePlugin(BaseHorizontalRulePlugin)
*/
const HorizontalRulePlugin: PlatePlugin;/**
* Plugin key constant for horizontal rule elements
*/
const KEYS: {
hr: 'hr';
};/** Horizontal rule element node structure */
interface HorizontalRuleElement {
/** Element type identifier */
type: 'hr';
/** Required empty children array for void elements */
children: [{ text: '' }];
}The plugin is created with these core settings:
KEYS.hr (equals 'hr'){ isElement: true, isVoid: true }<HR> tags via deserializer rules'hr' HTML elementHorizontal rule elements in the editor follow this structure:
{
type: 'hr',
children: [{ text: '' }] // Required by Slate for void elements
}<hr> tags