UNPKG

interweave-autolink

Version:

URL, IP, email, and hashtag autolinking support for Interweave.

28 lines (25 loc) 632 B
import React from 'react'; import { MatchResponse } from 'interweave'; import { IP_PATTERN } from './constants'; import { UrlMatcherOptions, UrlProps } from './types'; import { UrlMatch, UrlMatcher } from './UrlMatcher'; export class IpMatcher extends UrlMatcher { constructor( name: string, options?: UrlMatcherOptions, factory?: React.ComponentType<UrlProps> | null, ) { super( name, { ...options, // IPs dont have TLDs validateTLD: false, }, factory, ); } override match(string: string): MatchResponse<UrlMatch> | null { return this.doMatch(string, IP_PATTERN, this.handleMatches); } }