2 * @param {Editor} editor
6 function register(editor, url) {
8 editor.on('PreInit', () => {
10 editor.parser.addNodeFilter('li', function(nodes) {
11 for (const node of nodes) {
12 if (node.attributes.map.class === 'task-list-item') {
13 parseTaskListNode(node);
18 editor.serializer.addNodeFilter('li', function(nodes) {
19 for (const node of nodes) {
20 if (node.attributes.map.class === 'task-list-item') {
21 serializeTaskListNode(node);
31 * @param {AstNode} node
33 function parseTaskListNode(node) {
34 // Force task list item class
35 node.attr('class', 'task-list-item');
37 // Copy checkbox status and remove checkbox within editor
38 for (const child of node.children()) {
39 if (child.name === 'input') {
40 if (child.attr('checked') === 'checked') {
41 node.attr('checked', 'checked');
49 * @param {AstNode} node
51 function serializeTaskListNode(node) {
52 const isChecked = node.attr('checked') === 'checked';
53 node.attr('checked', null);
55 const inputAttrs = {type: 'checkbox', disabled: 'disabled'};
57 inputAttrs.checked = 'checked';
60 const checkbox = new tinymce.html.Node.create('input', inputAttrs);
61 checkbox.shortEnded = true;
62 node.firstChild ? node.insert(checkbox, node.firstChild, true) : node.append(checkbox);
66 * @param {WysiwygConfigOptions} options
69 export function getPlugin(options) {