@@ -128,8 +128,17 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
128
128
// Reset state.indentedCode
129
129
state . indentedCode = false ;
130
130
if ( state . f == htmlBlock ) {
131
- state . f = inlineNormal ;
132
- state . block = blockNormal ;
131
+ var exit = htmlModeMissing
132
+ if ( ! exit ) {
133
+ var inner = CodeMirror . innerMode ( htmlMode , state . htmlState )
134
+ exit = inner . mode . name == "xml" && inner . state . tagStart === null &&
135
+ ( ! inner . state . context && inner . state . tokenize . isInText )
136
+ }
137
+ if ( exit ) {
138
+ state . f = inlineNormal ;
139
+ state . block = blockNormal ;
140
+ state . htmlState = null ;
141
+ }
133
142
}
134
143
// Reset state.trailingSpace
135
144
state . trailingSpace = 0 ;
@@ -539,6 +548,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
539
548
}
540
549
541
550
if ( ch === '[' && ! state . image ) {
551
+ if ( state . linkText && stream . match ( / ^ .* ?\] / ) ) return getType ( state )
542
552
state . linkText = true ;
543
553
if ( modeCfg . highlightFormatting ) state . formatting = "link" ;
544
554
return getType ( state ) ;
@@ -576,7 +586,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
576
586
return type + tokenTypes . linkEmail ;
577
587
}
578
588
579
- if ( modeCfg . xml && ch === '<' && stream . match ( / ^ ( ! - - | [ a - z ] + (?: \s + [ a - z _ : . \- ] + (?: \s * = \s * [ ^ > ] + ) ? ) * \s * > ) / i, false ) ) {
589
+ if ( modeCfg . xml && ch === '<' && stream . match ( / ^ ( ! - - | \? | ! \[ C D A T A \[ | [ a - z ] [ a - z 0 - 9 - ] * (?: \s + [ a - z _ : . \- ] + (?: \s * = \s * [ ^ > ] + ) ? ) * \s * (?: > | $ ) ) / i, false ) ) {
580
590
var end = stream . string . indexOf ( ">" , stream . pos ) ;
581
591
if ( end != - 1 ) {
582
592
var atts = stream . string . substring ( stream . start , end ) ;
@@ -661,7 +671,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
661
671
}
662
672
663
673
if ( ch === ' ' ) {
664
- if ( stream . match ( / + $ / , false ) ) {
674
+ if ( stream . match ( / ^ + $ / , false ) ) {
665
675
state . trailingSpace ++ ;
666
676
} else if ( state . trailingSpace ) {
667
677
state . trailingSpaceNewLine = true ;
0 commit comments