2020-10-22 18:34:49 +08:00
|
|
|
import { Command, createNode, nodeInputRule } from '@tiptap/core'
|
|
|
|
|
2020-10-23 04:40:40 +08:00
|
|
|
const HorizontalRule = createNode({
|
2020-10-22 18:34:49 +08:00
|
|
|
name: 'horizontalRule',
|
|
|
|
|
|
|
|
group: 'block',
|
|
|
|
|
|
|
|
parseHTML() {
|
|
|
|
return [
|
|
|
|
{ tag: 'hr' },
|
|
|
|
]
|
|
|
|
},
|
|
|
|
|
|
|
|
renderHTML({ attributes }) {
|
|
|
|
return ['hr', attributes]
|
|
|
|
},
|
|
|
|
|
|
|
|
addCommands() {
|
|
|
|
return {
|
2020-10-23 04:40:40 +08:00
|
|
|
horizontalRule: (): Command => ({ tr }) => {
|
2020-10-22 18:34:49 +08:00
|
|
|
tr.replaceSelectionWith(this.type.create())
|
|
|
|
|
|
|
|
return true
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
addInputRules() {
|
|
|
|
return [
|
|
|
|
nodeInputRule(/^(?:---|___\s|\*\*\*\s)$/, this.type),
|
|
|
|
]
|
|
|
|
},
|
|
|
|
})
|
2020-10-23 04:40:40 +08:00
|
|
|
|
|
|
|
export default HorizontalRule
|
|
|
|
|
2020-11-11 04:18:22 +08:00
|
|
|
declare module '@tiptap/core' {
|
2020-10-23 04:40:40 +08:00
|
|
|
interface AllExtensions {
|
|
|
|
HorizontalRule: typeof HorizontalRule,
|
|
|
|
}
|
|
|
|
}
|