Commit 46c10594 authored by Andrew Fontaine's avatar Andrew Fontaine

Merge branch 'himkp-content-editor-title-attr' into 'master'

Allow title attribute in elements in content editor

See merge request gitlab-org/gitlab!68086
parents fed187a7 29e0ecb1
...@@ -22,6 +22,7 @@ export default { ...@@ -22,6 +22,7 @@ export default {
<img <img
data-testid="image" data-testid="image"
class="gl-max-w-full gl-h-auto" class="gl-max-w-full gl-h-auto"
:title="node.attrs.title"
:class="{ 'gl-opacity-5': node.attrs.uploading }" :class="{ 'gl-opacity-5': node.attrs.uploading }"
:src="node.attrs.src" :src="node.attrs.src"
/> />
......
...@@ -50,6 +50,16 @@ export default Image.extend({ ...@@ -50,6 +50,16 @@ export default Image.extend({
}; };
}, },
}, },
title: {
default: null,
parseHTML: (element) => {
const img = resolveImageEl(element);
return {
title: img.getAttribute('title'),
};
},
},
}; };
}, },
parseHTML() { parseHTML() {
......
...@@ -42,6 +42,14 @@ export default Link.extend({ ...@@ -42,6 +42,14 @@ export default Link.extend({
}; };
}, },
}, },
title: {
title: null,
parseHTML: (element) => {
return {
title: element.getAttribute('title'),
};
},
},
canonicalSrc: { canonicalSrc: {
default: null, default: null,
parseHTML: (element) => { parseHTML: (element) => {
......
...@@ -115,6 +115,64 @@ describe('markdownSerializer', () => { ...@@ -115,6 +115,64 @@ describe('markdownSerializer', () => {
expect(serialize(paragraph('hello', hardBreak(), 'world'))).toBe('hello\\\nworld'); expect(serialize(paragraph('hello', hardBreak(), 'world'))).toBe('hello\\\nworld');
}); });
it('correctly serializes a link', () => {
expect(serialize(paragraph(link({ href: 'https://example.com' }, 'example url')))).toBe(
'[example url](https://example.com)',
);
});
it('correctly serializes a link with a title', () => {
expect(
serialize(
paragraph(link({ href: 'https://example.com', title: 'click this link' }, 'example url')),
),
).toBe('[example url](https://example.com "click this link")');
});
it('correctly serializes a link with a canonicalSrc', () => {
expect(
serialize(
paragraph(
link(
{
href: '/uploads/abcde/file.zip',
canonicalSrc: 'file.zip',
title: 'click here to download',
},
'download file',
),
),
),
).toBe('[download file](file.zip "click here to download")');
});
it('correctly serializes an image', () => {
expect(serialize(paragraph(image({ src: 'img.jpg', alt: 'foo bar' })))).toBe(
'![foo bar](img.jpg)',
);
});
it('correctly serializes an image with a title', () => {
expect(serialize(paragraph(image({ src: 'img.jpg', title: 'baz', alt: 'foo bar' })))).toBe(
'![foo bar](img.jpg "baz")',
);
});
it('correctly serializes an image with a canonicalSrc', () => {
expect(
serialize(
paragraph(
image({
src: '/uploads/abcde/file.png',
alt: 'this is an image',
canonicalSrc: 'file.png',
title: 'foo bar baz',
}),
),
),
).toBe('![this is an image](file.png "foo bar baz")');
});
it('correctly serializes a table with inline content', () => { it('correctly serializes a table with inline content', () => {
expect( expect(
serialize( serialize(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment