@@ -128,8 +128,17 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
128128 // Reset state.indentedCode
129129 state . indentedCode = false ;
130130 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+ }
133142 }
134143 // Reset state.trailingSpace
135144 state . trailingSpace = 0 ;
@@ -539,6 +548,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
539548 }
540549
541550 if ( ch === '[' && ! state . image ) {
551+ if ( state . linkText && stream . match ( / ^ .* ?\] / ) ) return getType ( state )
542552 state . linkText = true ;
543553 if ( modeCfg . highlightFormatting ) state . formatting = "link" ;
544554 return getType ( state ) ;
@@ -576,7 +586,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
576586 return type + tokenTypes . linkEmail ;
577587 }
578588
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 ) ) {
580590 var end = stream . string . indexOf ( ">" , stream . pos ) ;
581591 if ( end != - 1 ) {
582592 var atts = stream . string . substring ( stream . start , end ) ;
@@ -661,7 +671,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
661671 }
662672
663673 if ( ch === ' ' ) {
664- if ( stream . match ( / + $ / , false ) ) {
674+ if ( stream . match ( / ^ + $ / , false ) ) {
665675 state . trailingSpace ++ ;
666676 } else if ( state . trailingSpace ) {
667677 state . trailingSpaceNewLine = true ;
0 commit comments