export function insertMentionLinks ( markdown ) { return markdown . replace ( /\B(@([a-zA-Z0-9](-?[a-zA-Z0-9_])+))/g , `**[$1](https://github.com/$2)**` ) ; } export function shorten ( text = "" , maxLength = 140 ) { let cleanText = text . replace ( /\\r\\n/g , "\n" ) ; if ( cleanText . length <= maxLength ) { return cleanText ; } const ellip = " ..." ; const oneTooLarge = cleanText . substr ( 0 , 141 ) ; if ( /\W$/ . test ( oneTooLarge ) ) { return oneTooLarge . substr ( 0 , 140 ) + ellip ; } let i = oneTooLarge . length ; while ( -- i ) { if ( /\W/ . test ( oneTooLarge [ i ] ) ) { return oneTooLarge . substr ( 0 , i ) + ellip ; } } return oneTooLarge . substr ( 0 , 140 ) + ellip ; }