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

comment.js « extensions « content_editor « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8e247e552a39718d2260a481a8aa7752055b5a68 (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
import { Node, textblockTypeInputRule } from '@tiptap/core';

export const commentInputRegex = /^<!--[\s\n]$/;

export default Node.create({
  name: 'comment',
  content: 'text*',
  marks: '',
  group: 'block',
  code: true,
  isolating: true,
  defining: true,

  parseHTML() {
    return [
      {
        tag: 'comment',
        preserveWhitespace: 'full',
        getContent(element, schema) {
          const node = schema.node('paragraph', {}, [
            schema.text(
              element.textContent.replace(/&#x([0-9A-F]{2,4});/gi, (_, code) =>
                String.fromCharCode(parseInt(code, 16)),
              ) || ' ',
            ),
          ]);
          return node.content;
        },
      },
    ];
  },

  renderHTML() {
    return [
      'pre',
      { class: 'gl-p-0 gl-border-0 gl-bg-transparent gl-text-gray-300' },
      ['span', { class: 'content-editor-comment' }, 0],
    ];
  },

  addInputRules() {
    return [
      textblockTypeInputRule({
        find: commentInputRegex,
        type: this.type,
      }),
    ];
  },
});