Carbon: Suggestion: Only syntax highlight range

Created on 19 Jul 2019  路  9Comments  路  Source: carbon-app/carbon

It's not uncommon to see presentations or code images where most of the code is de-coloured / not syntax highlighted, and only a specific range or set of ranges are highlighted.

I've worked out a possible solution.

CodeMirror supports marking a range of text with a class.
https://codemirror.net/doc/manual.html#api_marker

The CSS can then be added to make ALL text grey (or a themes comment colour?), only keeping the syntax highlighting for a specific section.

The CSS would look something like...

:not(.colourise) > span {
    color: gray !important;
}

Applying the class of colourise to a presentation span, then results in the attached screenshot result.
Screen Shot 2019-07-19 at 15 32 10

duplicate

Most helpful comment

This is a lesser known feature, but we already have support for highlighting/selecting lines. You have to turn on "Line numbers" in the settings, but then by clicking on the line numbers you can (de)select certain lines to highlight them. If you click, and then Shift-click another line, that will batch select a group of lines.

We also want to use opacity in order to ensure that deselection always looks good, no matter what the theme is.

All 9 comments

OR, actually, a simpler solution might be to invert the user entered range, add a class of cm-comment using the codemirror API, which then handles which colour to pick.

This is a lesser known feature, but we already have support for highlighting/selecting lines. You have to turn on "Line numbers" in the settings, but then by clicking on the line numbers you can (de)select certain lines to highlight them. If you click, and then Shift-click another line, that will batch select a group of lines.

We also want to use opacity in order to ensure that deselection always looks good, no matter what the theme is.

@Relequestual your comment about https://codemirror.net/doc/manual.html#api_marker is going to be _super_ useful for #548 and #806 though 馃憤

As for applying styles to a range, we will cover that as part of the other issues :+1: Duplicate of #548/#806

鈿狅笍 This issue has been marked as a duplicate. It will be closed in 1 day...

Huh, well I hadn't noticed you could already do line by line selection. This is pretty useful, thanks!

Looks like #806 has the same use case as me.

Now to file an issue on the cli repo!

@mfix22 Hum. Given it looks like the cli tool carbon-now-cli works by using URL query string.

Is there any way "lines selected" could be added to the query string?

@Relequestual sure! We probably have to refactor how the line selection state is handled first. Would you want to work on this? Otherwise I will get to it when there is time 馃檪

I wish I had time @mfix22! Appreciate you working on this!

Was this page helpful?
0 / 5 - 0 ratings