Merge pull request #185 from Chrissi2812/inputrule-hr

added markdown rule for horizontal line
This commit is contained in:
Philipp Kühn 2019-02-01 17:55:11 +01:00 committed by GitHub
commit bc2a37df94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 0 deletions

View File

@ -0,0 +1,14 @@
import { InputRule } from 'prosemirror-inputrules'
export default function (regexp, type, getAttrs) {
return new InputRule(regexp, (state, match, start, end) => {
const attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs
const { tr } = state
if (match[0]) {
tr.replaceWith(start - 1, end, type.create(attrs))
}
return tr
})
}

View File

@ -40,6 +40,7 @@ import {
import insertText from './commands/insertText'
import markInputRule from './commands/markInputRule'
import nodeInputRule from './commands/nodeInputRule'
import pasteRule from './commands/pasteRule'
import removeMark from './commands/removeMark'
import replaceText from './commands/replaceText'
@ -91,6 +92,7 @@ export {
// custom
insertText,
markInputRule,
nodeInputRule,
pasteRule,
removeMark,
replaceText,

View File

@ -1,4 +1,5 @@
import { Node } from 'tiptap'
import { nodeInputRule } from 'tiptap-commands'
export default class HorizontalRule extends Node {
get name() {
@ -16,4 +17,10 @@ export default class HorizontalRule extends Node {
commands({ type }) {
return () => (state, dispatch) => dispatch(state.tr.replaceSelectionWith(type.create()))
}
inputRules({ type }) {
return [
nodeInputRule(/^(?:---|___\s|\*\*\*\s)$/, type),
]
}
}