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

Highlight

PreviousNext

Add marked inline text.

Basic MarksHighlight LeafMark Toolbar ButtonFind Replace Demo

Highlight applies the highlight leaf mark to selected text. It is the authoring mark; Find Replace uses a separate search highlight leaf for transient search results.

Loading…
CodeKeyboard Input

On This Page

FeaturesKit UsageAdd Basic MarksAdd A Toolbar ButtonManual UsageOwnershipBehaviorAPI Reference
Build your editor
Production-ready AI template and reusable components.
Get all-access

Features

  • Boolean highlight leaf property owned by the PLUGINS.highlight capability.
  • Directional selection affinity.
  • HTML deserialization from mark.
  • <mark> rendering by default.
  • Registry HighlightLeaf for styled marked text.
  • Optional input rules through HighlightRules.
Report an issue

Kit Usage

Add Basic Marks

BasicMarksKit includes HighlightPlugin, HighlightLeaf, == and ≡ input rules, and a mod+shift+h shortcut.

'use client';
 
import {
  BoldRules,
  CodeRules,
  HighlightRules,
  ItalicRules,
  MarkComboRules,
  ScriptRules,
  StrikethroughRules,
  UnderlineRules,
} from '@platejs/basic-nodes';
import {
  BoldPlugin,
  CodePlugin,
  HighlightPlugin,
  ItalicPlugin,
  KbdPlugin,
  ScriptPlugin,
  StrikethroughPlugin,
  UnderlinePlugin,
} from '@platejs/basic-nodes/react';
 
import { CodeLeaf } from '@/components/editor/code';
import { HighlightLeaf } from '@/components/editor/highlight';
import { KbdLeaf } from '@/components/editor/kbd';
 
export const BasicMarksKit = [
  BoldPlugin.configure({
    inputRules: [
      BoldRules.markdown({ variant: '*' }),
      BoldRules.markdown({ variant: '_' }),
      MarkComboRules.markdown({ variant: 'boldItalic' }),
      MarkComboRules.markdown({ variant: 'boldUnderline' }),
      MarkComboRules.markdown({ variant: 'boldItalicUnderline' }),
      MarkComboRules.markdown({ variant: 'italicUnderline' }),
    ],
  }),
  ItalicPlugin.configure({
    inputRules: [
      ItalicRules.markdown({ variant: '*' }),
      ItalicRules.markdown({ variant: '_' }),
    ],
  }),
  UnderlinePlugin.configure({
    inputRules: [UnderlineRules.markdown()],
  }),
  CodePlugin.configure({
    component: CodeLeaf,
    inputRules: [CodeRules.markdown()],
    shortcuts: { toggle: { keys: 'mod+e' } },
  }),
  StrikethroughPlugin.configure({
    inputRules: [StrikethroughRules.markdown()],
    shortcuts: { toggle: { keys: 'mod+shift+x' } },
  }),
  ScriptPlugin.configure({
    inputRules: [
      ScriptRules.markdown({ value: 'sub' }),
      ScriptRules.markdown({ value: 'sup' }),
    ],
    shortcuts: {
      subscript: {
        keys: 'mod+comma',
        handler: ({ editor }) => {
          editor.plugin(ScriptPlugin).update.toggle('sub');
        },
      },
      superscript: {
        keys: 'mod+period',
        handler: ({ editor }) => {
          editor.plugin(ScriptPlugin).update.toggle('sup');
        },
      },
    },
  }),
  HighlightPlugin.configure({
    component: HighlightLeaf,
    inputRules: [
      HighlightRules.markdown({ variant: '==' }),
      HighlightRules.markdown({ variant: '≡' }),
    ],
    shortcuts: { toggle: { keys: 'mod+shift+h' } },
  }),
  KbdPlugin.configure({ component: KbdLeaf }),
] as const;
'use client';
 
import {
  BoldRules,
  CodeRules,
  HighlightRules,
  ItalicRules,
  MarkComboRules,
  ScriptRules,
  StrikethroughRules,
  UnderlineRules,
} from '@platejs/basic-nodes';
import {
  BoldPlugin,
  CodePlugin,
  HighlightPlugin,
  ItalicPlugin,
  KbdPlugin,
  ScriptPlugin,
  StrikethroughPlugin,
  UnderlinePlugin,
} from '@platejs/basic-nodes/react';
 
import { CodeLeaf } from '@/components/editor/code';
import { HighlightLeaf } from '@/components/editor/highlight';




























































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

Add A Toolbar Button

Pass HighlightPlugin to MarkToolbarButton so the button uses the configured mark key.

import { HighlighterIcon } from 'lucide-react';
import { HighlightPlugin } from '@platejs/basic-nodes/react';
 
import { MarkToolbarButton } from '@/components/editor/mark-toolbar-button';
 
export function HighlightToolbarButton() {
  return (
    <MarkToolbarButton plugin={HighlightPlugin} tooltip="Highlight">
      <HighlighterIcon />
    </MarkToolbarButton>
  );
}

Manual Usage

Install the mark package.

pnpm add @platejs/basic-nodes
pnpm add @platejs/basic-nodes

Add HighlightPlugin directly when you want the default <mark> render.

import { HighlightPlugin } from '@platejs/basic-nodes/react';
import { createPlateEditor } from 'platejs/react';
 
export const editor = createPlateEditor({
  plugins: [HighlightPlugin],
});
import { HighlightPlugin } from '@platejs/basic-nodes/react';
import { createPlateEditor } from 'platejs/react';
 
