Docs
Horizontal Rule
Horizontal Rule
Visually divide and organize content sections with a horizontal line.
Horizontal Rule
Add horizontal rules to visually separate sections and content within your document.
Installation
npm install @udecode/plate-horizontal-ruleUsage
import { createAutoformatPlugin } from '@udecode/plate-autoformat';
import { ELEMENT_DEFAULT, insertNodes, setNodes } from '@udecode/plate-common';
import {
  ELEMENT_HR,
  createHorizontalRulePlugin,
} from '@udecode/plate-horizontal-rule';
import { createSelectOnBackspacePlugin } from '@udecode/plate-select';
 
const plugins = [
  // ...otherPlugins,
  createHorizontalRulePlugin(),
  createSelectOnBackspacePlugin({
    options: { query: { allow: [ELEMENT_HR] } },
  }),
  createAutoformatPlugin({
    options: {
      rules: [
        {
          mode: 'block',
          type: ELEMENT_HR,
          match: ['---', '—-', '___ '],
          format: (editor) => {
            setNodes(editor, { type: ELEMENT_HR });
            insertNodes(editor, {
              type: ELEMENT_DEFAULT,
              children: [{ text: '' }],
            });
          },
        },
      ],
    },
  }),
];