UNPKG

2.12 kBJavaScriptView Raw
1import { __assign } from "tslib";
2import { LINK, COLOR } from '../groups';
3import { isSafeUrl, normalizeUrl } from '../../utils/url';
4export var link = {
5 excludes: LINK + " " + COLOR,
6 group: LINK,
7 attrs: {
8 href: {},
9 __confluenceMetadata: {
10 default: null,
11 },
12 },
13 inclusive: false,
14 parseDOM: [
15 {
16 tag: 'a[href]',
17 getAttrs: function (domNode) {
18 var dom = domNode;
19 var href = dom.getAttribute('href') || '';
20 var attrs = {
21 __confluenceMetadata: dom.hasAttribute('__confluenceMetadata')
22 ? JSON.parse(dom.getAttribute('__confluenceMetadata') || '')
23 : undefined,
24 };
25 if (isSafeUrl(href)) {
26 attrs.href = normalizeUrl(href);
27 }
28 else {
29 return false;
30 }
31 return attrs;
32 },
33 },
34 ],
35 toDOM: function (node, isInline) {
36 var attrs = Object.keys(node.attrs).reduce(function (attrs, key) {
37 if (key === '__confluenceMetadata') {
38 if (node.attrs[key] !== null) {
39 attrs[key] = JSON.stringify(node.attrs[key]);
40 }
41 }
42 else {
43 attrs[key] = node.attrs[key];
44 }
45 return attrs;
46 }, {});
47 if (isInline) {
48 return ['a', attrs];
49 }
50 return [
51 'a',
52 __assign(__assign({}, attrs), { class: 'blockLink' }),
53 0,
54 ];
55 },
56};
57var OPTIONAL_ATTRS = [
58 'title',
59 'id',
60 'collection',
61 'occurrenceKey',
62 '__confluenceMetadata',
63];
64export var toJSON = function (mark) { return ({
65 type: mark.type.name,
66 attrs: Object.keys(mark.attrs).reduce(function (attrs, key) {
67 if (OPTIONAL_ATTRS.indexOf(key) === -1 || mark.attrs[key] !== null) {
68 attrs[key] = mark.attrs[key];
69 }
70 return attrs;
71 }, {}),
72}); };
73//# sourceMappingURL=link.js.map
\No newline at end of file