Welcome to mirror list, hosted at ThFree Co, Russian Federation.

task_list_item.js « nodes « markdown « behaviors « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 56c2b17286da74b9d8dce9a5c8a7f105c20c733c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* eslint-disable class-methods-use-this */

import { Node } from 'tiptap';
import { HIGHER_PARSE_RULE_PRIORITY } from '../constants';

// Transforms generated HTML back to GFM for Banzai::Filter::TaskListFilter
export default class TaskListItem extends Node {
  get name() {
    return 'task_list_item';
  }

  get schema() {
    return {
      attrs: {
        done: {
          default: false,
        },
      },
      defining: true,
      draggable: false,
      content: 'paragraph block*',
      parseDOM: [
        {
          priority: HIGHER_PARSE_RULE_PRIORITY,
          tag: 'li.task-list-item',
          getAttrs: (el) => {
            const checkbox = el.querySelector('input[type=checkbox].task-list-item-checkbox');
            return { done: checkbox && checkbox.checked };
          },
        },
      ],
      toDOM(node) {
        return [
          'li',
          { class: 'task-list-item' },
          [
            'input',
            { type: 'checkbox', class: 'task-list-item-checkbox', checked: node.attrs.done },
          ],
          ['div', { class: 'todo-content' }, 0],
        ];
      },
    };
  }

  toMarkdown(state, node) {
    state.write(`[${node.attrs.done ? 'x' : ' '}] `);
    state.renderContent(node);
  }
}