add heading input rule

This commit is contained in:
Philipp Kühn 2020-04-21 22:48:27 +02:00
parent 4a94b76455
commit 3deae61a15

View File

@ -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 })
})
}
}