UNPKG

@atlaskit/editor-plugin-card

Version:

Card plugin for @atlaskit/editor-core

25 lines (23 loc) 921 B
import { normalizeUrl } from '@atlaskit/adf-schema'; import { md } from '@atlaskit/editor-common/paste'; export function shouldReplaceLink(node, compareLinkText = true, compareToUrl) { const linkMark = node.marks.find(mark => mark.type.name === 'link'); if (!linkMark) { // not a link anymore return false; } // ED-6041: compare normalised link text after linkfy from Markdown transformer // instead, since it always decodes URL ('%20' -> ' ') on the link text const normalisedHref = normalizeUrl(md.normalizeLinkText(linkMark.attrs.href)); const normalizedLinkText = normalizeUrl(md.normalizeLinkText(node.text || '')); if (compareLinkText && normalisedHref !== normalizedLinkText) { return false; } if (compareToUrl) { const normalizedUrl = normalizeUrl(md.normalizeLinkText(compareToUrl)); if (normalizedUrl !== normalisedHref) { return false; } } return true; }