Merge pull request #185 from Chrissi2812/inputrule-hr
added markdown rule for horizontal line
This commit is contained in:
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 insertText from './commands/insertText'
|
||||||
import markInputRule from './commands/markInputRule'
|
import markInputRule from './commands/markInputRule'
|
||||||
|
import nodeInputRule from './commands/nodeInputRule'
|
||||||
import pasteRule from './commands/pasteRule'
|
import pasteRule from './commands/pasteRule'
|
||||||
import removeMark from './commands/removeMark'
|
import removeMark from './commands/removeMark'
|
||||||
import replaceText from './commands/replaceText'
|
import replaceText from './commands/replaceText'
|
||||||
@@ -91,6 +92,7 @@ export {
|
|||||||
// custom
|
// custom
|
||||||
insertText,
|
insertText,
|
||||||
markInputRule,
|
markInputRule,
|
||||||
|
nodeInputRule,
|
||||||
pasteRule,
|
pasteRule,
|
||||||
removeMark,
|
removeMark,
|
||||||
replaceText,
|
replaceText,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { Node } from 'tiptap'
|
import { Node } from 'tiptap'
|
||||||
|
import { nodeInputRule } from 'tiptap-commands'
|
||||||
|
|
||||||
export default class HorizontalRule extends Node {
|
export default class HorizontalRule extends Node {
|
||||||
get name() {
|
get name() {
|
||||||
@@ -16,4 +17,10 @@ export default class HorizontalRule extends Node {
|
|||||||
commands({ type }) {
|
commands({ type }) {
|
||||||
return () => (state, dispatch) => dispatch(state.tr.replaceSelectionWith(type.create()))
|
return () => (state, dispatch) => dispatch(state.tr.replaceSelectionWith(type.create()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inputRules({ type }) {
|
||||||
|
return [
|
||||||
|
nodeInputRule(/^(?:---|___\s|\*\*\*\s)$/, type),
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user