Restrict overlays to a specific sub-mode

I’m using a mode (gfm with many sub-modes multiplexed) where I’ve added a spell-checker overlay. Now, everything works fine, except that the spell checking is also performed on the sub-modes (e.g. stex), which I want to avoid.

I tried to figure out the base.mode from within the token(stream, state) function of the overlay, but I don’t seem to have access to it! At the moment, my workaround is to enable the addModeClass and then show the spell errors only when with the span.cm-m-markdown.cm-spell-error CSS.

However, this is rather unsatisfactory, since now some of my HTML contains span.cm-spell-error (e.g. span class="cm-m-stex cm-spell-error", which is simply ignored: I’d rather to not have those additional classes in the HTML in the first place.

Is it possible to tell an overlay to act only on a certain sub-set of modes if the given mode is a multiplexed mode? If not, how can I “hack” it? Or what would be the proper solution?

Please see https://www.notex.ch/editor and copy-paste the below snippet for a demonstration (the ABC spell-checking is also required to be enabled):

Well, it's a circuit diagram of a QFT with four *input* and *output* Qbits. Just wait a minute: "What is a Qbit?" I hear you screaming. I did not explain it yet, did I? And "what are these funny brackets around $|x_i⟩$ and $|y_i⟩$?" And "what is $\textbf{H}$?" Further, "why do you have these numbers in these circles, what do they do?".

If you investigate then e.g. QFT is highlighted as wrong, and $\textbf{H}$ is not since the latter is rendered with the stex sub-mode. However, if you investigate $\textbf{H}$ in the inspector, then it still contains a cm-spell-error, due to the explanation above.

Nope, overlays apply to the whole document. You could try writing a wrapping mode that inspects the gfm mode’s state to determine in which sub-mode it currently is, and conditionally applies spell checking based on that.

@marijn: Thanks for the feedback! :wink: Is there maybe a example where such a wrapping has been demonstrated?