File tree 1 file changed +33
-0
lines changed
packages/core/src/blocks/QuoteBlockContent
1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import { createDefaultBlockDOMOutputSpec } from "../defaultBlockHelpers.js";
6
6
import { defaultProps } from "../defaultProps.js" ;
7
7
import { getBlockInfoFromSelection } from "../../api/getBlockInfoFromPos.js" ;
8
8
import { updateBlockCommand } from "../../api/blockManipulation/commands/updateBlock/updateBlock.js" ;
9
+ import { InputRule } from "@tiptap/core" ;
9
10
10
11
export const quotePropSchema = {
11
12
...defaultProps ,
@@ -16,6 +17,38 @@ export const QuoteBlockContent = createStronglyTypedTiptapNode({
16
17
content : "inline*" ,
17
18
group : "blockContent" ,
18
19
20
+ addInputRules ( ) {
21
+ return [
22
+ // Creates a block quote when starting with ">".
23
+ new InputRule ( {
24
+ find : new RegExp ( `^>\\s$` ) ,
25
+ handler : ( { state, chain, range } ) => {
26
+ const blockInfo = getBlockInfoFromSelection ( state ) ;
27
+ if (
28
+ ! blockInfo . isBlockContainer ||
29
+ blockInfo . blockContent . node . type . spec . content !== "inline*"
30
+ ) {
31
+ return ;
32
+ }
33
+
34
+ chain ( )
35
+ . command (
36
+ updateBlockCommand (
37
+ this . options . editor ,
38
+ blockInfo . bnBlock . beforePos ,
39
+ {
40
+ type : "quote" ,
41
+ props : { } ,
42
+ }
43
+ )
44
+ )
45
+ // Removes the ">" character used to set the list.
46
+ . deleteRange ( { from : range . from , to : range . to } ) ;
47
+ } ,
48
+ } ) ,
49
+ ] ;
50
+ } ,
51
+
19
52
addKeyboardShortcuts ( ) {
20
53
return {
21
54
"Mod-Alt-q" : ( ) => {
You can’t perform that action at this time.
0 commit comments