Skip to content

Commit 63f9a9b

Browse files
committed
Added input rule
1 parent 17a623a commit 63f9a9b

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

packages/core/src/blocks/QuoteBlockContent/QuoteBlockContent.ts

+33
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { createDefaultBlockDOMOutputSpec } from "../defaultBlockHelpers.js";
66
import { defaultProps } from "../defaultProps.js";
77
import { getBlockInfoFromSelection } from "../../api/getBlockInfoFromPos.js";
88
import { updateBlockCommand } from "../../api/blockManipulation/commands/updateBlock/updateBlock.js";
9+
import { InputRule } from "@tiptap/core";
910

1011
export const quotePropSchema = {
1112
...defaultProps,
@@ -16,6 +17,38 @@ export const QuoteBlockContent = createStronglyTypedTiptapNode({
1617
content: "inline*",
1718
group: "blockContent",
1819

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+
1952
addKeyboardShortcuts() {
2053
return {
2154
"Mod-Alt-q": () => {

0 commit comments

Comments
 (0)