Lukasa / language-restructuredtext

A ReStructuredText syntax package for Atom
MIT License
27 stars 15 forks source link

Is possible to add some background highlight for code blocks #65

Open tonyriverms opened 6 years ago

tonyriverms commented 6 years ago

It is really great this plugin have proper highlight for code. Is it possible to also add some background highlight to a code block like this?

capture
Alhadis commented 2 years ago

I'd like to say “you can use your stylesheet, but it turns out that adding a background colour to certain lines in Atom is more complicated than simply dropping this into your stylesheet:

.line > * > .syntax--text.syntax--restructuredtext{
    &:only-child > .syntax--source.syntax--embedded.syntax--python{
        background-color: #236423;
    }
}

Unless you're happy with the effect looking like this:

Figure 1

If not, the effect you're after is achieved with something a lot like this:

const ed = atom.workspace.getActiveTextEditor();
const range = ed.getLastSelection().getBufferRange();
const marker = ed.markBufferRange(range);
const decoration = ed.decorateMarker(marker, {
    type: "line",
    class: "python-snippet",
})

… and this code needs to be run every time an update is made to an editor that's using text.restructuredtext as its grammar. And the code to do that monitoring is really, really, really fiddly. But if you're masochistic and/or determined enough to do down that route, the relevant APIs have something resembling documentation here.

tl;dr: Atom's APIs suck ass.