UNPKG

@atlaskit/adf-schema

Version:

Shared package that contains the ADF-schema (json) and ProseMirror node/mark specs

19 lines 640 B
import { isRootRelative } from '../../utils/is-root-relative'; import { isSafeUrl } from '../../utils/is-safe-url'; import { normalizeUrl } from '../../utils/normalize-url'; export const getLinkAttrs = attribute => domNode => { const dom = domNode; const href = dom.getAttribute(attribute) || ''; const 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; };