@ -17,7 +17,8 @@ function isLinkClose(str) {
module . exports = function linkify ( state ) {
var i , j , l , tokens , token , currentToken , nodes , ln , text , pos , lastPos , level , htmlLinkLevel , url , fullUrl ,
var i , j , l , tokens , token , currentToken , nodes , ln , text , pos , lastPos ,
level , htmlLinkLevel , url , fullUrl , urlText ,
blockTokens = state . tokens ,
links ;
@ -74,6 +75,20 @@ module.exports = function linkify(state) {
fullUrl = state . md . normalizeLink ( url ) ;
if ( ! state . md . validateLink ( fullUrl ) ) { continue ; }
urlText = links [ ln ] . text ;
// Linkifier might send raw hostnames like "example.com", where url
// starts with domain name. So we prepend http:// in those cases,
// and remove it afterwards.
//
if ( ! links [ ln ] . schema ) {
urlText = state . md . normalizeLinkText ( 'http://' + urlText ) . replace ( /^http:\/\// , '' ) ;
} else if ( links [ ln ] . schema === 'mailto:' && ! /^mailto:/i . test ( urlText ) ) {
urlText = state . md . normalizeLinkText ( 'mailto:' + urlText ) . replace ( /^mailto:/ , '' ) ;
} else {
urlText = state . md . normalizeLinkText ( urlText ) ;
}
pos = links [ ln ] . index ;
if ( pos > lastPos ) {
@ -89,7 +104,7 @@ module.exports = function linkify(state) {
nodes . push ( token ) ;
token = new state . Token ( 'text' , '' , 0 ) ;
token . content = state . md . normalizeLinkText ( links [ ln ] . text ) ;
token . content = urlText ;
token . level = level ;
nodes . push ( token ) ;