Files
tiptap/packages/extension-horizontal-rule/src/index.ts
Philipp Kühn 0c9ce26c02 Revert "use global namespace"
This reverts commit 24c3a9abd3.

# Conflicts:
#	packages/core/src/Editor.ts
2020-11-16 16:58:30 +01:00

55 lines
921 B
TypeScript

import { Command, Node, nodeInputRule } from '@tiptap/core'
export interface HorizontalRuleOptions {
HTMLAttributes: {
[key: string]: any
},
}
const HorizontalRule = Node.create({
name: 'horizontalRule',
defaultOptions: <HorizontalRuleOptions>{
HTMLAttributes: {},
},
group: 'block',
parseHTML() {
return [
{ tag: 'hr' },
]
},
renderHTML({ HTMLAttributes }) {
return ['hr', HTMLAttributes]
},
addCommands() {
return {
/**
* Add a horizontal rule
*/
horizontalRule: (): Command => ({ tr }) => {
tr.replaceSelectionWith(this.type.create())
return true
},
}
},
addInputRules() {
return [
nodeInputRule(/^(?:---|___\s|\*\*\*\s)$/, this.type),
]
},
})
export default HorizontalRule
declare module '@tiptap/core' {
interface AllExtensions {
HorizontalRule: typeof HorizontalRule,
}
}