123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.AbstractMatch = void 0;
- /**
- * @abstract
- * @class Autolinker.match.AbstractMatch
- *
- * Represents a match found in an input string which should be Autolinked. A Match object is what is provided in a
- * {@link Autolinker#replaceFn replaceFn}, and may be used to query for details about the match.
- *
- * For example:
- *
- * var input = "..."; // string with URLs, Email Addresses, and Mentions (Twitter, Instagram, Soundcloud)
- *
- * var linkedText = Autolinker.link( input, {
- * replaceFn : function( match ) {
- * console.log( "href = ", match.getAnchorHref() );
- * console.log( "text = ", match.getAnchorText() );
- *
- * switch( match.getType() ) {
- * case 'url' :
- * console.log( "url: ", match.getUrl() );
- *
- * case 'email' :
- * console.log( "email: ", match.getEmail() );
- *
- * case 'mention' :
- * console.log( "mention: ", match.getMention() );
- * }
- * }
- * } );
- *
- * See the {@link Autolinker} class for more details on using the {@link Autolinker#replaceFn replaceFn}.
- */
- var AbstractMatch = /** @class */ (function () {
- /**
- * @member Autolinker.match.Match
- * @method constructor
- * @param {Object} cfg The configuration properties for the Match
- * instance, specified in an Object (map).
- */
- function AbstractMatch(cfg) {
- /**
- * @cfg {Autolinker.AnchorTagBuilder} tagBuilder (required)
- *
- * Reference to the AnchorTagBuilder instance to use to generate an anchor
- * tag for the Match.
- */
- // @ts-ignore
- this._ = null; // property used just to get the above doc comment into the ES5 output and documentation generator
- /**
- * @cfg {String} matchedText (required)
- *
- * The original text that was matched by the {@link Autolinker.matcher.Matcher}.
- */
- this.matchedText = ''; // default value just to get the above doc comment in the ES5 output and documentation generator
- /**
- * @cfg {Number} offset (required)
- *
- * The offset of where the match was made in the input string.
- */
- this.offset = 0; // default value just to get the above doc comment in the ES5 output and documentation generator
- this.tagBuilder = cfg.tagBuilder;
- this.matchedText = cfg.matchedText;
- this.offset = cfg.offset;
- }
- /**
- * Returns the original text that was matched.
- *
- * @return {String}
- */
- AbstractMatch.prototype.getMatchedText = function () {
- return this.matchedText;
- };
- /**
- * Sets the {@link #offset} of where the match was made in the input string.
- *
- * A {@link Autolinker.matcher.Matcher} will be fed only HTML text nodes,
- * and will therefore set an original offset that is relative to the HTML
- * text node itself. However, we want this offset to be relative to the full
- * HTML input string, and thus if using {@link Autolinker#parse} (rather
- * than calling a {@link Autolinker.matcher.Matcher} directly), then this
- * offset is corrected after the Matcher itself has done its job.
- *
- * @private
- * @param {Number} offset
- */
- AbstractMatch.prototype.setOffset = function (offset) {
- this.offset = offset;
- };
- /**
- * Returns the offset of where the match was made in the input string. This
- * is the 0-based index of the match.
- *
- * @return {Number}
- */
- AbstractMatch.prototype.getOffset = function () {
- return this.offset;
- };
- /**
- * Returns the CSS class suffix(es) for this match.
- *
- * A CSS class suffix is appended to the {@link Autolinker#className} in
- * the {@link Autolinker.AnchorTagBuilder} when a match is translated into
- * an anchor tag.
- *
- * For example, if {@link Autolinker#className} was configured as 'myLink',
- * and this method returns `[ 'url' ]`, the final class name of the element
- * will become: 'myLink myLink-url'.
- *
- * The match may provide multiple CSS class suffixes to be appended to the
- * {@link Autolinker#className} in order to facilitate better styling
- * options for different match criteria. See {@link Autolinker.match.Mention}
- * for an example.
- *
- * By default, this method returns a single array with the match's
- * {@link #getType type} name, but may be overridden by subclasses.
- *
- * @return {String[]}
- */
- AbstractMatch.prototype.getCssClassSuffixes = function () {
- return [this.type];
- };
- /**
- * Builds and returns an {@link Autolinker.HtmlTag} instance based on the
- * Match.
- *
- * This can be used to easily generate anchor tags from matches, and either
- * return their HTML string, or modify them before doing so.
- *
- * Example Usage:
- *
- * var tag = match.buildTag();
- * tag.addClass( 'cordova-link' );
- * tag.setAttr( 'target', '_system' );
- *
- * tag.toAnchorString(); // <a href="http://google.com" class="cordova-link" target="_system">Google</a>
- *
- * Example Usage in {@link Autolinker#replaceFn}:
- *
- * var html = Autolinker.link( "Test google.com", {
- * replaceFn : function( match ) {
- * var tag = match.buildTag(); // returns an {@link Autolinker.HtmlTag} instance
- * tag.setAttr( 'rel', 'nofollow' );
- *
- * return tag;
- * }
- * } );
- *
- * // generated html:
- * // Test <a href="http://google.com" target="_blank" rel="nofollow">google.com</a>
- */
- AbstractMatch.prototype.buildTag = function () {
- return this.tagBuilder.build(this);
- };
- return AbstractMatch;
- }());
- exports.AbstractMatch = AbstractMatch;
- //# sourceMappingURL=abstract-match.js.map
|