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

reference.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: 9ae6ab07004e5e20d1b6cde7a795a9b400e07a4e (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
import { HIGHER_PARSE_RULE_PRIORITY } from '../constants';

// Transforms generated HTML back to GFM for Banzai::Filter::ReferenceFilter and subclasses
export default () => ({
  name: 'reference',
  schema: {
    inline: true,
    group: 'inline',
    atom: true,
    attrs: {
      className: {},
      referenceType: {},
      originalText: { default: null },
      href: {},
      text: {},
    },
    parseDOM: [
      {
        tag: 'a.gfm:not([data-link=true])',
        priority: HIGHER_PARSE_RULE_PRIORITY,
        getAttrs: (el) => ({
          className: el.className,
          referenceType: el.dataset.referenceType,
          originalText: el.dataset.original,
          href: el.getAttribute('href'),
          text: el.textContent,
        }),
      },
    ],
    toDOM: (node) => [
      'a',
      {
        class: node.attrs.className,
        href: node.attrs.href,
        'data-reference-type': node.attrs.referenceType,
        'data-original': node.attrs.originalText,
      },
      node.attrs.text,
    ],
  },
  toMarkdown(state, node) {
    state.write(node.attrs.originalText || node.attrs.text);
  },
});