Way to "overlay" multiple tokens/rules/styles with CodeMirror simple mode?

342 Views Asked by At

A CodeMirror "simple mode" allows you to define a bunch of regex rules that capture chunks of text and apply styles to them. A regex rule can also be used to transition to another mode that has been defined. Here's a really simple example of that:

CodeMirror.defineSimpleMode("simplemode", {
  start: [
    {regex: /\[/, token: "meta", mode: {spec: "javascript", end: /\]/}}
  ]
});

This just grabs chunks of text that are surrounded by square brackets and applies the JavaScript mode stylings to it. Here's a working example of that on jsbin.

It produces text stylings like this:

enter image description here

But what if I wanted to make it so it looked something like this:

enter image description here

In other words, I want to apply a background "highlight" to the whole captured JavaScript group. Is there a simple way to do that, or is this beyond the scope of simple modes?

0

There are 0 best solutions below