@@ -195,7 +195,6 @@ module.exports = class Tokenizer {
195195 let raw = cap [ 0 ] ;
196196 const bull = cap [ 2 ] ;
197197 const isordered = bull . length > 1 ;
198- const isparen = bull [ bull . length - 1 ] === ')' ;
199198
200199 const list = {
201200 type : 'list' ,
@@ -212,17 +211,45 @@ module.exports = class Tokenizer {
212211 let next = false ,
213212 item ,
214213 space ,
215- b ,
214+ bcurr ,
215+ bnext ,
216216 addBack ,
217217 loose ,
218218 istask ,
219219 ischecked ;
220220
221- const l = itemMatch . length ;
221+ let l = itemMatch . length ;
222+ bcurr = this . rules . block . listItemStart . exec ( itemMatch [ 0 ] ) ;
222223 for ( let i = 0 ; i < l ; i ++ ) {
223224 item = itemMatch [ i ] ;
224225 raw = item ;
225226
227+ // Determine whether the next list item belongs here.
228+ // Backpedal if it does not belong in this list.
229+ if ( i !== l - 1 ) {
230+ bnext = this . rules . block . listItemStart . exec ( itemMatch [ i + 1 ] ) ;
231+
232+ if ( bnext [ 1 ] . length > bcurr [ 0 ] . length || bnext [ 1 ] . length > 3 ) {
233+ // nested list
234+ itemMatch . splice ( i , 2 , itemMatch [ i ] + '\n' + itemMatch [ i + 1 ] ) ;
235+ i -- ;
236+ l -- ;
237+ continue ;
238+ } else {
239+ if (
240+ // different bullet style
241+ ! this . options . pedantic || this . options . smartLists
242+ ? bnext [ 2 ] [ bnext [ 2 ] . length - 1 ] !== bull [ bull . length - 1 ]
243+ : isordered === ( bnext [ 2 ] . length === 1 )
244+ ) {
245+ addBack = itemMatch . slice ( i + 1 ) . join ( '\n' ) ;
246+ list . raw = list . raw . substring ( 0 , list . raw . length - addBack . length ) ;
247+ i = l - 1 ;
248+ }
249+ }
250+ bcurr = bnext ;
251+ }
252+
226253 // Remove the list item's bullet
227254 // so it is seen as the next token.
228255 space = item . length ;
@@ -237,18 +264,6 @@ module.exports = class Tokenizer {
237264 : item . replace ( / ^ { 1 , 4 } / gm, '' ) ;
238265 }
239266
240- // Determine whether the next list item belongs here.
241- // Backpedal if it does not belong in this list.
242- if ( i !== l - 1 ) {
243- b = this . rules . block . bullet . exec ( itemMatch [ i + 1 ] ) [ 0 ] ;
244- if ( isordered ? b . length === 1 || ( ! isparen && b [ b . length - 1 ] === ')' )
245- : ( b . length > 1 || ( this . options . smartLists && b !== bull ) ) ) {
246- addBack = itemMatch . slice ( i + 1 ) . join ( '\n' ) ;
247- list . raw = list . raw . substring ( 0 , list . raw . length - addBack . length ) ;
248- i = l - 1 ;
249- }
250- }
251-
252267 // Determine whether item is loose or not.
253268 // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/
254269 // for discount behavior.
0 commit comments