@@ -303,8 +303,9 @@ class Parser
303303 text = text .replace / !\[ ((?:[^ \] ] | \\\] | \\\[ )*? )\]\( ((?:[^ \) ] | \\\) | \\\( )+? )\) / g , (matches ... ) =>
304304 escaped = htmlspecialchars @ escapeBracket matches[1 ]
305305 url = @ escapeBracket matches[2 ]
306- url = @ cleanUrl url
307- @ makeHolder " <img src=\" #{ url} \" alt=\" #{ escaped} \" title=\" #{ escaped} \" >"
306+ [url , title ] = @ cleanUrl url, yes
307+ title = if not title? then escaped else " title=\" #{ title} \" "
308+ @ makeHolder " <img src=\" #{ url} \" alt=\" #{ title} \" title=\" #{ title} \" >"
308309
309310 text = text .replace / !\[ ((?:[^ \] ] | \\\] | \\\[ )*? )\]\[ ((?:[^ \] ] | \\\] | \\\[ )+? )\] / g , (matches ... ) =>
310311 escaped = htmlspecialchars @ escapeBracket matches[1 ]
@@ -317,8 +318,10 @@ class Parser
317318 text = text .replace / \[ ((?:[^ \] ] | \\\] | \\\[ )+? )\]\( ((?:[^ \) ] | \\\) | \\\( )+? )\) / g , (matches ... ) =>
318319 escaped = @parseInline (@ escapeBracket matches[1 ]), ' ' , no , no
319320 url = @ escapeBracket matches[2 ]
320- url = @ cleanUrl url
321- @ makeHolder " <a href=\" #{ url} \" >#{ escaped} </a>"
321+ [url , title ] = @ cleanUrl url, yes
322+ title = if not title? then ' ' else " title=\" #{ title} \" "
323+
324+ @ makeHolder " <a href=\" #{ url} \" #{ title} >#{ escaped} </a>"
322325
323326 text = text .replace / \[ ((?:[^ \] ] | \\\] | \\\[ )+? )\]\[ ((?:[^ \] ] | \\\] | \\\[ )+? )\] / g , (matches ... ) =>
324327 escaped = @parseInline (@ escapeBracket matches[1 ]), ' ' , no , no
@@ -987,15 +990,24 @@ class Parser
987990 (@ markLines lines, start).join " \n "
988991
989992
990- cleanUrl : (url ) ->
993+ cleanUrl : (url , parseTitle = false ) ->
994+ title = null
995+
996+ if parseTitle
997+ pos = url .indexOf ' '
998+
999+ if pos > 0
1000+ title = htmlspecialchars trim (url .substring pos + 1 ), ' "\' '
1001+ url = url .substring 0 , pos
1002+
9911003 url = url .replace / ["'<>\s ] / g , ' '
9921004
9931005 if !! (matches = url .match / ^ (mailto:)? [_a-z0-9 -\.\+ ] + @[_\w -] + \. [a-z ] {2,} $ / i )
9941006 url = ' mailto:' + url if not matches[1 ]?
9951007
9961008 return ' #' if (url .match / ^ \w + :/ i ) and not (url .match / ^ (https? | mailto):/ i )
9971009
998- url
1010+ if parseTitle then [url, title] else url
9991011
10001012
10011013 escapeBracket : (str ) ->
0 commit comments