UNPKG

2.06 kBTypeScriptView Raw
1import { Match } from '../match/match';
2import { HashtagService } from './hashtag-utils';
3import { MentionService } from './mention-utils';
4import { AnchorTagBuilder } from '../anchor-tag-builder';
5import type { StripPrefixConfigObj } from '../autolinker';
6/**
7 * Parses URL, email, twitter, mention, and hashtag matches from the given
8 * `text`.
9 */
10export declare function parseMatches(text: string, args: ParseMatchesArgs): Match[];
11export interface ParseMatchesArgs {
12 tagBuilder: AnchorTagBuilder;
13 stripPrefix: Required<StripPrefixConfigObj>;
14 stripTrailingSlash: boolean;
15 decodePercentEncoding: boolean;
16 hashtagServiceName: HashtagService;
17 mentionServiceName: MentionService;
18}
19/**
20 * Determines if a match found has unmatched closing parenthesis,
21 * square brackets or curly brackets. If so, these unbalanced symbol(s) will be
22 * removed from the URL match itself.
23 *
24 * A match may have an extra closing parenthesis/square brackets/curly brackets
25 * at the end of the match because these are valid URL path characters. For
26 * example, "wikipedia.com/something_(disambiguation)" should be auto-linked.
27 *
28 * However, an extra parenthesis *will* be included when the URL itself is
29 * wrapped in parenthesis, such as in the case of:
30 *
31 * "(wikipedia.com/something_(disambiguation))"
32 *
33 * In this case, the last closing parenthesis should *not* be part of the
34 * URL itself, and this method will exclude it from the returned URL.
35 *
36 * For square brackets in URLs such as in PHP arrays, the same behavior as
37 * parenthesis discussed above should happen:
38 *
39 * "[http://www.example.com/foo.php?bar[]=1&bar[]=2&bar[]=3]"
40 *
41 * The very last closing square bracket should not be part of the URL itself,
42 * and therefore this method will remove it.
43 *
44 * @param matchedText The full matched URL/email/hashtag/etc. from the state
45 * machine parser.
46 * @return The updated matched text with extraneous suffix characters removed.
47 */
48export declare function excludeUnbalancedTrailingBracesAndPunctuation(matchedText: string): string;