A blockquote extension for the Tiptap rich text editor framework
npx @tessl/cli install tessl/npm-tiptap--extension-blockquote@3.4.0The Tiptap Blockquote Extension provides blockquote functionality for the Tiptap rich text editor framework. It allows users to create, toggle, and manipulate blockquote elements with keyboard shortcuts, input rules, and programmatic commands.
npm install @tiptap/extension-blockquoteimport { Blockquote } from '@tiptap/extension-blockquote';For default import:
import Blockquote from '@tiptap/extension-blockquote';For importing additional exports:
import { Blockquote, inputRegex, type BlockquoteOptions } from '@tiptap/extension-blockquote';For CommonJS:
const { Blockquote } = require('@tiptap/extension-blockquote');import { Editor } from '@tiptap/core';
import { Blockquote } from '@tiptap/extension-blockquote';
const editor = new Editor({
extensions: [
Blockquote.configure({
HTMLAttributes: {
class: 'my-custom-blockquote',
},
}),
],
content: '<p>Type > and a space to create a blockquote</p>',
});
// Use commands programmatically
editor.commands.setBlockquote(); // Wrap selection in blockquote
editor.commands.toggleBlockquote(); // Toggle blockquote
editor.commands.unsetBlockquote(); // Remove blockquote wrappingThe main Blockquote extension that integrates with Tiptap's node system.
/**
* Blockquote extension for Tiptap editor
* Provides blockquote functionality with commands, keyboard shortcuts, and input rules
*/
const Blockquote: Node<BlockquoteOptions, any>;Configure the blockquote extension behavior and HTML attributes.
interface BlockquoteOptions {
/**
* HTML attributes to add to the blockquote element
* @default {}
* @example { class: 'foo' }
*/
HTMLAttributes: Record<string, any>;
}Usage Example:
import { Blockquote } from '@tiptap/extension-blockquote';
const editor = new Editor({
extensions: [
Blockquote.configure({
HTMLAttributes: {
class: 'prose-blockquote',
'data-type': 'blockquote',
},
}),
],
});The extension adds three commands to the editor's command system.
interface Commands {
blockQuote: {
/**
* Set a blockquote node - wraps the current selection in a blockquote
* @returns Command function that returns boolean indicating success
*/
setBlockquote(): Command;
/**
* Toggle a blockquote node - toggles blockquote wrapping on selection
* @returns Command function that returns boolean indicating success
*/
toggleBlockquote(): Command;
/**
* Unset a blockquote node - removes blockquote wrapping from selection
* @returns Command function that returns boolean indicating success
*/
unsetBlockquote(): Command;
};
}Usage Examples:
// Wrap current selection in blockquote
if (editor.commands.setBlockquote()) {
console.log('Successfully created blockquote');
}
// Toggle blockquote (create if none, remove if exists)
editor.commands.toggleBlockquote();
// Remove blockquote wrapping
editor.commands.unsetBlockquote();
// Check if current selection can be wrapped in blockquote
if (editor.can().setBlockquote()) {
editor.commands.setBlockquote();
}The extension automatically creates blockquotes when users type the trigger pattern.
/**
* Regular expression that matches blockquote input trigger
* Matches "> " at the beginning of a line (with optional whitespace)
*/
const inputRegex: RegExp;Behavior:
> followed by a space at the start of a line automatically creates a blockquote> and space are consumed and replaced with the blockquote structureThe extension provides keyboard shortcuts for quick blockquote manipulation.
Available Shortcuts:
Mod-Shift-b: Toggle blockquote (⌘⇧B on Mac, Ctrl+Shift+B on Windows/Linux)The blockquote node has the following ProseMirror characteristics:
'blockquote''block+' (contains one or more block-level elements)'block' (belongs to the block content group)true (creates structural boundaries in the document)The extension handles HTML parsing and rendering:
HTML Parsing:
<blockquote> elements when parsing HTML contentHTML Rendering:
<blockquote> elementsinterface BlockquoteOptions {
HTMLAttributes: Record<string, any>;
}
type Command = (props: {
editor: Editor;
tr: Transaction;
commands: Commands;
can: () => Commands;
chain: () => Commands;
state: EditorState;
dispatch: ((tr: Transaction) => void) | undefined;
view: EditorView;
}) => boolean;The extension follows Tiptap's standard error handling patterns:
boolean values indicating success/failurefalse