Loading...
Features
- Highlight important text with background colors
- Keyboard shortcut support for quick formatting
- Renders as
<mark>
HTML element by default
Kit Usage
Installation
The fastest way to add the highlight plugin is with the BasicMarksKit
, which includes pre-configured HighlightPlugin
along with other basic marks and their Plate UI components.
HighlightLeaf
: Renders highlighted text elements.
Add Kit
Add the kit to your plugins:
import { createPlateEditor } from 'platejs/react';
import { BasicMarksKit } from '@/components/editor/plugins/basic-marks-kit';
const editor = createPlateEditor({
plugins: [
// ...otherPlugins,
...BasicMarksKit,
],
});
Manual Usage
Installation
pnpm add @platejs/basic-nodes
Add Plugin
Include HighlightPlugin
in your Plate plugins array when creating the editor.
import { HighlightPlugin } from '@platejs/basic-nodes/react';
import { createPlateEditor } from 'platejs/react';
const editor = createPlateEditor({
plugins: [
// ...otherPlugins,
HighlightPlugin,
],
});
Configure Plugin
You can configure the HighlightPlugin
with a custom component and keyboard shortcuts.
import { HighlightPlugin } from '@platejs/basic-nodes/react';
import { createPlateEditor } from 'platejs/react';
import { HighlightLeaf } from '@/components/ui/highlight-node';
const editor = createPlateEditor({
plugins: [
// ...otherPlugins,
HighlightPlugin.configure({
node: { component: HighlightLeaf },
shortcuts: { toggle: { keys: 'mod+shift+h' } },
}),
],
});
node.component
: AssignsHighlightLeaf
to render highlighted text elements.shortcuts.toggle
: Defines a keyboard shortcut to toggle highlight formatting.
Add Toolbar Button
You can add MarkToolbarButton
to your Toolbar to toggle highlight formatting.
Plugins
HighlightPlugin
Plugin for highlight text formatting. Renders as <mark>
HTML element by default.
Transforms
tf.highlight.toggle
Toggles the highlight formatting for the selected text.