-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathrules.ts
52 lines (45 loc) · 1.13 KB
/
rules.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import {
ellipsis,
emDash,
inputRules,
smartQuotes,
textblockTypeInputRule,
wrappingInputRule,
} from 'prosemirror-inputrules'
import { Plugin } from 'prosemirror-state'
import { schema } from './schema'
export const rules = (): Plugin =>
inputRules({
rules: [
...smartQuotes,
ellipsis,
emDash,
// > blockquote
wrappingInputRule(/^\s*>\s$/, schema.nodes.blockquote),
// 1. ordered list
wrappingInputRule(
/^(\d+)\.\s$/,
schema.nodes.list,
(match) => {
return { type: 'ordered', start: +match[1] }
},
(match, node) => {
return node.childCount + Number(node.attrs.start) === +match[1]
}
),
// * bullet list
wrappingInputRule(/^\s*\*\s$/, schema.nodes.list, () => {
return { type: 'bullet' }
}),
// ``` code block
textblockTypeInputRule(/^```$/, schema.nodes.codeBlock),
// # heading
textblockTypeInputRule(
new RegExp('^(#{1,6})\\s$'),
schema.nodes.heading,
(match) => {
return { level: match[1].length }
}
),
],
})