debian-mirror-gitlab/app/assets/javascripts/behaviors/markdown/nodes/image.js

54 lines
1.4 KiB
JavaScript
Raw Normal View History

2019-03-02 22:35:43 +05:30
/* eslint-disable class-methods-use-this */
import { defaultMarkdownSerializer } from 'prosemirror-markdown';
2021-03-11 19:13:27 +05:30
import { Image as BaseImage } from 'tiptap-extensions';
2020-01-01 13:55:28 +05:30
import { placeholderImage } from '~/lazy_loader';
2020-03-13 15:44:24 +05:30
import { HIGHER_PARSE_RULE_PRIORITY } from '../constants';
2019-03-02 22:35:43 +05:30
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',
2020-03-13 15:44:24 +05:30
priority: HIGHER_PARSE_RULE_PRIORITY,
2019-03-02 22:35:43 +05:30
skip: true,
},
// Matches HTML generated by Banzai::Filter::ImageLazyLoadFilter
{
2021-11-18 22:05:49 +05:30
tag: 'img[src]:not(.emoji)',
2021-03-08 18:12:59 +05:30
getAttrs: (el) => {
2019-03-02 22:35:43 +05:30
const imageSrc = el.src;
const imageUrl =
imageSrc && imageSrc !== placeholderImage ? imageSrc : el.dataset.src || '';
return {
src: imageUrl,
title: el.getAttribute('title'),
alt: el.getAttribute('alt'),
};
},
},
],
2021-03-08 18:12:59 +05:30
toDOM: (node) => ['img', node.attrs],
2019-03-02 22:35:43 +05:30
};
}
toMarkdown(state, node) {
defaultMarkdownSerializer.nodes.image(state, node);
}
}