debian-mirror-gitlab/app/assets/javascripts/behaviors/markdown/marks/link.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

48 lines
1.2 KiB
JavaScript
Raw Normal View History

2022-04-04 11:22:00 +05:30
import { defaultMarkdownSerializer } from '~/lib/prosemirror_markdown_serializer';
2019-03-02 22:35:43 +05:30
// Transforms generated HTML back to GFM for Banzai::Filter::MarkdownFilter
2022-05-07 20:08:51 +05:30
export default () => ({
name: 'link',
schema: {
attrs: {
href: {
default: null,
},
target: {
default: null,
},
},
inclusive: false,
parseDOM: [
{
tag: 'a[href]',
getAttrs: (dom) => ({
href: dom.getAttribute('href'),
target: dom.getAttribute('target'),
}),
2019-03-02 22:35:43 +05:30
},
2022-05-07 20:08:51 +05:30
],
toDOM: (node) => [
'a',
{
...node.attrs,
// eslint-disable-next-line @gitlab/require-i18n-strings
rel: 'noopener noreferrer nofollow',
target: node.attrs.target,
2019-03-02 22:35:43 +05:30
},
2022-05-07 20:08:51 +05:30
0,
],
},
toMarkdown: {
mixable: true,
open(state, mark, parent, index) {
const open = defaultMarkdownSerializer.marks.link.open(state, mark, parent, index);
return open === '<' ? '' : open;
},
close(state, mark, parent, index) {
const close = defaultMarkdownSerializer.marks.link.close(state, mark, parent, index);
return close === '>' ? '' : close;
},
},
});