From zbeyens. The source code is available on GitHub.

Plate
PlatePliteEditorsTemplates
GitHub16kGitHub
DiscordDiscord
    • Stream
    • Copilot
  • Discussion
    • Comments
    • Suggestion
    • Basic Blocks
      • Blockquote
      • Heading
      • Horizontal Rule
    • Callout
    • Code Block
    • Column
    • Date
    • Equation
    • Link
    • List Classic
    • Media
    • MentionElement
    • Table
    • Table of Contents
    • Footnote
    • Toggle
  • Marks
    • Bold
    • Italic
    • Underline
    • Code
    • Highlight
    • Keyboard Input
    • Strikethrough
    • Subscript
    • Superscript
      • Font
      • Line Height
      • Text Align
    • Indent
    • List
      • Exit Break
      • Single Block
      • Trailing Block
    • Autoformat
    • Block Menu
    • Block Placeholder
    • Combobox
      • Emoji
      • MentionElement
      • Slash Command
    • Cursor Overlay
    • Drag & Drop
    • Navigation Feedback
    • Tabbable
    • Toolbar
    • Yjs
    • Multi SelectEditor
    • CSV
    • DOCX
    • HTML
    • Markdown

Single Block

PreviousNext

Restrict an editor to one root block or one line of text.

DemoTrailing Block

Single Block provides two input constraints: one root block with soft breaks, or one line with no breaks. Each constraint is an independent plugin.

Loading…
Exit BreakTrailing Block

On This Page

FeaturesUsageCompose With A Broad Editor KitOwnershipBehaviorCorrectionsDemo ToggleAPI Reference
Build your editor
Production-ready AI template and reusable components.
Get all-access

Features

  • SingleBlockPlugin keeps one root block and converts Enter to a soft break.
  • SingleLinePlugin keeps one root block and removes all line break characters.
  • Root normalization merges extra blocks into the first block.
  • Demo toggle for switching between single-block and single-line behavior.
Report an issue

Usage

Use SingleBlockPlugin when the field may contain line breaks.

import { SingleBlockPlugin } from "platejs";
import { createPlateEditor } from "platejs/react";
 
export const editor = createPlateEditor({
  plugins: [SingleBlockPlugin],
});
import { SingleBlockPlugin } from "platejs";
import { createPlateEditor } from "platejs/react";
 
export const editor = createPlateEditor({
  plugins: [SingleBlockPlugin],
});

Use SingleLinePlugin when the field must be plain one-line text.

import { SingleLinePlugin } from "platejs";
import { createPlateEditor } from "platejs/react";
 
export const editor = createPlateEditor({
  plugins: [SingleLinePlugin],
});
import { SingleLinePlugin } from "platejs";
import { createPlateEditor } from "platejs/react";
 
export const editor = createPlateEditor({
  plugins: [SingleLinePlugin],
});

Compose With A Broad Editor Kit

SingleBlockPlugin weakly disables an installed TrailingBlockPlugin, so the package remains correct even when it cannot control the consumer's broad kit:

import { SingleBlockPlugin } from "platejs";
import { createPlateEditor } from "platejs/react";
 
import { plugins as editorPlugins } from "@/components/editor/editor";
 
export const editor = createPlateEditor({
  plugins: [...editorPlugins, SingleBlockPlugin],
});
import { SingleBlockPlugin } from "platejs";
import { createPlateEditor } from "platejs/react";
 
import { plugins as editorPlugins } from "@/components/editor/editor";
 
export const editor = createPlateEditor({
  plugins: [...editorPlugins, SingleBlockPlugin],
});

Use SingleLinePlugin in the same shape for a one-line field.

The weak peer applies only when Trailing Block is installed. It never installs the target, and a missing target is a no-op. Required dependencies still reject disablement.

Ownership

LayerOwnerWhat It Does
SingleBlockPlugin@platejs/utilsKeeps one root block and preserves line breaks as text.
SingleLinePlugin@platejs/utilsKeeps one root block and strips line break characters.
TrailingBlockPlugin@platejs/utilsProvides trailing-block normalization when enabled.
single-block-demoRegistry exampleOwns the broad composition and mode toggle.

These plugins are editor constraints, not schema validation. Their Plite corrections rewrite invalid root content before publication.

Behavior

PluginEnterSoft BreakExtra Root BlocksExisting Text Breaks
SingleBlockPluginCalls tx.break.insertSoft().Preserved as \n.Merged into the first block with \n separators.Preserved.
SingleLinePluginNo-op.No-op.Merged into the first block with no separator.Removes \r, \n, \r\n, \u2028, and \u2029.

Use single-block mode for descriptions, comments, or titles that may wrap across lines. Use single-line mode for labels, slugs, short titles, and command inputs.

Corrections

Both behavior plugins register Plite corrections.

CaseResult
Root has one blockLeaves the value alone.
Root has multiple blocks with SingleBlockPluginInserts \n at the start of each next block, then merges it into the first block.
Root has multiple blocks with SingleLinePluginMerges each next block into the first block without a separator.
Text node contains line separators with SingleLinePluginReplaces the text with the filtered one-line string.

Each correction runs in the active Plite transaction, so the root collapse publishes as one update.

Demo Toggle

The registry example switches plugins from a checkbox.

import {
  SingleBlockPlugin,
  SingleLinePlugin,
} from "platejs";
 
const plugins = [
  ...editorPlugins,
  isSingleBlock ? SingleBlockPlugin : SingleLinePlugin,
];
import {
  SingleBlockPlugin,
  SingleLinePlugin,
} from "platejs";
 
const plugins = [
  ...editorPlugins,
  isSingleBlock ? SingleBlockPlugin : SingleLinePlugin,
];

Single Block Mode keeps pasted lines as \n. Turning it off switches to single-line mode and removes line breaks.

API Reference

APIPackageUse
SingleBlockPluginplatejs / @platejs/utilsOne root block with soft breaks preserved.
SingleLinePluginplatejs / @platejs/utilsOne root block with all line breaks removed.
PLUGINS.singleBlockplatejs / @platejs/utilsPlugin name for SingleBlockPlugin.
PLUGINS.singleLineplatejs / @platejs/utilsPlugin name for SingleLinePlugin.
override.plugins[PLUGINS.trailingBlock]@platejs/utilsPackage-owned weak peer that disables Trailing Block only when installed.