2020-03-13 15:44:24 +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
|
2022-05-07 20:08:51 +05:30
|
|
|
export default () => ({
|
|
|
|
name: 'reference',
|
|
|
|
schema: {
|
|
|
|
inline: true,
|
|
|
|
group: 'inline',
|
|
|
|
atom: true,
|
|
|
|
attrs: {
|
|
|
|
className: {},
|
|
|
|
referenceType: {},
|
|
|
|
originalText: { default: null },
|
|
|
|
href: {},
|
|
|
|
text: {},
|
|
|
|
},
|
|
|
|
parseDOM: [
|
|
|
|
{
|
|
|
|
tag: 'a.gfm:not([data-link=true])',
|
|
|
|
priority: HIGHER_PARSE_RULE_PRIORITY,
|
|
|
|
getAttrs: (el) => ({
|
|
|
|
className: el.className,
|
|
|
|
referenceType: el.dataset.referenceType,
|
|
|
|
originalText: el.dataset.original,
|
|
|
|
href: el.getAttribute('href'),
|
|
|
|
text: el.textContent,
|
|
|
|
}),
|
2019-03-02 22:35:43 +05:30
|
|
|
},
|
2022-05-07 20:08:51 +05:30
|
|
|
],
|
|
|
|
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,
|
|
|
|
],
|
|
|
|
},
|
2019-03-02 22:35:43 +05:30
|
|
|
toMarkdown(state, node) {
|
|
|
|
state.write(node.attrs.originalText || node.attrs.text);
|
2022-05-07 20:08:51 +05:30
|
|
|
},
|
|
|
|
});
|