@@ -94,7 +94,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
94
94
, linkDefRE = / ^ \s * \[ [ ^ \] ] + ?\] : \s * \S + ( \s * \S * \s * ) ? $ / // naive link-definition
95
95
, punctuation = / [ ! \" # $ % & \' ( ) * + , \- \. \/ : ; < = > ? @ \[ \\ \] ^ _ ` { | } ~ — ] /
96
96
, expandedTab = " " // CommonMark specifies tab as 4 spaces
97
- , fencedMathRE = new RegExp ( " ^(\$\$)[ \\ t]*([\\ w+#\ -]*)" ) ;
97
+ , fencedMathRE = / ^ ( \$ \$ ) [ \t ] * ( [ \w + # - ] * ) [ ^ \n ` ] * $ /
98
98
99
99
function switchInline ( stream , state , f ) {
100
100
state . f = state . inline = f ;
@@ -228,10 +228,10 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
228
228
if ( modeCfg . highlightFormatting ) state . formatting = "code-block" ;
229
229
state . code = - 1
230
230
return getType ( state ) ;
231
- } else if ( match = stream . match ( fencedMathRE , true ) ) {
232
- state . fencedChars = match [ 1 ]
231
+ } else if ( firstTokenOnLine && state . indentation <= maxNonCodeIndentation && ( match = stream . match ( fencedMathRE , true ) ) ) {
232
+ state . fencedEndRE = new RegExp ( match [ 1 ] . replace ( / \$ / g , '\\$' ) + "+ *$" ) ;
233
233
// try switching mode
234
- state . localMode = getMode ( match [ 2 ] ) ;
234
+ state . localMode = modeCfg . fencedCodeBlockHighlighting && getMode ( match [ 2 ] ) ;
235
235
if ( state . localMode ) state . localState = CodeMirror . startState ( state . localMode ) ;
236
236
state . f = state . block = local ;
237
237
state . formatting = "math" ;
0 commit comments