2021-08-31 12:11:07 +00:00
|
|
|
import { Node } from '@tiptap/core';
|
|
|
|
import { PARSE_HTML_PRIORITY_LOWEST } from '../constants';
|
|
|
|
|
2021-12-13 15:12:59 +00:00
|
|
|
const getDiv = (element) => {
|
|
|
|
if (element.nodeName === 'DIV') return element;
|
|
|
|
return element.querySelector('div');
|
|
|
|
};
|
|
|
|
|
2021-08-31 12:11:07 +00:00
|
|
|
export default Node.create({
|
|
|
|
name: 'division',
|
|
|
|
content: 'block*',
|
|
|
|
group: 'block',
|
|
|
|
defining: true,
|
|
|
|
|
2021-12-13 15:12:59 +00:00
|
|
|
addAttributes() {
|
|
|
|
return {
|
|
|
|
className: {
|
|
|
|
default: null,
|
|
|
|
parseHTML: (element) => getDiv(element).className || null,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2021-08-31 12:11:07 +00:00
|
|
|
parseHTML() {
|
|
|
|
return [{ tag: 'div', priority: PARSE_HTML_PRIORITY_LOWEST }];
|
|
|
|
},
|
|
|
|
|
|
|
|
renderHTML({ HTMLAttributes }) {
|
|
|
|
return ['div', HTMLAttributes, 0];
|
|
|
|
},
|
|
|
|
});
|