Skip to content

Commit d5123ad

Browse files
authored
Merge pull request #28 from stanley2058/fix/inline-block-mathjax-and-shell-delimiter
fix/inline block mathjax and shell delimiter
2 parents 63be846 + 036375e commit d5123ad

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

mode/markdown/markdown_math.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,32 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
248248
state.code = -1
249249
return getType(state);
250250
} else if (firstTokenOnLine && state.indentation <= maxNonCodeIndentation && (match = stream.match(fencedMathRE, true))) {
251-
state.fencedEndRE = new RegExp(match[1].replace(/\$/g, '\\$') + "+ *$");
251+
// match[0] is the whole line
252+
// match[1] is the opening fence "$$"
253+
// match[2] is the optional language / mode name
254+
var wholeLine = match[0];
255+
var openingFence = match[1];
256+
257+
// Everything after the opening "$$"
258+
var rest = wholeLine.slice(openingFence.length);
259+
260+
// If there's another "$$" in the rest of the line, treat this as
261+
// a single-line math block: $$ ... $$.
262+
var closingIndex = rest.indexOf("$$");
263+
264+
if (closingIndex !== -1) {
265+
// Single-line $$ ... $$: highlight as math, but do NOT enter
266+
// multi-line fenced math mode.
267+
268+
state.formatting = "math";
269+
state.math = 0; // not in a multi-line math block
270+
// We've already consumed the whole line via stream.match(..., true)
271+
// so just return the math token type for this line.
272+
return tokenTypes.math;
273+
}
274+
275+
// Otherwise fall back to the original behavior: multi-line fenced math
276+
state.fencedEndRE = new RegExp(openingFence.replace(/\$/g, '\\$') + "+ *$");
252277
// try switching mode
253278
state.localMode = modeCfg.fencedCodeBlockHighlighting && getMode(match[2] || modeCfg.fencedCodeBlockDefaultMode );
254279
if (state.localMode) state.localState = CodeMirror.startState(state.localMode);

mode/shell/shell.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ CodeMirror.defineMode('shell', function() {
7272
}
7373
if (ch == "<") {
7474
if (stream.match("<<")) return "operator"
75-
var heredoc = stream.match(/^<-?\s*['"]?([^'"]*)['"]?/)
75+
var heredoc = stream.match(/^<-?\s*['"]?([^\s'"]*)['"]?/)
7676
if (heredoc) {
7777
state.tokens.unshift(tokenHeredoc(heredoc[1]))
7878
return 'string-2'

0 commit comments

Comments
 (0)