Skip to content

Commit a49a776

Browse files
AlbertHilbmarijnh
authored andcommitted
[stex mode] Add inMathMode config option
When `true` `sTeX` parser starts in math mode.
1 parent 09ce884 commit a49a776

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

mode/stex/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ <h2>sTeX mode</h2>
103103
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {});
104104
</script>
105105

106+
<p>sTeX mode supports this option:</p>
107+
<d1>
108+
<dt><code>inMathMode: boolean</code></dt>
109+
<dd>Whether to start parsing in math mode (default: <code>false</code>).</dd>
110+
</d1>
111+
106112
<p><strong>MIME types defined:</strong> <code>text/x-stex</code>.</p>
107113

108114
<p><strong>Parsing/Highlighting Tests:</strong> <a href="../../test/index.html#stex_*">normal</a>, <a href="../../test/index.html#verbose,stex_*">verbose</a>.</p>

mode/stex/stex.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
})(function(CodeMirror) {
1717
"use strict";
1818

19-
CodeMirror.defineMode("stex", function() {
19+
CodeMirror.defineMode("stex", function(_config, parserConfig) {
2020
"use strict";
2121

2222
function pushCommand(state, command) {
@@ -173,7 +173,7 @@
173173
if (source.eatSpace()) {
174174
return null;
175175
}
176-
if (source.match(endModeSeq)) {
176+
if (endModeSeq && source.match(endModeSeq)) {
177177
setState(state, normal);
178178
return "keyword";
179179
}
@@ -235,9 +235,10 @@
235235

236236
return {
237237
startState: function() {
238+
var f = parserConfig.inMathMode ? function(source, state){ return inMathMode(source, state); } : normal;
238239
return {
239240
cmdState: [],
240-
f: normal
241+
f: f
241242
};
242243
},
243244
copyState: function(s) {

0 commit comments

Comments
 (0)