mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-01-06 02:17:49 +08:00
b941eea6da
* added JSDocs for almost all extensions * start adding commands jsdocs * add jsdocs for rest of extensions * add jsdocs for Extensions * add js docs for all extensions * add more jsdocs * add js docs for node spec definitions
95 lines
1.8 KiB
TypeScript
95 lines
1.8 KiB
TypeScript
import { mergeAttributes, Node, wrappingInputRule } from '@tiptap/core'
|
|
|
|
export interface BlockquoteOptions {
|
|
/**
|
|
* HTML attributes to add to the blockquote element
|
|
* @default {}
|
|
* @example { class: 'foo' }
|
|
*/
|
|
HTMLAttributes: Record<string, any>,
|
|
}
|
|
|
|
declare module '@tiptap/core' {
|
|
interface Commands<ReturnType> {
|
|
blockQuote: {
|
|
/**
|
|
* Set a blockquote node
|
|
*/
|
|
setBlockquote: () => ReturnType,
|
|
/**
|
|
* Toggle a blockquote node
|
|
*/
|
|
toggleBlockquote: () => ReturnType,
|
|
/**
|
|
* Unset a blockquote node
|
|
*/
|
|
unsetBlockquote: () => ReturnType,
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Matches a blockquote to a `>` as input.
|
|
*/
|
|
export const inputRegex = /^\s*>\s$/
|
|
|
|
/**
|
|
* This extension allows you to create blockquotes.
|
|
* @see https://tiptap.dev/api/nodes/blockquote
|
|
*/
|
|
export const Blockquote = Node.create<BlockquoteOptions>({
|
|
|
|
name: 'blockquote',
|
|
|
|
addOptions() {
|
|
return {
|
|
HTMLAttributes: {},
|
|
}
|
|
},
|
|
|
|
content: 'block+',
|
|
|
|
group: 'block',
|
|
|
|
defining: true,
|
|
|
|
parseHTML() {
|
|
return [
|
|
{ tag: 'blockquote' },
|
|
]
|
|
},
|
|
|
|
renderHTML({ HTMLAttributes }) {
|
|
return ['blockquote', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]
|
|
},
|
|
|
|
addCommands() {
|
|
return {
|
|
setBlockquote: () => ({ commands }) => {
|
|
return commands.wrapIn(this.name)
|
|
},
|
|
toggleBlockquote: () => ({ commands }) => {
|
|
return commands.toggleWrap(this.name)
|
|
},
|
|
unsetBlockquote: () => ({ commands }) => {
|
|
return commands.lift(this.name)
|
|
},
|
|
}
|
|
},
|
|
|
|
addKeyboardShortcuts() {
|
|
return {
|
|
'Mod-Shift-b': () => this.editor.commands.toggleBlockquote(),
|
|
}
|
|
},
|
|
|
|
addInputRules() {
|
|
return [
|
|
wrappingInputRule({
|
|
find: inputRegex,
|
|
type: this.type,
|
|
}),
|
|
]
|
|
},
|
|
})
|