Back to Plate

Basic Blocks

content/docs/(plugins)/(elements)/basic-blocks.mdx

53.0.86.1 KB
Original Source

Basic Blocks is the registry kit for the common structural blocks in a Plate editor. It wires paragraphs, six heading levels, blockquotes, and horizontal rules to Plate UI components. Use the leaf docs when you need the behavior details for one block type.

<Cards> <Card icon="heading" title="Heading" href="/docs/heading"> Structure content with H1 through H6 blocks. </Card> <Card icon="blockquote" title="Blockquote" href="/docs/blockquote"> Wrap quoted or emphasized content in a blockquote. </Card> <Card icon="horizontal-rule" title="Horizontal Rule" href="/docs/horizontal-rule"> Insert a void divider between sections. </Card> </Cards> <ComponentPreview name="basic-blocks-demo" /> <PackageInfo>

Features

  • Paragraph, H1-H6, blockquote, and horizontal rule components.
  • Markdown shortcuts for headings, blockquotes, and horizontal rules.
  • Keyboard shortcuts for heading toggles and blockquote toggling.
  • Static rendering companion through basic-blocks-base-kit.
  • Leaf docs for block-specific setup and API details.
</PackageInfo>

Fast Path

<Steps>

Add The Kit

BasicBlocksKit is the normal app/editor kit. It installs the React plugins and the matching registry UI components.

<ComponentSource name="basic-blocks-kit" />
tsx
import { createPlateEditor } from 'platejs/react';

import { BasicBlocksKit } from '@/components/editor/plugins/basic-blocks-kit';

export const editor = createPlateEditor({
  plugins: BasicBlocksKit,
});

Add Static Rendering

Use BaseBasicBlocksKit in static or server-safe rendering paths.

<ComponentSource name="basic-blocks-base-kit" />
tsx
import { createStaticEditor } from 'platejs';

import { BaseBasicBlocksKit } from '@/components/editor/plugins/basic-blocks-base-kit';

const value = [
  {
    children: [{ text: 'Static content' }],
    type: 'p',
  },
];

export const staticEditor = createStaticEditor({
  plugins: BaseBasicBlocksKit,
  value,
});
</Steps>

Ownership

LayerOwnerWhat It Does
platejs/reactPackageExports ParagraphPlugin.
@platejs/basic-nodesPackageExports block rules and base block plugins.
@platejs/basic-nodes/reactPackageExports BlockquotePlugin, HeadingPlugin, H1Plugin through H6Plugin, HorizontalRulePlugin, and BasicBlocksPlugin.
basic-blocks-kitRegistryAdds React UI components, input rules, break rules, and shortcuts.
basic-blocks-base-kitRegistryAdds static UI components for static rendering.
Leaf pagesDocsOwn block-specific behavior: Heading, Blockquote, and Horizontal Rule.

BasicBlocksPlugin is a package-level grouping plugin. It does not install the registry UI components; use BasicBlocksKit when you want Plate UI rendering.

Included Plugins

BlockPluginRegistry ComponentNotes
ParagraphParagraphPluginParagraphElementComes from platejs/react; the registry kit adds the UI component.
Heading 1-6H1Plugin through H6PluginH1Element through H6ElementEach level gets a markdown rule and mod+alt+<level> shortcut.
BlockquoteBlockquotePluginBlockquoteElementUses a wrapping transform and mod+shift+period.
Horizontal ruleHorizontalRulePluginHrElementVoid block; supports dash and underscore markdown rules.

Markdown Shortcuts

ShortcutResult
# through ###### Converts the current paragraph into H1 through H6.
> Wraps the current block in a blockquote.
---Converts the current block into a horizontal rule, then inserts a paragraph after it.
___ Converts the current block into a horizontal rule, then inserts a paragraph after it.

See Plugin Input Rules for the rule engine and trigger model.

Manual Setup

Use manual setup when you want the package plugins without the registry kit.

bash
npm install @platejs/basic-nodes
tsx
import {
  BlockquoteRules,
  HeadingRules,
  HorizontalRuleRules,
} from '@platejs/basic-nodes';
import {
  BlockquotePlugin,
  H1Plugin,
  H2Plugin,
  H3Plugin,
  H4Plugin,
  H5Plugin,
  H6Plugin,
  HorizontalRulePlugin,
} from '@platejs/basic-nodes/react';
import { createPlateEditor, ParagraphPlugin } from 'platejs/react';

export const editor = createPlateEditor({
  plugins: [
    ParagraphPlugin,
    H1Plugin.configure({
      inputRules: [HeadingRules.markdown()],
      shortcuts: { toggle: { keys: 'mod+alt+1' } },
    }),
    H2Plugin.configure({
      inputRules: [HeadingRules.markdown()],
      shortcuts: { toggle: { keys: 'mod+alt+2' } },
    }),
    H3Plugin.configure({
      inputRules: [HeadingRules.markdown()],
      shortcuts: { toggle: { keys: 'mod+alt+3' } },
    }),
    H4Plugin.configure({
      inputRules: [HeadingRules.markdown()],
      shortcuts: { toggle: { keys: 'mod+alt+4' } },
    }),
    H5Plugin.configure({
      inputRules: [HeadingRules.markdown()],
      shortcuts: { toggle: { keys: 'mod+alt+5' } },
    }),
    H6Plugin.configure({
      inputRules: [HeadingRules.markdown()],
      shortcuts: { toggle: { keys: 'mod+alt+6' } },
    }),
    BlockquotePlugin.configure({
      inputRules: [BlockquoteRules.markdown()],
      shortcuts: { toggle: { keys: 'mod+shift+period' } },
    }),
    HorizontalRulePlugin.configure({
      inputRules: [
        HorizontalRuleRules.markdown({ variant: '-' }),
        HorizontalRuleRules.markdown({ variant: '_' }),
      ],
    }),
  ],
});

API Reference

APIUse
BasicBlocksPluginPackage grouping plugin for blockquote, heading, and horizontal rule behavior.
BaseBasicBlocksPluginStatic/headless grouping plugin for blockquote, heading, and horizontal rule behavior.
HeadingRules.markdown()Creates heading input rules based on the configured H1-H6 plugin key.
BlockquoteRules.markdown()Creates the > block-start rule.
HorizontalRuleRules.markdown({ variant })Creates dash or underscore thematic-break rules.