debian-mirror-gitlab/app/assets/javascripts/content_editor/extensions/division.js

32 lines
663 B
JavaScript
Raw Normal View History

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