debian-mirror-gitlab/app/assets/javascripts/behaviors/markdown/nodes/reference.js

54 lines
1.3 KiB
JavaScript
Raw Normal View History

2019-03-02 22:35:43 +05:30
/* eslint-disable class-methods-use-this */
import { Node } from 'tiptap';
2020-03-09 13:42:32 +05:30
import { HIGHER_PARSE_RULE_PRIORITY } from '../constants';
2019-03-02 22:35:43 +05:30
// Transforms generated HTML back to GFM for Banzai::Filter::ReferenceFilter and subclasses
export default class Reference extends Node {
get name() {
return 'reference';
}
get schema() {
return {
inline: true,
group: 'inline',
atom: true,
attrs: {
className: {},
referenceType: {},
originalText: { default: null },
href: {},
text: {},
},
parseDOM: [
{
tag: 'a.gfm:not([data-link=true])',
2020-03-09 13:42:32 +05:30
priority: HIGHER_PARSE_RULE_PRIORITY,
2019-03-02 22:35:43 +05:30
getAttrs: el => ({
className: el.className,
referenceType: el.dataset.referenceType,
originalText: el.dataset.original,
href: el.getAttribute('href'),
text: el.textContent,
}),
},
],
toDOM: node => [
'a',
{
class: node.attrs.className,
href: node.attrs.href,
'data-reference-type': node.attrs.referenceType,
'data-original': node.attrs.originalText,
},
node.attrs.text,
],
};
}
toMarkdown(state, node) {
state.write(node.attrs.originalText || node.attrs.text);
}
}