UNPKG

@atlaskit/adf-schema

Version:

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

45 lines (43 loc) 1.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.linkifyMatch = void 0; var _url = require("./url"); /** * 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 */ /** Attempt to find a link match using a regex string defining a URL */ var linkifyMatch = exports.linkifyMatch = function linkifyMatch(text) { if (!_url.LINK_REGEXP.test(text)) { return []; } var matches = []; var startpos = 0; var substr; substr = text.substr(startpos); while (substr) { var link = (substr.match(_url.LINK_REGEXP) || [''])[0]; if (link) { var index = substr.search(_url.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; };