or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-tiptap--extension-strike

Strike extension for tiptap rich text editor that adds strikethrough text formatting

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@tiptap/extension-strike@3.4.x

To install, run

npx @tessl/cli install tessl/npm-tiptap--extension-strike@3.4.0

index.mddocs/

Tiptap Strike Extension

The Strike extension for tiptap provides strikethrough text formatting functionality. This extension allows users to apply, toggle, and remove strikethrough formatting in rich text editors, with keyboard shortcuts and automatic parsing of markdown-style strikethrough syntax.

Package Information

  • Package Name: @tiptap/extension-strike
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install @tiptap/extension-strike

Core Imports

import { Strike } from "@tiptap/extension-strike";

For full imports:

import { Strike, StrikeOptions, inputRegex, pasteRegex } from "@tiptap/extension-strike";

CommonJS:

const { Strike } = require("@tiptap/extension-strike");

Basic Usage

import { Strike } from "@tiptap/extension-strike";
import { Editor } from "@tiptap/core";

// Register the extension
const editor = new Editor({
  extensions: [
    Strike,
    // ... other extensions
  ],
});

// Use commands programmatically
editor.commands.setStrike();      // Apply strikethrough
editor.commands.toggleStrike();   // Toggle strikethrough
editor.commands.unsetStrike();    // Remove strikethrough

// Use keyboard shortcut: Mod-Shift-s (Ctrl+Shift+s or Cmd+Shift+s)
// Type markdown syntax: ~~strikethrough text~~

Capabilities

Strike Extension Class

Creates a tiptap extension that provides strikethrough text formatting capabilities.

/**
 * Strike extension for tiptap that adds strikethrough text formatting
 */
const Strike: Mark<StrikeOptions>;

Extension Configuration

Configure the Strike extension with HTML attributes.

interface StrikeOptions {
  /**
   * HTML attributes to add to the strike element.
   * @default {}
   * @example { class: 'custom-strike', 'data-testid': 'strike' }
   */
  HTMLAttributes: Record<string, any>;
}

Strike Commands

The extension adds these commands to the editor's command interface:

interface StrikeCommands {
  /**
   * Set a strike mark on the current selection
   * @example editor.commands.setStrike()
   */
  setStrike(): boolean;
  
  /**
   * Toggle a strike mark on the current selection
   * @example editor.commands.toggleStrike()
   */
  toggleStrike(): boolean;
  
  /**
   * Remove strike mark from the current selection
   * @example editor.commands.unsetStrike()
   */
  unsetStrike(): boolean;
}

Input Pattern Matching

Regular expressions used for automatic strikethrough text parsing:

/**
 * Matches strikethrough syntax on input: ~~text~~
 * Used to automatically convert typed markdown syntax to strike formatting
 */
const inputRegex: RegExp;

/**
 * Matches strikethrough syntax on paste: ~~text~~
 * Used to automatically convert pasted markdown syntax to strike formatting
 */
const pasteRegex: RegExp;

Extension Methods

Core extension methods for HTML processing and behavior:

interface StrikeExtension {
  /**
   * Returns default configuration options for the extension
   */
  addOptions(): StrikeOptions;
  
  /**
   * Defines how HTML elements are parsed into strike marks
   * Supports: <s>, <del>, <strike> tags and text-decoration: line-through
   */
  parseHTML(): Array<{
    tag?: string;
    style?: string;
    consuming?: boolean;
    getAttrs?: (value: string) => any;
  }>;
  
  /**
   * Defines how strike marks are rendered as HTML
   * Renders as <s> tag with merged attributes
   */
  renderHTML(props: { HTMLAttributes: Record<string, any> }): [string, Record<string, any>, number];
  
  /**
   * Adds strike-related commands to the editor
   */
  addCommands(): Record<string, () => (props: any) => boolean>;
  
  /**
   * Adds keyboard shortcuts for strike functionality
   * Registers Mod-Shift-s (Ctrl+Shift+s or Cmd+Shift+s) to toggle strike
   */
  addKeyboardShortcuts(): Record<string, () => boolean>;
  
  /**
   * Adds input rules for automatic markdown-style parsing
   * Converts ~~text~~ to strikethrough formatting while typing
   */
  addInputRules(): Array<any>;
  
  /**
   * Adds paste rules for automatic markdown-style parsing
   * Converts ~~text~~ to strikethrough formatting when pasting
   */
  addPasteRules(): Array<any>;
}

Usage Examples

Basic Setup

import { Strike } from "@tiptap/extension-strike";
import { Editor } from "@tiptap/core";

const editor = new Editor({
  extensions: [
    Strike.configure({
      HTMLAttributes: {
        class: 'my-strike-class',
      },
    }),
  ],
  content: '<p>This is <s>strikethrough</s> text.</p>',
});

Programmatic Control

// Check if strike is active
const isActive = editor.isActive('strike');

// Apply strikethrough to current selection
if (!isActive) {
  editor.commands.setStrike();
}

// Toggle strikethrough
editor.commands.toggleStrike();

// Remove strikethrough
editor.commands.unsetStrike();

HTML Output

The extension renders strikethrough text using the <s> HTML tag:

<!-- Input: ~~strikethrough~~ -->
<p>This is <s>strikethrough</s> text.</p>

<!-- With custom HTMLAttributes -->
<p>This is <s class="my-strike-class">strikethrough</s> text.</p>

Supported HTML Input

The extension recognizes these HTML elements as strikethrough:

  • <s>strikethrough</s>
  • <del>strikethrough</del>
  • <strike>strikethrough</strike>
  • <span style="text-decoration: line-through">strikethrough</span>

Keyboard Shortcuts

  • Windows/Linux: Ctrl + Shift + S
  • macOS: Cmd + Shift + S

Markdown-Style Input

Users can type ~~text~~ and it will automatically convert to strikethrough formatting, both when typing and when pasting content.