@@ -169,7 +169,7 @@ export class Tokenizer {
169169 let cap = this . rules . block . list . exec ( src ) ;
170170 if ( cap ) {
171171 let raw , istask , ischecked , indent , i , blankLine , endsWithBlankLine ,
172- line , nextLine , rawLine , itemContents ;
172+ line , nextLine , rawLine , itemContents , endEarly ;
173173
174174 let bull = cap [ 1 ] . trim ( ) ;
175175 const isordered = bull . length > 1 ;
@@ -194,6 +194,7 @@ export class Tokenizer {
194194
195195 // Check if current bullet point can start a new List Item
196196 while ( src ) {
197+ endEarly = false ;
197198 if ( ! ( cap = itemRegex . exec ( src ) ) ) {
198199 break ;
199200 }
@@ -223,40 +224,42 @@ export class Tokenizer {
223224 if ( ! line && / ^ * $ / . test ( nextLine ) ) { // Items begin with at most one blank line
224225 raw += nextLine + '\n' ;
225226 src = src . substring ( nextLine . length + 1 ) ;
226- list . loose = true ;
227+ endEarly = true ;
227228 }
228229
229- const nextBulletRegex = new RegExp ( `^ {0,${ Math . min ( 3 , indent - 1 ) } }(?:[*+-]|\\d{1,9}[.)])` ) ;
230-
231- // Check if following lines should be included in List Item
232- while ( src && ! list . loose ) {
233- rawLine = src . split ( '\n' , 1 ) [ 0 ] ;
234- line = rawLine ;
235-
236- // Re-align to follow commonmark nesting rules
237- if ( this . options . pedantic ) {
238- line = line . replace ( / ^ { 1 , 4 } (? = ( { 4 } ) * [ ^ ] ) / g, ' ' ) ;
239- }
240-
241- // End list item if found start of new bullet
242- if ( nextBulletRegex . test ( line ) ) {
243- break ;
230+ if ( ! endEarly ) {
231+ const nextBulletRegex = new RegExp ( `^ {0,${ Math . min ( 3 , indent - 1 ) } }(?:[*+-]|\\d{1,9}[.)])` ) ;
232+
233+ // Check if following lines should be included in List Item
234+ while ( src ) {
235+ rawLine = src . split ( '\n' , 1 ) [ 0 ] ;
236+ line = rawLine ;
237+
238+ // Re-align to follow commonmark nesting rules
239+ if ( this . options . pedantic ) {
240+ line = line . replace ( / ^ { 1 , 4 } (? = ( { 4 } ) * [ ^ ] ) / g, ' ' ) ;
241+ }
242+
243+ // End list item if found start of new bullet
244+ if ( nextBulletRegex . test ( line ) ) {
245+ break ;
246+ }
247+
248+ if ( line . search ( / [ ^ ] / ) >= indent || ! line . trim ( ) ) { // Dedent if possible
249+ itemContents += '\n' + line . slice ( indent ) ;
250+ } else if ( ! blankLine ) { // Until blank line, item doesn't need indentation
251+ itemContents += '\n' + line ;
252+ } else { // Otherwise, improper indentation ends this item
253+ break ;
254+ }
255+
256+ if ( ! blankLine && ! line . trim ( ) ) { // Check if current line is blank
257+ blankLine = true ;
258+ }
259+
260+ raw += rawLine + '\n' ;
261+ src = src . substring ( rawLine . length + 1 ) ;
244262 }
245-
246- if ( line . search ( / [ ^ ] / ) >= indent || ! line . trim ( ) ) { // Dedent if possible
247- itemContents += '\n' + line . slice ( indent ) ;
248- } else if ( ! blankLine ) { // Until blank line, item doesn't need indentation
249- itemContents += '\n' + line ;
250- } else { // Otherwise, improper indentation ends this item
251- break ;
252- }
253-
254- if ( ! blankLine && ! line . trim ( ) ) { // Check if current line is blank
255- blankLine = true ;
256- }
257-
258- raw += rawLine + '\n' ;
259- src = src . substring ( rawLine . length + 1 ) ;
260263 }
261264
262265 if ( ! list . loose ) {
0 commit comments