2020-01-01 13:55:28 +05:30
|
|
|
import { placeholderImage } from '~/lazy_loader';
|
2022-04-04 11:22:00 +05:30
|
|
|
import { defaultMarkdownSerializer } from '~/lib/prosemirror_markdown_serializer';
|
2020-03-13 15:44:24 +05:30
|
|
|
import { HIGHER_PARSE_RULE_PRIORITY } from '../constants';
|
2019-03-02 22:35:43 +05:30
|
|
|
|
2022-05-07 20:08:51 +05:30
|
|
|
export default () => ({
|
|
|
|
name: 'image',
|
|
|
|
schema: {
|
|
|
|
attrs: {
|
|
|
|
src: {},
|
|
|
|
alt: {
|
|
|
|
default: null,
|
2019-03-02 22:35:43 +05:30
|
|
|
},
|
2022-05-07 20:08:51 +05:30
|
|
|
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 || '';
|
2019-03-02 22:35:43 +05:30
|
|
|
|
2022-05-07 20:08:51 +05:30
|
|
|
return {
|
|
|
|
src: imageUrl,
|
|
|
|
title: el.getAttribute('title'),
|
|
|
|
alt: el.getAttribute('alt'),
|
|
|
|
};
|
2019-03-02 22:35:43 +05:30
|
|
|
},
|
2022-05-07 20:08:51 +05:30
|
|
|
},
|
|
|
|
],
|
|
|
|
toDOM: (node) => ['img', node.attrs],
|
|
|
|
},
|
2019-03-02 22:35:43 +05:30
|
|
|
toMarkdown(state, node) {
|
|
|
|
defaultMarkdownSerializer.nodes.image(state, node);
|
2022-05-07 20:08:51 +05:30
|
|
|
},
|
|
|
|
});
|