Basic Marks

PreviousNext

Common inline text formatting marks.

Basic Marks covers the common inline formatting marks: bold, italic, underline, strikethrough, code, subscript, superscript, highlight, and kbd. The package owns mark plugins and transforms; the registry kit adds leaf components, toolbar wiring, and Markdown-style input rules.

Loading…

Features

  • Leaf plugins for common mark keys.
  • Toggle transforms through each mark plugin.
  • HTML deserialization for semantic tags and styles.
  • Markdown-style input rules in the registry kit.
  • Registry leaves for code, highlight, and keyboard text.
  • Toolbar support through MarkToolbarButton.

Kit Usage

Add The Kit

BasicMarksKit is the full client-side registry kit. It includes mark plugins, input rules, CodeLeaf, HighlightLeaf, and KbdLeaf.

'use client';
 
import {
  BoldRules,
  CodeRules,
  HighlightRules,
  ItalicRules,
  MarkComboRules,
  StrikethroughRules,
  SubscriptRules,
  SuperscriptRules,
  UnderlineRules,
} from '@platejs/basic-nodes';
import {
  BoldPlugin,
  CodePlugin,
  HighlightPlugin,
  ItalicPlugin,
  KbdPlugin,
  StrikethroughPlugin,
  SubscriptPlugin,
  SuperscriptPlugin,
  UnderlinePlugin,
} from '@platejs/basic-nodes/react';
 
import { CodeLeaf } from '@/components/ui/code-node';
import { HighlightLeaf } from '@/components/ui/highlight-node';
import { KbdLeaf } from '@/components/ui/kbd-node';
 
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({
    inputRules: [CodeRules.markdown()],
    node: { component: CodeLeaf },
    shortcuts: { toggle: { keys: 'mod+e' } },
  }),
  StrikethroughPlugin.configure({
    inputRules: [StrikethroughRules.markdown()],
    shortcuts: { toggle: { keys: 'mod+shift+x' } },
  }),
  SubscriptPlugin.configure({
    inputRules: [SubscriptRules.markdown()],
    shortcuts: { toggle: { keys: 'mod+comma' } },
  }),
  SuperscriptPlugin.configure({
    inputRules: [SuperscriptRules.markdown()],
    shortcuts: { toggle: { keys: 'mod+period' } },
  }),
  HighlightPlugin.configure({
    inputRules: [
      HighlightRules.markdown({ variant: '==' }),
      HighlightRules.markdown({ variant: '≡' }),
    ],
    node: { component: HighlightLeaf },
    shortcuts: { toggle: { keys: 'mod+shift+h' } },
  }),
  KbdPlugin.withComponent(KbdLeaf),
];
'use client';
 
import {
  BoldRules,
  CodeRules,
  HighlightRules,
  ItalicRules,
  MarkComboRules,
  StrikethroughRules,
  SubscriptRules,
  SuperscriptRules,
  UnderlineRules,
} from '@platejs/basic-nodes';
import {
  BoldPlugin,
  CodePlugin,
  HighlightPlugin,
  ItalicPlugin,
  KbdPlugin,
  StrikethroughPlugin,
  SubscriptPlugin,
  SuperscriptPlugin,
  UnderlinePlugin,
} from '@platejs/basic-nodes/react';
 
import { CodeLeaf } from '@/components/ui/code-node';
import { HighlightLeaf } from '@/components/ui/highlight-node';
import { KbdLeaf } from '@/components/ui/kbd-node';
 
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({
    inputRules: [CodeRules.markdown()],
    node: { component: CodeLeaf },
    shortcuts: { toggle: { keys: 'mod+e' } },
  }),
  StrikethroughPlugin.configure({
    inputRules: [StrikethroughRules.markdown()],
    shortcuts: { toggle: { keys: 'mod+shift+x' } },
  }),
  SubscriptPlugin.configure({
    inputRules: [SubscriptRules.markdown()],
    shortcuts: { toggle: { keys: 'mod+comma' } },
  }),
  SuperscriptPlugin.configure({
    inputRules: [SuperscriptRules.markdown()],
    shortcuts: { toggle: { keys: 'mod+period' } },
  }),
  HighlightPlugin.configure({
    inputRules: [
      HighlightRules.markdown({ variant: '==' }),
      HighlightRules.markdown({ variant: '≡' }),
    ],
    node: { component: HighlightLeaf },
    shortcuts: { toggle: { keys: 'mod+shift+h' } },
  }),
  KbdPlugin.withComponent(KbdLeaf),
];
import { createPlateEditor } from 'platejs/react';
 
import { BasicMarksKit } from '@/components/editor/plugins/basic-marks-kit';
 
export const editor = createPlateEditor({
  plugins: [...BasicMarksKit],
});
import { createPlateEditor } from 'platejs/react';
 
