Apologies if this has already been asked before, but my use case is rather unique and I couldn’t find anything exactly like what I’m trying to do.
I have a SimpleMode that wraps other language modes, various lines of the following:
{regex: /^%py.*$/, token: "meta", sol: true, mode: {spec: "text/x-python", end: /^(?=%)/}}
Basically, sub languages are delineated by a %lang marker or such at the start of the line.
There’s no explicit end marker, the “end” marker is the next %lang marker at the start of a line.
Unfortunately there’s no “sol” option for the end marker, so the lexer is currently broken.
But it turned out that the problem is actually a bit more complicated.
Some markers are special and don’t nest other modes, perhaps an example:
%py
print("Hello World")
%clear
print("Hello World") # still python
%js
console.log("Hello World)"
For this to work, the next %marker shouldn’t necessarily pop back to the previous state, they should keep stacking indefinitely.
If I controlled every language I could simply add a mode switch to the top level SimpleMode whenever they themselves find a %marker at the start of a line, but the idea is that the languages might be existing ones like Python or Javascript.
Is there a way to accomplish this? Perhaps by wrapping every sub language in an overlay mode?
This work is being done in the context of JupyterLab which I assume will eventually switch to CodeMirror 6 so I’d rather not commit to writing a complicated custom CodeMirror 5 solution that will have to be replaced later on.