@@ -571,7 +571,7 @@ inline.tag = edit(inline.tag)
571
571
. getRegex ( ) ;
572
572
573
573
inline . _label = / (?: \[ [ ^ \[ \] ] * \] | \\ [ \[ \] ] ? | ` [ ^ ` ] * ` | [ ^ \[ \] \\ ] ) * ?/ ;
574
- inline . _href = / \s * ( < (?: \\ [ < > ] ? | [ ^ \s < > \\ ] ) * > | (?: \\ [ ( ) ] ? | \( [ ^ \s \x00 - \x1f \\ ] * \) | [ ^ \s \x00 - \x1f ( ) \\ ] ) * ? ) / ;
574
+ inline . _href = / \s * ( < (?: \\ [ < > ] ? | [ ^ \s < > \\ ] ) * > | [ ^ \s \x00 - \x1f ] * ) / ;
575
575
inline . _title = / " (?: \\ " ? | [ ^ " \\ ] ) * " | ' (?: \\ ' ? | [ ^ ' \\ ] ) * ' | \( (?: \\ \) ? | [ ^ ) \\ ] ) * \) / ;
576
576
577
577
inline . link = edit ( inline . link )
@@ -719,6 +719,12 @@ InlineLexer.prototype.output = function(src) {
719
719
720
720
// link
721
721
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
+ }
722
728
src = src . substring ( cap [ 0 ] . length ) ;
723
729
this . inLink = true ;
724
730
href = cap [ 2 ] ;
@@ -1503,6 +1509,26 @@ function rtrim(str, c, invert) {
1503
1509
return str . substr ( 0 , str . length - suffLen ) ;
1504
1510
}
1505
1511
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
+
1506
1532
/**
1507
1533
* Marked
1508
1534
*/
0 commit comments