mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-06-12 04:33:34 +08:00
add heading input rule
This commit is contained in:
parent
4a94b76455
commit
3deae61a15
@ -1,5 +1,7 @@
|
||||
import { Node, CommandSpec } from '@tiptap/core'
|
||||
import { NodeSpec } from 'prosemirror-model'
|
||||
import VerEx from 'verbal-expressions'
|
||||
import { textblockTypeInputRule } from 'prosemirror-inputrules'
|
||||
|
||||
type Level = 1 | 2 | 3 | 4 | 5 | 6
|
||||
|
||||
@ -52,4 +54,17 @@ export default class Heading extends Node {
|
||||
}
|
||||
}
|
||||
|
||||
inputRules() {
|
||||
return this.options.levels.map((level: Level) => {
|
||||
const regex = VerEx()
|
||||
.startOfLine()
|
||||
.find('#')
|
||||
.repeatPrevious(level)
|
||||
.whitespace()
|
||||
.endOfLine()
|
||||
|
||||
return textblockTypeInputRule(regex, this.type, { level })
|
||||
})
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user