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 { Image as BaseImage } from 'tiptap-extensions';
import { defaultMarkdownSerializer } from 'prosemirror-markdown';
2020-01-01 13:55:28 +05:30
import { placeholderImage } from '~/lazy_loader';
2020-03-09 13:42:32 +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-09 13:42:32 +05:30
priority: HIGHER_PARSE_RULE_PRIORITY,
2019-03-02 22:35:43 +05:30
skip: true,
},
// Matches HTML generated by Banzai::Filter::ImageLazyLoadFilter
{
tag: 'img[src]',
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);
}
}