import { BasicMarksKit } from '@/components/editor/plugins/basic-marks-kit';
 
export const editor = createPlateEditor({
  plugins: [...BasicMarksKit],
});

Add Toolbar Buttons

Use MarkToolbarButton for direct mark toggles.

import { BoldIcon } from 'lucide-react';
import { KEYS } from 'platejs';
 
import { MarkToolbarButton } from '@/components/ui/mark-toolbar-button';
 
export function BoldToolbarButton() {
  return (
    <MarkToolbarButton nodeType={KEYS.bold} tooltip="Bold (⌘+B)">
      <BoldIcon />
    </MarkToolbarButton>
  );
}
import { BoldIcon } from 'lucide-react';
import { KEYS } from 'platejs';
 
import { MarkToolbarButton } from '@/components/ui/mark-toolbar-button';
 
export function BoldToolbarButton() {
  return (
    <MarkToolbarButton nodeType={KEYS.bold} tooltip="Bold (⌘+B)">
      <BoldIcon />
    </MarkToolbarButton>
  );
}

Ownership

SurfaceOwnerWhat It Does
BasicMarksPlugin@platejs/basic-nodes/reactGroups bold, code, italic, strikethrough, subscript, superscript, and underline.
BaseBasicMarksPlugin@platejs/basic-nodesHeadless grouping plugin for the same seven marks.
BasicMarksKitRegistryAdds the full mark set, input rules, and client leaf components.
BaseBasicMarksKitRegistryAdds static/base mark plugins with static code, highlight, and kbd leaves.
Individual mark plugins@platejs/basic-nodesOwn mark keys, HTML parsing, render tags, and toggle transforms.
MarkToolbarButtonRegistry UIReads mark state and calls the mark toolbar hook.

BasicMarksPlugin is smaller than BasicMarksKit: highlight and kbd are separate plugins that the registry kit includes.

Mark Set

MarkPluginKeyRenderNotes
BoldBoldPluginKEYS.boldstrongDeserializes strong, b, and bold font weight.
ItalicItalicPluginKEYS.italicemDeserializes em, i, and italic font style.
UnderlineUnderlinePluginKEYS.underlineuDeserializes u and underline text decoration.
StrikethroughStrikethroughPluginKEYS.strikethroughsUses directional selection affinity.
CodeCodePluginKEYS.codecodeUses hard selection affinity and skips pre HTML parents.
SubscriptSubscriptPluginKEYS.subsubToggle removes superscript.
SuperscriptSuperscriptPluginKEYS.supsupToggle removes subscript.
HighlightHighlightPluginKEYS.highlightmarkUses directional selection affinity.
KbdKbdPluginKEYS.kbdkbdUses hard selection affinity.

Each base mark plugin extends editor.tf.<mark>.toggle() by calling editor.tf.toggleMark(type).

Input Rules

BasicMarksKit registers input rules explicitly. The package plugins do not enable them by default.

Rule FamilyKit Registration
BoldRules.markdownvariant: '*' and variant: '_'
ItalicRules.markdownvariant: '*' and variant: '_'
UnderlineRules.markdownDefault underline rule
CodeRules.markdownDefault inline code rule
StrikethroughRules.markdownDefault strikethrough rule
SubscriptRules.markdownDefault subscript rule
SuperscriptRules.markdownDefault superscript rule
HighlightRules.markdownvariant: '==' and variant: '≡'
MarkComboRules.markdownBold/italic/underline combinations

See Plugin Input Rules for the runtime model.

Manual Usage

Install the package when you want to compose marks yourself.

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

Add only the marks you need.

components/editor/mark-plugins.tsx
import {
  BoldPlugin,
  CodePlugin,
  ItalicPlugin,
  UnderlinePlugin,
} from '@platejs/basic-nodes/react';
 
export const markPlugins = [
  BoldPlugin,
  ItalicPlugin,
  UnderlinePlugin,
  CodePlugin,
];
components/editor/mark-plugins.tsx
import {
  BoldPlugin,
  CodePlugin,
  ItalicPlugin,
  UnderlinePlugin,
} from '@platejs/basic-nodes/react';
 
export const markPlugins = [
  BoldPlugin,
  ItalicPlugin,
  UnderlinePlugin,
  CodePlugin,
];

Use the individual pages for mark-specific setup and component details.

API Reference

APIPackageUse
BasicMarksPlugin@platejs/basic-nodes/reactReact grouping plugin for seven common marks.
BaseBasicMarksPlugin@platejs/basic-nodesHeadless grouping plugin for seven common marks.
BasicMarksKitRegistryFull client kit with highlight, kbd, input rules, and leaves.
BaseBasicMarksKitRegistryStatic/base kit for server or static rendering.
MarkToolbarButtonRegistry UIToolbar control for one mark key.