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

Heading

PreviousNext

One semantic heading element with levels 1 through 6.

Heading ElementBasic Blocks

Heading uses one element type and one plugin. The required level property selects H1 through H6 rendering and Markdown depth.

Loading…
BlockquoteHorizontal Rule

On This Page

FeaturesKit UsageManual UsageValueCommandsAPI Reference
Build your editor
Production-ready AI template and reusable components.
Get all-access

Features

  • One HeadingPlugin and BaseHeadingPlugin capability.
  • Required level from 1 through 6.
  • One HTML and MDAST codec.
  • Markdown shortcuts from # through ######.
  • Registry shortcuts from mod+alt+1 through mod+alt+6.
Report an issue

Kit Usage

BasicBlocksKit includes HeadingPlugin, the dynamic HeadingElement, all six keyboard shortcuts, and HeadingRules.markdown().

import { BasicBlocksKit } from '@/components/editor/plugins/basic-blocks-kit';
import { createPlateEditor } from 'platejs/react';
 
const editor = createPlateEditor({
  plugins: [...BasicBlocksKit],
});
import { BasicBlocksKit } from '@/components/editor/plugins/basic-blocks-kit';
import { createPlateEditor } from 'platejs/react';
 
const editor = createPlateEditor({
  plugins: [...BasicBlocksKit],
});

Manual Usage

import { HeadingRules } from '@platejs/basic-nodes';
import { HeadingPlugin } from '@platejs/basic-nodes/react';
 
const plugins = [
  HeadingPlugin.configure({
    component: HeadingElement,
    inputRules: [HeadingRules.markdown()],
  }),
];
import { HeadingRules } from '@platejs/basic-nodes';
import { HeadingPlugin } from '@platejs/basic-nodes/react';
 
const plugins = [
  HeadingPlugin.configure({
    component: HeadingElement,
    inputRules: [HeadingRules.markdown()],
  }),
];

A renderer reads element.level and chooses the matching intrinsic element.

import type { PlateElementProps } from 'platejs/react';
import { HeadingPlugin } from '@platejs/basic-nodes/react';
import { PlateElement } from 'platejs/react';
 
export function HeadingElement(
  props: PlateElementProps<typeof HeadingPlugin>
) {
  const tag = `h${props.element.level}` as const;
 
  return <PlateElement as={tag} {...props} />;
}
import type { PlateElementProps } from 'platejs/react';
import { HeadingPlugin } from '@platejs/basic-nodes/react';
import { PlateElement } from 'platejs/react';
 
export function HeadingElement(
  props: PlateElementProps<typeof HeadingPlugin>
) {
  const tag = `h${props.element.level}` as const;
 
  return <PlateElement as={tag} {...props} />;
}

Value

const value = [
  {
    type: 'heading',
    level: 2,
    children: [{ text: 'Document model' }],
  },
];
const value = [
  {
    type: 'heading',
    level: 2,
    children: [{ text: 'Document model' }],
  },
];

level is semantic Plate data. The HTML codec maps it to an h1 through h6 tag. The Markdown codec maps it to MDAST depth.

Commands

editor.plugin(HeadingPlugin).update.toggle({ level: 2 });
editor.plugin(HeadingPlugin).update.toggle({ level: 2 });

Calling toggle with the active level resets the selected heading to the root default block. Calling it with another level changes the level on the same heading type.

API Reference

APIPurpose
BaseHeadingPluginHeadless heading schema, behavior, codecs, and update.
HeadingPluginReact adapter for BaseHeadingPlugin.
HeadingRules.markdown()One block-start rule for # through ######.
HeadingLevel1, 2, 3, 4, 5, or 6.