summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/behaviors/markdown/marks/inline_diff.js
blob: 7f1506cd5d94c5d978209726f6f78e950a4d58f8 (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
/* eslint-disable class-methods-use-this */

import { Mark } from 'tiptap';

// Transforms generated HTML back to GFM for Banzai::Filter::InlineDiffFilter
export default class InlineDiff extends Mark {
  get name() {
    return 'inline_diff';
  }

  get schema() {
    return {
      attrs: {
        addition: {
          default: true,
        },
      },
      parseDOM: [
        { tag: 'span.idiff.addition', attrs: { addition: true } },
        { tag: 'span.idiff.deletion', attrs: { addition: false } },
      ],
      toDOM: (node) => [
        'span',
        { class: `idiff left right ${node.attrs.addition ? 'addition' : 'deletion'}` },
        0,
      ],
    };
  }

  get toMarkdown() {
    return {
      mixable: true,
      open(state, mark) {
        return mark.attrs.addition ? '{+' : '{-';
      },
      close(state, mark) {
        return mark.attrs.addition ? '+}' : '-}';
      },
    };
  }
}