diff --git a/index.js b/index.js index d8a2660..ddf594d 100644 --- a/index.js +++ b/index.js @@ -203,14 +203,13 @@ function bare_math_block(state, start, end, silent) { const endRe = /^\\end/; if (!beginRe.test(firstLine)) { return false; } - + if (silent) { return true; } + let nestingCount = 0; let next; for (next = start; !found;) { - next++; - if (next >= end) { break; } pos = state.bMarks[next] + state.tShift[next]; @@ -221,10 +220,15 @@ function bare_math_block(state, start, end, silent) { break; } const line = state.src.slice(pos, max); - if (endRe.test(line)) { - const lastPos = max; - lastLine = state.src.slice(pos, lastPos); - found = true; + if (beginRe.test(line)) { + ++nestingCount; + } else if (endRe.test(line)) { + --nestingCount; + if (nestingCount < 0) { + const lastPos = max; + lastLine = state.src.slice(pos, lastPos); + found = true; + } } } diff --git a/test/fixtures/bare.txt b/test/fixtures/bare.txt index 5d94a5a..ccf1140 100644 --- a/test/fixtures/bare.txt +++ b/test/fixtures/bare.txt @@ -29,3 +29,24 @@ end \end{equation}
end
. + +Bare block with multiple begin/ends +. +start +\begin{equation} +\begin{split} +a = b \\ +c = c +\end{split} +\end{equation} +end +. +start
++
end
+.