Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | 1x 1x 1x 1x 1x 69x 69x 69x 69x 69x 37x 37x | import { matchLink } from './matchLink';
import type { AutoLinkOptions } from 'roosterjs-content-model-types';
const COMMON_REGEX = `[\s]*[a-zA-Z0-9+][\s]*`;
const TELEPHONE_REGEX = `(T|t)el:${COMMON_REGEX}`;
const MAILTO_REGEX = `(M|m)ailto:${COMMON_REGEX}`;
/**
* @internal
*/
export function getLinkUrl(text: string, autoLinkOptions?: AutoLinkOptions): string | undefined {
const { autoLink, autoMailto, autoTel } = autoLinkOptions ?? {};
const linkMatch = autoLink ? matchLink(text)?.normalizedUrl : undefined;
const telMatch = autoTel ? matchTel(text) : undefined;
const mailtoMatch = autoMailto ? matchMailTo(text) : undefined;
return linkMatch || telMatch || mailtoMatch;
}
function matchTel(text: string) {
return text.match(TELEPHONE_REGEX) ? text.toLocaleLowerCase() : undefined;
}
function matchMailTo(text: string) {
return text.match(MAILTO_REGEX) ? text.toLocaleLowerCase() : undefined;
}
|