debian-mirror-gitlab/app/assets/javascripts/content_editor/extensions/reference.js

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

56 lines
1.2 KiB
JavaScript
Raw Normal View History

2021-10-27 15:23:28 +05:30
import { Node } from '@tiptap/core';
2021-11-11 11:23:49 +05:30
import { PARSE_HTML_PRIORITY_HIGHEST } from '../constants';
const getAnchor = (element) => {
if (element.nodeName === 'A') return element;
return element.querySelector('a');
};
2021-10-27 15:23:28 +05:30
export default Node.create({
name: 'reference',
inline: true,
group: 'inline',
atom: true,
addAttributes() {
return {
className: {
default: null,
2021-11-11 11:23:49 +05:30
parseHTML: (element) => getAnchor(element).className,
2021-10-27 15:23:28 +05:30
},
referenceType: {
default: null,
2021-11-11 11:23:49 +05:30
parseHTML: (element) => getAnchor(element).dataset.referenceType,
2021-10-27 15:23:28 +05:30
},
originalText: {
default: null,
2021-11-11 11:23:49 +05:30
parseHTML: (element) => getAnchor(element).dataset.original,
2021-10-27 15:23:28 +05:30
},
href: {
default: null,
2021-11-11 11:23:49 +05:30
parseHTML: (element) => getAnchor(element).getAttribute('href'),
2021-10-27 15:23:28 +05:30
},
text: {
default: null,
2021-11-11 11:23:49 +05:30
parseHTML: (element) => getAnchor(element).textContent,
2021-10-27 15:23:28 +05:30
},
};
},
parseHTML() {
return [
{
tag: 'a.gfm:not([data-link=true])',
2021-11-11 11:23:49 +05:30
priority: PARSE_HTML_PRIORITY_HIGHEST,
},
2021-10-27 15:23:28 +05:30
];
},
renderHTML({ node }) {
2022-11-25 23:54:43 +05:30
return ['a', { href: '#' }, node.attrs.text];
2021-10-27 15:23:28 +05:30
},
});