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

footnote_definition.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: bf752918934c4d565702a0f87af0347f382c533f (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
import { mergeAttributes, Node } from '@tiptap/core';
import { VueNodeViewRenderer } from '@tiptap/vue-2';
import FootnoteDefinitionWrapper from '../components/wrappers/footnote_definition.vue';
import { PARSE_HTML_PRIORITY_HIGHEST } from '../constants';

const extractFootnoteIdentifier = (idAttribute) => /^fn-(\w+)-\d+$/.exec(idAttribute)?.[1];

export default Node.create({
  name: 'footnoteDefinition',
  content: 'paragraph',
  group: 'block',
  isolating: true,
  addAttributes() {
    return {
      identifier: {
        default: null,
        parseHTML: (element) => extractFootnoteIdentifier(element.getAttribute('id')),
      },
      label: {
        default: null,
        parseHTML: (element) => extractFootnoteIdentifier(element.getAttribute('id')),
      },
    };
  },

  parseHTML() {
    return [
      { tag: 'section.footnotes li' },
      { tag: '.footnote-backref', priority: PARSE_HTML_PRIORITY_HIGHEST, ignore: true },
    ];
  },

  renderHTML({ label, ...HTMLAttributes }) {
    return ['div', mergeAttributes(HTMLAttributes), 0];
  },

  addNodeView() {
    return new VueNodeViewRenderer(FootnoteDefinitionWrapper);
  },
});