@atlaskit/editor-wikimarkup-transformer
Version:
Wiki markup transformer for JIRA and Confluence
37 lines (35 loc) • 1.35 kB
JavaScript
import { mentionLinkResolver } from './mention-link';
import { attachmentLinkResolver } from './attachment-link';
import { urlLinkResolver } from './url-link';
import { issueLinkResolver } from './issue-link';
/**
* Given some parsed link text, convert it into a link object that can then be rendered into
* the page. The parseAsContentLink() method must have been called on the GenericLinkParser
* object before being passed to this method.
*
* @param context The render context
* @param parsedLink The parsed link information
* @returns the corresponding link. If no link can be created, null is returned
*/
// jira-components/jira-core/src/main/resources/system-contentlinkresolvers-plugin.xml
// attachment resolver: 10
// anchor resolver: 20 - unsupported
// jiraissue resolver: 30 - unsupported
// user profile: 40
//
// Fall back to url link resolver
const linkResolverStrategies = [attachmentLinkResolver, mentionLinkResolver, issueLinkResolver, urlLinkResolver];
export function resolveLink(link, schema, context) {
const length = link.originalLinkText.length + 2;
for (const resolver of linkResolverStrategies) {
const resolvedLink = resolver(link, schema, context);
if (resolvedLink) {
return {
length,
nodes: resolvedLink,
type: 'pmnode'
};
}
}
return undefined;
}