@@ -122,7 +122,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
122122 state . quote = 0 ;
123123 // Reset state.indentedCode
124124 state . indentedCode = false ;
125- if ( htmlModeMissing && state . f == htmlBlock ) {
125+ if ( state . f == htmlBlock ) {
126126 state . f = inlineNormal ;
127127 state . block = blockNormal ;
128128 }
@@ -250,10 +250,17 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
250250 }
251251
252252 function local ( stream , state ) {
253- if ( state . fencedChars && stream . match ( state . fencedChars , false ) ) {
253+ if ( state . fencedChars && stream . match ( state . fencedChars ) ) {
254+ if ( modeCfg . highlightFormatting ) state . formatting = "code-block" ;
255+ var returnType = getType ( state )
254256 state . localMode = state . localState = null ;
255- state . f = state . block = leavingLocal ;
256- return null ;
257+ state . block = blockNormal ;
258+ state . f = inlineNormal ;
259+ state . fencedChars = null ;
260+ state . code = 0
261+ return returnType ;
262+ } else if ( state . fencedChars && stream . skipTo ( state . fencedChars ) ) {
263+ return "comment"
257264 } else if ( state . localMode ) {
258265 return state . localMode . token ( stream , state . localState ) ;
259266 } else {
@@ -265,25 +272,6 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
265272 }
266273 }
267274
268- function leavingLocal ( stream , state ) {
269- stream . match ( state . fencedChars ) ;
270- state . block = blockNormal ;
271- state . f = inlineNormal ;
272- state . fencedChars = null ;
273- if ( state . math === - 1 ) {
274- state . formatting = "math" ;
275- state . math = 1
276- var returnType = getType ( state ) ;
277- state . math = 0
278- return returnType ;
279- }
280- if ( modeCfg . highlightFormatting ) state . formatting = "code-block" ;
281- state . code = 1
282- var returnType = getType ( state ) ;
283- state . code = 0
284- return returnType ;
285- }
286-
287275 // Inline
288276 function getType ( state ) {
289277 var styles = [ ] ;
@@ -479,7 +467,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
479467 return getType ( state ) ;
480468 }
481469
482- if ( ch === '[' && state . imageMarker ) {
470+ if ( ch === '[' && state . imageMarker && stream . match ( / [ ^ \] ] * \] ( \( . * ? \) | ? \[ . * ? \] ) / , false ) ) {
483471 state . imageMarker = false ;
484472 state . imageAltText = true
485473 if ( modeCfg . highlightFormatting ) state . formatting = "image" ;
@@ -533,7 +521,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
533521 return type + tokenTypes . linkEmail ;
534522 }
535523
536- if ( ch === '<' && stream . match ( / ^ ( ! - - | \w ) / , false ) ) {
524+ if ( ch === '<' && stream . match ( / ^ ( ! - - | [ a - z ] + (?: \s + [ a - z _ : . \- ] + (?: \s * = \s * [ ^ > ] + ) ? ) * \s * > ) / i , false ) ) {
537525 var end = stream . string . indexOf ( ">" , stream . pos ) ;
538526 if ( end != - 1 ) {
539527 var atts = stream . string . substring ( stream . start , end ) ;
0 commit comments