@@ -111,7 +111,6 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
111111 // Blocks
112112
113113 function blankLine ( state ) {
114- state . hr = false ;
115114 // Reset linkTitle state
116115 state . linkTitle = false ;
117116 // Reset EM state
@@ -141,11 +140,10 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
141140 var firstTokenOnLine = stream . column ( ) === state . indentation ;
142141 var prevLineLineIsEmpty = lineIsEmpty ( state . prevLine . stream ) ;
143142 var prevLineIsIndentedCode = state . indentedCode ;
144- var prevLineIsHr = state . hr ;
143+ var prevLineIsHr = state . prevLine . hr ;
145144 var prevLineIsList = state . list !== false ;
146145 var maxNonCodeIndentation = ( state . listStack [ state . listStack . length - 1 ] || 0 ) + 3 ;
147146
148- state . hr = false ;
149147 state . indentedCode = false ;
150148
151149 var lineIndentation = state . indentation ;
@@ -172,6 +170,13 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
172170 }
173171 }
174172
173+ // not comprehensive (currently only for setext detection purposes)
174+ var allowsInlineContinuation = (
175+ ! prevLineLineIsEmpty && ! prevLineIsHr && ! state . prevLine . header &&
176+ ( ! prevLineIsList || ! prevLineIsIndentedCode ) &&
177+ ! state . prevLine . fencedCodeEnd
178+ ) ;
179+
175180 var isHr = ( state . list === false || prevLineIsHr || prevLineLineIsEmpty ) &&
176181 state . indentation <= maxNonCodeIndentation && stream . match ( hrRE ) ;
177182
@@ -195,7 +200,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
195200 if ( modeCfg . highlightFormatting ) state . formatting = "quote" ;
196201 stream . eatSpace ( ) ;
197202 return getType ( state ) ;
198- } else if ( ! isHr && firstTokenOnLine && state . indentation <= maxNonCodeIndentation && ( match = stream . match ( listRE ) ) ) {
203+ } else if ( ! isHr && ! state . setext && firstTokenOnLine && state . indentation <= maxNonCodeIndentation && ( match = stream . match ( listRE ) ) ) {
199204 var listType = match [ 1 ] ? "ol" : "ul" ;
200205
201206 state . indentation = lineIndentation + stream . current ( ) . length ;
@@ -227,8 +232,8 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
227232 // if setext set, indicates line after ---/===
228233 state . setext || (
229234 // line before ---/===
230- ! state . quote && state . list === false && ! state . code && ! isHr &&
231- ! prevLineIsList && ! linkDefRE . test ( stream . string ) &&
235+ ( ! allowsInlineContinuation || ! prevLineIsList ) && ! state . quote && state . list === false &&
236+ ! state . code && ! isHr && ! linkDefRE . test ( stream . string ) &&
232237 ( match = stream . lookAhead ( 1 ) ) && ( match = match . match ( setextHeaderRE ) )
233238 )
234239 ) {
@@ -248,6 +253,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
248253 } else if ( isHr ) {
249254 stream . skipToEnd ( ) ;
250255 state . hr = true ;
256+ state . thisLine . hr = true ;
251257 return tokenTypes . hr ;
252258 } else if ( stream . peek ( ) === '[' ) {
253259 return switchInline ( stream , state , footnoteLink ) ;
@@ -796,9 +802,9 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
796802 // Reset state.formatting
797803 state . formatting = false ;
798804
799- // Reset state.header
800805 if ( stream != state . thisLine . stream ) {
801806 state . header = 0 ;
807+ state . hr = false ;
802808
803809 if ( stream . match ( / ^ \s * $ / , true ) ) {
804810 blankLine ( state ) ;
0 commit comments