@atlaskit/adf-schema
Version:
Shared package that contains the ADF-schema (json) and ProseMirror node/mark specs
39 lines (38 loc) • 1.16 kB
JavaScript
/**
* This file has been partially duplicated in packages/linking-platform/linking-common/src/url.ts
* Any changes made here should be mirrored there.
* Ticket for dedeplication: https://product-fabric.atlassian.net/browse/EDM-7138
* Ticket for fixing linkification of filename-like urls: https://product-fabric.atlassian.net/browse/EDM-7190
*/
import { LINK_REGEXP } from './url';
/** Attempt to find a link match using a regex string defining a URL */
export var linkifyMatch = function linkifyMatch(text) {
if (!LINK_REGEXP.test(text)) {
return [];
}
var matches = [];
var startpos = 0;
var substr;
substr = text.substr(startpos);
while (substr) {
var link = (substr.match(LINK_REGEXP) || [''])[0];
if (link) {
var index = substr.search(LINK_REGEXP);
var start = index >= 0 ? index + startpos : index;
var end = start + link.length;
matches.push({
index: start,
lastIndex: end,
raw: link,
url: link,
text: link,
schema: ''
});
startpos = end;
substr = text.substr(startpos);
} else {
break;
}
}
return matches;
};