export const editor = createPlateEditor({
  plugins: [HighlightPlugin],
});

Configure the registry leaf, input rules, and shortcut when you want the same behavior as the kit.

import { HighlightRules } from '@platejs/basic-nodes';
import { HighlightPlugin } from '@platejs/basic-nodes/react';
 
import { HighlightLeaf } from '@/components/editor/highlight';
 
export const highlightPlugin = HighlightPlugin.configure({
  component: HighlightLeaf,
  inputRules: [
    HighlightRules.markdown({ variant: '==' }),
    HighlightRules.markdown({ variant: '≡' }),
  ],
  shortcuts: { toggle: { keys: 'mod+shift+h' } },
});
import { HighlightRules } from '@platejs/basic-nodes';
import { HighlightPlugin } from '@platejs/basic-nodes/react';
 
import { HighlightLeaf } from '@/components/editor/highlight';
 
export const highlightPlugin = HighlightPlugin.configure({
  component: HighlightLeaf,
  inputRules: [
    HighlightRules.markdown({ variant: '==' }),
    HighlightRules.markdown({ variant: '≡' }),
  ],
  shortcuts: { toggle: { keys: 'mod+shift+h' } },
});

Ownership

SurfaceOwnerWhat It Does
BaseHighlightPlugin@platejs/basic-nodesHeadless highlight mark, HTML parser, render tag, selection rule, and toggle transform.
HighlightPlugin@platejs/basic-nodes/reactReact wrapper for the headless highlight mark.
HighlightRules.markdown@platejs/basic-nodesOptional mark input rule factory.
HighlightLeafRegistry UIStyled client highlight leaf using PlateLeaf.
HighlightLeafStaticRegistry UIStatic rendering version using PliteLeaf.
BasicMarksKitRegistryAdds HighlightPlugin, HighlightLeaf, two input-rule variants, and mod+shift+h.
MarkToolbarButtonRegistry UIReads active mark state and calls the mark toggle hook.

The package owns the mark. The registry owns highlight color and toolbar placement.

Behavior

BehaviorSource
Mark keyeditor.plugin(HighlightPlugin).schema.key (default: highlight)
Mark declarationschema.mark: property.boolean({ default: false, omitDefault: true })
Toggle commandtx.highlight.toggle() toggles the resolved schema key.
Selection affinitydirectional
HTML tagsmark
Render outputmark
Kit input rules== and ≡ variants
Kit shortcutmod+shift+h

API Reference

APIPackageUse
BaseHighlightPlugin@platejs/basic-nodesHeadless highlight plugin.
HighlightPlugin@platejs/basic-nodes/reactReact highlight plugin.
HighlightRules.markdown(options)@platejs/basic-nodesCreates a highlight mark input rule.
tx.highlight.toggle()@platejs/basic-nodesToggles the highlight mark at the selection.
HighlightLeafRegistry UIStyled client highlight leaf.
HighlightLeafStaticRegistry UIStyled static highlight leaf.
import { KbdLeaf } from '@/components/editor/kbd';
export const BasicMarksKit = [
BoldPlugin.configure({
inputRules: [
BoldRules.markdown({ variant: '*' }),
BoldRules.markdown({ variant: '_' }),
MarkComboRules.markdown({ variant: 'boldItalic' }),
MarkComboRules.markdown({ variant: 'boldUnderline' }),
MarkComboRules.markdown({ variant: 'boldItalicUnderline' }),
MarkComboRules.markdown({ variant: 'italicUnderline' }),
],
}),
ItalicPlugin.configure({
inputRules: [
ItalicRules.markdown({ variant: '*' }),
ItalicRules.markdown({ variant: '_' }),
],
}),
UnderlinePlugin.configure({
inputRules: [UnderlineRules.markdown()],
}),
CodePlugin.configure({
component: CodeLeaf,
inputRules: [CodeRules.markdown()],
shortcuts: { toggle: { keys: 'mod+e' } },
}),
StrikethroughPlugin.configure({
inputRules: [StrikethroughRules.markdown()],
shortcuts: { toggle: { keys: 'mod+shift+x' } },
}),
ScriptPlugin.configure({
inputRules: [
ScriptRules.markdown({ value: 'sub' }),
ScriptRules.markdown({ value: 'sup' }),
],
shortcuts: {
subscript: {
keys: 'mod+comma',
handler: ({ editor }) => {
editor.plugin(ScriptPlugin).update.toggle('sub');
},
},
superscript: {
keys: 'mod+period',
handler: ({ editor }) => {
editor.plugin(ScriptPlugin).update.toggle('sup');
},
},
},
}),
HighlightPlugin.configure({
component: HighlightLeaf,
inputRules: [
HighlightRules.markdown({ variant: '==' }),
HighlightRules.markdown({ variant: '≡' }),
],
shortcuts: { toggle: { keys: 'mod+shift+h' } },
}),
KbdPlugin.configure({ component: KbdLeaf }),
] as const;
plugins: [
...
BasicMarksKit],
});
import { HighlighterIcon } from 'lucide-react'; import { HighlightPlugin } from '@platejs/basic-nodes/react'; import { MarkToolbarButton } from '@/components/editor/mark-toolbar-button'; export function HighlightToolbarButton() { return ( <MarkToolbarButton plugin={HighlightPlugin} tooltip="Highlight"> <HighlighterIcon /> </MarkToolbarButton> ); }