[d24f17c] | 1 | import { Match, MatchConfig } from './match';
|
---|
| 2 | import { StripPrefixConfigObj, UrlMatchTypeOptions } from '../autolinker';
|
---|
| 3 | /**
|
---|
| 4 | * @class Autolinker.match.Url
|
---|
| 5 | * @extends Autolinker.match.Match
|
---|
| 6 | *
|
---|
| 7 | * Represents a Url match found in an input string which should be Autolinked.
|
---|
| 8 | *
|
---|
| 9 | * See this class's superclass ({@link Autolinker.match.Match}) for more details.
|
---|
| 10 | */
|
---|
| 11 | export declare class UrlMatch extends Match {
|
---|
| 12 | /**
|
---|
| 13 | * @cfg {String} url (required)
|
---|
| 14 | *
|
---|
| 15 | * The url that was matched.
|
---|
| 16 | */
|
---|
| 17 | private url;
|
---|
| 18 | /**
|
---|
| 19 | * @cfg {"scheme"/"www"/"tld"} urlMatchType (required)
|
---|
| 20 | *
|
---|
| 21 | * The type of URL match that this class represents. This helps to determine
|
---|
| 22 | * if the match was made in the original text with a prefixed scheme (ex:
|
---|
| 23 | * 'http://www.google.com'), a prefixed 'www' (ex: 'www.google.com'), or
|
---|
| 24 | * was matched by a known top-level domain (ex: 'google.com').
|
---|
| 25 | */
|
---|
| 26 | private readonly urlMatchType;
|
---|
| 27 | /**
|
---|
| 28 | * @cfg {Boolean} protocolUrlMatch (required)
|
---|
| 29 | *
|
---|
| 30 | * `true` if the URL is a match which already has a protocol (i.e.
|
---|
| 31 | * 'http://'), `false` if the match was from a 'www' or known TLD match.
|
---|
| 32 | */
|
---|
| 33 | private readonly protocolUrlMatch;
|
---|
| 34 | /**
|
---|
| 35 | * @cfg {Boolean} protocolRelativeMatch (required)
|
---|
| 36 | *
|
---|
| 37 | * `true` if the URL is a protocol-relative match. A protocol-relative match
|
---|
| 38 | * is a URL that starts with '//', and will be either http:// or https://
|
---|
| 39 | * based on the protocol that the site is loaded under.
|
---|
| 40 | */
|
---|
| 41 | private readonly protocolRelativeMatch;
|
---|
| 42 | /**
|
---|
| 43 | * @cfg {Object} stripPrefix (required)
|
---|
| 44 | *
|
---|
| 45 | * The Object form of {@link Autolinker#cfg-stripPrefix}.
|
---|
| 46 | */
|
---|
| 47 | private readonly stripPrefix;
|
---|
| 48 | /**
|
---|
| 49 | * @cfg {Boolean} stripTrailingSlash (required)
|
---|
| 50 | * @inheritdoc Autolinker#cfg-stripTrailingSlash
|
---|
| 51 | */
|
---|
| 52 | private readonly stripTrailingSlash;
|
---|
| 53 | /**
|
---|
| 54 | * @cfg {Boolean} decodePercentEncoding (required)
|
---|
| 55 | * @inheritdoc Autolinker#cfg-decodePercentEncoding
|
---|
| 56 | */
|
---|
| 57 | private readonly decodePercentEncoding;
|
---|
| 58 | /**
|
---|
| 59 | * @private
|
---|
| 60 | * @property {RegExp} schemePrefixRegex
|
---|
| 61 | *
|
---|
| 62 | * A regular expression used to remove the 'http://' or 'https://' from
|
---|
| 63 | * URLs.
|
---|
| 64 | */
|
---|
| 65 | schemePrefixRegex: RegExp;
|
---|
| 66 | /**
|
---|
| 67 | * @private
|
---|
| 68 | * @property {RegExp} wwwPrefixRegex
|
---|
| 69 | *
|
---|
| 70 | * A regular expression used to remove the 'www.' from URLs.
|
---|
| 71 | */
|
---|
| 72 | wwwPrefixRegex: RegExp;
|
---|
| 73 | /**
|
---|
| 74 | * @private
|
---|
| 75 | * @property {RegExp} protocolRelativeRegex
|
---|
| 76 | *
|
---|
| 77 | * The regular expression used to remove the protocol-relative '//' from the {@link #url} string, for purposes
|
---|
| 78 | * of {@link #getAnchorText}. A protocol-relative URL is, for example, "//yahoo.com"
|
---|
| 79 | */
|
---|
| 80 | protocolRelativeRegex: RegExp;
|
---|
| 81 | /**
|
---|
| 82 | * @private
|
---|
| 83 | * @property {Boolean} protocolPrepended
|
---|
| 84 | *
|
---|
| 85 | * Will be set to `true` if the 'http://' protocol has been prepended to the {@link #url} (because the
|
---|
| 86 | * {@link #url} did not have a protocol)
|
---|
| 87 | */
|
---|
| 88 | protocolPrepended: boolean;
|
---|
| 89 | /**
|
---|
| 90 | * @method constructor
|
---|
| 91 | * @param {Object} cfg The configuration properties for the Match
|
---|
| 92 | * instance, specified in an Object (map).
|
---|
| 93 | */
|
---|
| 94 | constructor(cfg: UrlMatchConfig);
|
---|
| 95 | /**
|
---|
| 96 | * Returns a string name for the type of match that this class represents.
|
---|
| 97 | * For the case of UrlMatch, returns 'url'.
|
---|
| 98 | *
|
---|
| 99 | * @return {String}
|
---|
| 100 | */
|
---|
| 101 | getType(): string;
|
---|
| 102 | /**
|
---|
| 103 | * Returns a string name for the type of URL match that this class
|
---|
| 104 | * represents.
|
---|
| 105 | *
|
---|
| 106 | * This helps to determine if the match was made in the original text with a
|
---|
| 107 | * prefixed scheme (ex: 'http://www.google.com'), a prefixed 'www' (ex:
|
---|
| 108 | * 'www.google.com'), or was matched by a known top-level domain (ex:
|
---|
| 109 | * 'google.com').
|
---|
| 110 | *
|
---|
| 111 | * @return {"scheme"/"www"/"tld"}
|
---|
| 112 | */
|
---|
| 113 | getUrlMatchType(): UrlMatchTypeOptions;
|
---|
| 114 | /**
|
---|
| 115 | * Returns the url that was matched, assuming the protocol to be 'http://' if the original
|
---|
| 116 | * match was missing a protocol.
|
---|
| 117 | *
|
---|
| 118 | * @return {String}
|
---|
| 119 | */
|
---|
| 120 | getUrl(): string;
|
---|
| 121 | /**
|
---|
| 122 | * Returns the anchor href that should be generated for the match.
|
---|
| 123 | *
|
---|
| 124 | * @return {String}
|
---|
| 125 | */
|
---|
| 126 | getAnchorHref(): string;
|
---|
| 127 | /**
|
---|
| 128 | * Returns the anchor text that should be generated for the match.
|
---|
| 129 | *
|
---|
| 130 | * @return {String}
|
---|
| 131 | */
|
---|
| 132 | getAnchorText(): string;
|
---|
| 133 | /**
|
---|
| 134 | * Strips the scheme prefix (such as "http://" or "https://") from the given
|
---|
| 135 | * `url`.
|
---|
| 136 | *
|
---|
| 137 | * @private
|
---|
| 138 | * @param {String} url The text of the anchor that is being generated, for
|
---|
| 139 | * which to strip off the url scheme.
|
---|
| 140 | * @return {String} The `url`, with the scheme stripped.
|
---|
| 141 | */
|
---|
| 142 | private stripSchemePrefix;
|
---|
| 143 | /**
|
---|
| 144 | * Strips the 'www' prefix from the given `url`.
|
---|
| 145 | *
|
---|
| 146 | * @private
|
---|
| 147 | * @param {String} url The text of the anchor that is being generated, for
|
---|
| 148 | * which to strip off the 'www' if it exists.
|
---|
| 149 | * @return {String} The `url`, with the 'www' stripped.
|
---|
| 150 | */
|
---|
| 151 | private stripWwwPrefix;
|
---|
| 152 | /**
|
---|
| 153 | * Strips any protocol-relative '//' from the anchor text.
|
---|
| 154 | *
|
---|
| 155 | * @private
|
---|
| 156 | * @param {String} text The text of the anchor that is being generated, for which to strip off the
|
---|
| 157 | * protocol-relative prefix (such as stripping off "//")
|
---|
| 158 | * @return {String} The `anchorText`, with the protocol-relative prefix stripped.
|
---|
| 159 | */
|
---|
| 160 | private stripProtocolRelativePrefix;
|
---|
| 161 | /**
|
---|
| 162 | * Removes any trailing slash from the given `anchorText`, in preparation for the text to be displayed.
|
---|
| 163 | *
|
---|
| 164 | * @private
|
---|
| 165 | * @param {String} anchorText The text of the anchor that is being generated, for which to remove any trailing
|
---|
| 166 | * slash ('/') that may exist.
|
---|
| 167 | * @return {String} The `anchorText`, with the trailing slash removed.
|
---|
| 168 | */
|
---|
| 169 | private removeTrailingSlash;
|
---|
| 170 | /**
|
---|
| 171 | * Decodes percent-encoded characters from the given `anchorText`, in
|
---|
| 172 | * preparation for the text to be displayed.
|
---|
| 173 | *
|
---|
| 174 | * @private
|
---|
| 175 | * @param {String} anchorText The text of the anchor that is being
|
---|
| 176 | * generated, for which to decode any percent-encoded characters.
|
---|
| 177 | * @return {String} The `anchorText`, with the percent-encoded characters
|
---|
| 178 | * decoded.
|
---|
| 179 | */
|
---|
| 180 | private removePercentEncoding;
|
---|
| 181 | }
|
---|
| 182 | export interface UrlMatchConfig extends MatchConfig {
|
---|
| 183 | url: string;
|
---|
| 184 | urlMatchType: UrlMatchTypeOptions;
|
---|
| 185 | protocolUrlMatch: boolean;
|
---|
| 186 | protocolRelativeMatch: boolean;
|
---|
| 187 | stripPrefix: Required<StripPrefixConfigObj>;
|
---|
| 188 | stripTrailingSlash: boolean;
|
---|
| 189 | decodePercentEncoding: boolean;
|
---|
| 190 | }
|
---|