import { ImagePathRecognizer , UrlMatch } from './recognizer' ; export const linkRecognizer = { recognize : ( lineIndex , line ) : UrlMatch [ ] => { let pattern = /(?:(?:https?|ftp):\/\/|\b(?:[a-z\d]+\.))(?:(?:[^\s()<>]+|\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))?\))+(?:\((?:[^\s()<>]+|(?:\(?:[^\s()<>]+\)))?\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))?/gi ; let match ; const result = [ ] ; while ( ( match = pattern . exec ( line ) ) ) { if ( match . length > 0 ) { const imagePath = match [ 0 ] ; result . push ( { url : imagePath , lineIndex , start : match . index , end : match . index + imagePath . length , } ) ; } } return result ; } , } ;