debian-mirror-gitlab/spec/frontend/content_editor/test_utils.js

35 lines
749 B
JavaScript
Raw Normal View History

2021-06-08 01:23:25 +05:30
import { Node } from '@tiptap/core';
export const createTestContentEditorExtension = () => ({
tiptapExtension: Node.create({
name: 'label',
priority: 101,
inline: true,
group: 'inline',
addAttributes() {
return {
labelName: {
default: null,
parseHTML: (element) => {
return { labelName: element.dataset.labelName };
},
},
};
},
parseHTML() {
return [
{
tag: 'span[data-reference="label"]',
},
];
},
renderHTML({ HTMLAttributes }) {
return ['span', HTMLAttributes, 0];
},
}),
serializer: (state, node) => {
state.write(`~${node.attrs.labelName}`);
state.closeBlock(node);
},
});