tiptap/packages/extension-codeblock/index.ts

24 lines
492 B
TypeScript
Raw Normal View History

2020-04-02 14:53:59 +08:00
import { Node } from '@tiptap/core'
2020-09-09 05:44:45 +08:00
export default new Node()
2020-09-10 21:03:48 +08:00
.name('codeBlock')
2020-09-09 05:44:45 +08:00
.schema(() => ({
content: 'text*',
marks: '',
group: 'block',
code: true,
defining: true,
draggable: false,
parseDOM: [
{ tag: 'pre', preserveWhitespace: 'full' },
],
toDOM: () => ['pre', ['code', 0]],
}))
2020-09-10 21:03:48 +08:00
.commands(({ editor, name }) => ({
[name]: next => attrs => {
editor.toggleNode(name, 'paragraph', attrs)
next()
},
}))
2020-09-09 05:44:45 +08:00
.create()