@@ -532,39 +532,51 @@ var Tokenizer_1 = class Tokenizer {
532532 addBack ,
533533 loose ,
534534 istask ,
535- ischecked ;
535+ ischecked ,
536+ endMatch ;
536537
537538 let l = itemMatch . length ;
538539 bcurr = this . rules . block . listItemStart . exec ( itemMatch [ 0 ] ) ;
539540 for ( let i = 0 ; i < l ; i ++ ) {
540541 item = itemMatch [ i ] ;
541542 raw = item ;
542543
544+ if ( ! this . options . pedantic ) {
545+ // Determine if current item contains the end of the list
546+ endMatch = item . match ( new RegExp ( '\\n\\s*\\n {0,' + ( bcurr [ 0 ] . length - 1 ) + '}\\S' ) ) ;
547+ if ( endMatch ) {
548+ addBack = item . length - endMatch . index + itemMatch . slice ( i + 1 ) . join ( '\n' ) . length ;
549+ list . raw = list . raw . substring ( 0 , list . raw . length - addBack ) ;
550+
551+ item = item . substring ( 0 , endMatch . index ) ;
552+ raw = item ;
553+ l = i + 1 ;
554+ }
555+ }
556+
543557 // Determine whether the next list item belongs here.
544558 // Backpedal if it does not belong in this list.
545559 if ( i !== l - 1 ) {
546560 bnext = this . rules . block . listItemStart . exec ( itemMatch [ i + 1 ] ) ;
547561 if (
548562 ! this . options . pedantic
549- ? bnext [ 1 ] . length > bcurr [ 0 ] . length || bnext [ 1 ] . length > 3
563+ ? bnext [ 1 ] . length >= bcurr [ 0 ] . length || bnext [ 1 ] . length > 3
550564 : bnext [ 1 ] . length > bcurr [ 1 ] . length
551565 ) {
552- // nested list
553- itemMatch . splice ( i , 2 , itemMatch [ i ] + ' \n' + itemMatch [ i + 1 ] ) ;
566+ // nested list or continuation
567+ itemMatch . splice ( i , 2 , itemMatch [ i ] + ( ! this . options . pedantic && bnext [ 1 ] . length < bcurr [ 0 ] . length && ! itemMatch [ i ] . match ( / \n $ / ) ? '' : ' \n') + itemMatch [ i + 1 ] ) ;
554568 i -- ;
555569 l -- ;
556570 continue ;
557- } else {
558- if (
559- // different bullet style
560- ! this . options . pedantic || this . options . smartLists
561- ? bnext [ 2 ] [ bnext [ 2 ] . length - 1 ] !== bull [ bull . length - 1 ]
562- : isordered === ( bnext [ 2 ] . length === 1 )
563- ) {
564- addBack = itemMatch . slice ( i + 1 ) . join ( '\n' ) ;
565- list . raw = list . raw . substring ( 0 , list . raw . length - addBack . length ) ;
566- i = l - 1 ;
567- }
571+ } else if (
572+ // different bullet style
573+ ! this . options . pedantic || this . options . smartLists
574+ ? bnext [ 2 ] [ bnext [ 2 ] . length - 1 ] !== bull [ bull . length - 1 ]
575+ : isordered === ( bnext [ 2 ] . length === 1 )
576+ ) {
577+ addBack = itemMatch . slice ( i + 1 ) . join ( '\n' ) . length ;
578+ list . raw = list . raw . substring ( 0 , list . raw . length - addBack ) ;
579+ i = l - 1 ;
568580 }
569581 bcurr = bnext ;
570582 }
@@ -583,12 +595,15 @@ var Tokenizer_1 = class Tokenizer {
583595 : item . replace ( / ^ { 1 , 4 } / gm, '' ) ;
584596 }
585597
598+ // trim item newlines at end
599+ item = item . replace ( / \n + $ / , '' ) ;
600+
586601 // Determine whether item is loose or not.
587602 // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/
588603 // for discount behavior.
589- loose = next || / \n \n (? ! \s * $ ) / . test ( item ) ;
604+ loose = next || / \n \n (? ! \s * $ ) / . test ( raw ) ;
590605 if ( i !== l - 1 ) {
591- next = item . charAt ( item . length - 1 ) === '\n' ;
606+ next = raw . charAt ( raw . length - 1 ) === '\n' ;
592607 if ( ! loose ) loose = next ;
593608 }
594609
@@ -1072,7 +1087,7 @@ block.item = edit$1(block.item, 'gm')
10721087 . replace ( / b u l l / g, block . bullet )
10731088 . getRegex ( ) ;
10741089
1075- block . listItemStart = edit$1 ( / ^ ( * ) ( b u l l ) / )
1090+ block . listItemStart = edit$1 ( / ^ ( * ) ( b u l l ) * / )
10761091 . replace ( 'bull' , block . bullet )
10771092 . getRegex ( ) ;
10781093
0 commit comments