@@ -149,10 +149,8 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
149149 state . list = null ;
150150 } else if ( state . indentation > 0 ) {
151151 state . list = null ;
152- state . listDepth = Math . floor ( state . indentation / 4 ) ;
153152 } else { // No longer a list
154153 state . list = false ;
155- state . listDepth = 0 ;
156154 }
157155 }
158156
@@ -199,7 +197,17 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
199197 }
200198 state . indentation = stream . column ( ) + stream . current ( ) . length ;
201199 state . list = true ;
202- state . listDepth ++ ;
200+
201+ // While this list item's marker's indentation
202+ // is less than the deepest list item's content's indentation,
203+ // pop the deepest list item indentation off the stack.
204+ while ( state . listStack && stream . column ( ) < state . listStack [ state . listStack . length - 1 ] ) {
205+ state . listStack . pop ( ) ;
206+ }
207+
208+ // Add this list item's content's indentation to the stack
209+ state . listStack . push ( state . indentation ) ;
210+
203211 if ( modeCfg . taskLists && stream . match ( taskListRE , false ) ) {
204212 state . taskList = true ;
205213 }
@@ -321,7 +329,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
321329 }
322330
323331 if ( state . list !== false ) {
324- var listMod = ( state . listDepth - 1 ) % 3 ;
332+ var listMod = ( state . listStack . length - 1 ) % 3 ;
325333 if ( ! listMod ) {
326334 styles . push ( tokenTypes . list1 ) ;
327335 } else if ( listMod === 1 ) {
@@ -697,7 +705,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
697705 hr : false ,
698706 taskList : false ,
699707 list : false ,
700- listDepth : 0 ,
708+ listStack : [ ] ,
701709 quote : 0 ,
702710 trailingSpace : 0 ,
703711 trailingSpaceNewLine : false ,
@@ -732,7 +740,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
732740 hr : s . hr ,
733741 taskList : s . taskList ,
734742 list : s . list ,
735- listDepth : s . listDepth ,
743+ listStack : s . listStack . slice ( 0 ) ,
736744 quote : s . quote ,
737745 indentedCode : s . indentedCode ,
738746 trailingSpace : s . trailingSpace ,
@@ -772,11 +780,8 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
772780
773781 state . f = state . block ;
774782 var indentation = stream . match ( / ^ \s * / , true ) [ 0 ] . replace ( / \t / g, ' ' ) . length ;
775- var difference = Math . floor ( ( indentation - state . indentation ) / 4 ) * 4 ;
776- if ( difference > 4 ) difference = 4 ;
777- var adjustedIndentation = state . indentation + difference ;
778- state . indentationDiff = adjustedIndentation - state . indentation ;
779- state . indentation = adjustedIndentation ;
783+ state . indentationDiff = Math . min ( indentation - state . indentation , 4 ) ;
784+ state . indentation = state . indentation + state . indentationDiff ;
780785 if ( indentation > 0 ) return null ;
781786 }
782787 return state . f ( stream , state ) ;
0 commit comments