Strikethrough

PreviousNext

Strike through inline text.

Strikethrough applies the strikethrough leaf mark to selected text. The package owns the mark semantics; BasicMarksKit adds the Markdown-style input rule and shortcut.

Loading…

Features

  • KEYS.strikethrough leaf mark.
  • Directional selection affinity.
  • HTML deserialization from s, del, strike, and line-through text decoration.
  • <s> rendering by default.
  • Optional Markdown-style input rule through StrikethroughRules.
  • Toolbar support through MarkToolbarButton.

Kit Usage

Add Basic Marks

BasicMarksKit includes StrikethroughPlugin, ~~ input rules, and a mod+shift+x shortcut.

'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 A Toolbar Button

Use MarkToolbarButton with KEYS.strikethrough.

import { StrikethroughIcon } from 'lucide-react';
import { KEYS } from 'platejs';
 
import { MarkToolbarButton } from '@/components/ui/mark-toolbar-button';
 
export function StrikethroughToolbarButton() {
  return (
    <MarkToolbarButton
      nodeType={KEYS.strikethrough}
      tooltip="Strikethrough"
    >
      <StrikethroughIcon />
    </MarkToolbarButton>
  );
}
import { StrikethroughIcon } from 'lucide-react';
import { KEYS } from 'platejs';
 
import { MarkToolbarButton } from '@/components/ui/mark-toolbar-button';
 
export function StrikethroughToolbarButton() {
  return (
    <MarkToolbarButton
      nodeType={KEYS.strikethrough}
      tooltip="Strikethrough"
    >
      <StrikethroughIcon />
    </MarkToolbarButton>
  );
}

Manual Usage

Install the mark package.

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

Add StrikethroughPlugin directly when you want the default <s> render.

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

Configure the input rule and shortcut when you want the same behavior as the kit.

import { StrikethroughRules } from '@platejs/basic-nodes';
import { StrikethroughPlugin } from '@platejs/basic-nodes/react';
 
export const strikethroughPlugin = StrikethroughPlugin.configure({
  inputRules: [StrikethroughRules.markdown()],
  shortcuts: { toggle: { keys: 'mod+shift+x' } },
});
import { StrikethroughRules } from '@platejs/basic-nodes';
import { StrikethroughPlugin } from '@platejs/basic-nodes/react';
 
export const strikethroughPlugin = StrikethroughPlugin.configure({
  inputRules: [StrikethroughRules.markdown()],
  shortcuts: { toggle: { keys: 'mod+shift+x' } },
});

Ownership

SurfaceOwnerWhat It Does
BaseStrikethroughPlugin@platejs/basic-nodesHeadless strikethrough mark, HTML parser, render tag, selection rule, and toggle transform.
StrikethroughPlugin@platejs/basic-nodes/reactReact wrapper for the headless strikethrough mark.
StrikethroughRules.markdown@platejs/basic-nodesOptional ~~ mark input rule factory.
BasicMarksKitRegistryAdds StrikethroughPlugin, the input rule, and mod+shift+x.
MarkToolbarButtonRegistry UIReads active mark state and calls the mark toggle hook.

The package owns the mark. The registry owns shortcut configuration and toolbar placement.

Behavior

BehaviorSource
Mark keyKEYS.strikethrough
Leaf behaviornode.isLeaf: true
Toggle transformeditor.tf.strikethrough.toggle() calls editor.tf.toggleMark(type).
Selection affinitydirectional
HTML tagss, del, strike
HTML stylestext-decoration: line-through
HTML guardIgnores descendants where textDecoration is none.
Render outputs
Kit input ruleStrikethroughRules.markdown()
Kit shortcutmod+shift+x

API Reference

APIPackageUse
BaseStrikethroughPlugin@platejs/basic-nodesHeadless strikethrough plugin.
StrikethroughPlugin@platejs/basic-nodes/reactReact strikethrough plugin.
StrikethroughRules.markdown()@platejs/basic-nodesCreates the ~~ mark input rule.
tf.strikethrough.toggle()@platejs/basic-nodesToggles the strikethrough mark at the selection.