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

image.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: 4cc28c45739d745996b9eeea35478da2900a8ee5 (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
51
52
53
/* eslint-disable class-methods-use-this */

import { defaultMarkdownSerializer } from 'prosemirror-markdown';
import { Image as BaseImage } from 'tiptap-extensions';
import { placeholderImage } from '~/lazy_loader';
import { HIGHER_PARSE_RULE_PRIORITY } from '../constants';

export default class Image extends BaseImage {
  get schema() {
    return {
      attrs: {
        src: {},
        alt: {
          default: null,
        },
        title: {
          default: null,
        },
      },
      group: 'inline',
      inline: true,
      draggable: true,
      parseDOM: [
        // Matches HTML generated by Banzai::Filter::ImageLinkFilter
        {
          tag: 'a.no-attachment-icon',
          priority: HIGHER_PARSE_RULE_PRIORITY,
          skip: true,
        },
        // Matches HTML generated by Banzai::Filter::ImageLazyLoadFilter
        {
          tag: 'img[src]:not(.emoji)',
          getAttrs: (el) => {
            const imageSrc = el.src;
            const imageUrl =
              imageSrc && imageSrc !== placeholderImage ? imageSrc : el.dataset.src || '';

            return {
              src: imageUrl,
              title: el.getAttribute('title'),
              alt: el.getAttribute('alt'),
            };
          },
        },
      ],
      toDOM: (node) => ['img', node.attrs],
    };
  }

  toMarkdown(state, node) {
    defaultMarkdownSerializer.nodes.image(state, node);
  }
}