@@ -571,7 +571,7 @@ inline.tag = edit(inline.tag)
571571 . getRegex ( ) ;
572572
573573inline . _label = / (?: \[ [ ^ \[ \] ] * \] | \\ [ \[ \] ] ? | ` [ ^ ` ] * ` | [ ^ \[ \] \\ ] ) * ?/ ;
574- inline . _href = / \s * ( < (?: \\ [ < > ] ? | [ ^ \s < > \\ ] ) * > | (?: \\ [ ( ) ] ? | \( [ ^ \s \x00 - \x1f \\ ] * \) | [ ^ \s \x00 - \x1f ( ) \\ ] ) * ? ) / ;
574+ inline . _href = / \s * ( < (?: \\ [ < > ] ? | [ ^ \s < > \\ ] ) * > | [ ^ \s \x00 - \x1f ] * ) / ;
575575inline . _title = / " (?: \\ " ? | [ ^ " \\ ] ) * " | ' (?: \\ ' ? | [ ^ ' \\ ] ) * ' | \( (?: \\ \) ? | [ ^ ) \\ ] ) * \) / ;
576576
577577inline . link = edit ( inline . link )
@@ -719,6 +719,12 @@ InlineLexer.prototype.output = function(src) {
719719
720720 // link
721721 if ( cap = this . rules . link . exec ( src ) ) {
722+ var lastParenIndex = findClosingBracket ( cap [ 2 ] , '()' ) ;
723+ if ( lastParenIndex > - 1 ) {
724+ var removeChars = cap [ 2 ] . length - lastParenIndex ;
725+ cap [ 2 ] = cap [ 2 ] . substring ( 0 , lastParenIndex ) ;
726+ cap [ 0 ] = cap [ 0 ] . substring ( 0 , cap [ 0 ] . length - removeChars ) ;
727+ }
722728 src = src . substring ( cap [ 0 ] . length ) ;
723729 this . inLink = true ;
724730 href = cap [ 2 ] ;
@@ -1503,6 +1509,26 @@ function rtrim(str, c, invert) {
15031509 return str . substr ( 0 , str . length - suffLen ) ;
15041510}
15051511
1512+ function findClosingBracket ( str , b ) {
1513+ if ( str . indexOf ( b [ 1 ] ) === - 1 ) {
1514+ return - 1 ;
1515+ }
1516+ var level = 0 ;
1517+ for ( var i = 0 ; i < str . length ; i ++ ) {
1518+ if ( str [ i ] === '\\' ) {
1519+ i ++ ;
1520+ } else if ( str [ i ] === b [ 0 ] ) {
1521+ level ++ ;
1522+ } else if ( str [ i ] === b [ 1 ] ) {
1523+ level -- ;
1524+ if ( level < 0 ) {
1525+ return i ;
1526+ }
1527+ }
1528+ }
1529+ return - 1 ;
1530+ }
1531+
15061532/**
15071533 * Marked
15081534 */
0 commit comments