mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-01-19 06:43:02 +08:00
Merge pull request #185 from Chrissi2812/inputrule-hr
added markdown rule for horizontal line
This commit is contained in:
commit
bc2a37df94
14
packages/tiptap-commands/src/commands/nodeInputRule.js
Normal file
14
packages/tiptap-commands/src/commands/nodeInputRule.js
Normal 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
|
||||
})
|
||||
}
|
@ -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,
|
||||
|
@ -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),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user