@atlaskit/adf-schema
Version:
Shared package that contains the ADF-schema (json) and ProseMirror node/mark specs
21 lines • 704 B
JavaScript
import { isRootRelative } from '../../utils/is-root-relative';
import { isSafeUrl } from '../../utils/is-safe-url';
import { normalizeUrl } from '../../utils/normalize-url';
export var getLinkAttrs = function getLinkAttrs(attribute) {
return function (domNode) {
var dom = domNode;
var href = dom.getAttribute(attribute) || '';
var attrs = {
__confluenceMetadata: dom.hasAttribute('__confluenceMetadata') ? JSON.parse(dom.getAttribute('__confluenceMetadata') || '') : undefined
};
if (!isSafeUrl(href)) {
return false;
}
if (isRootRelative(href)) {
attrs.href = href;
return attrs;
}
attrs.href = normalizeUrl(href);
return attrs;
};
};