Open data-niklas opened 3 months ago
Hello! Sorry for the late reply. I've been kind of busy, working on other projects.
Highlighting lines is a feature I really want to support, especially considering that with it, I would be able to support zebra coloring for the lines.
Briefly, we currently display the code as a table nested in a block. The block is breakable, and so looks good while being broken across multiple pages. This is important to me.
To do line highlighting well, we need to instead display the code as a stack
(or grid
, or table
) of rectangles, or a similar element, so we can style them individually.
Originally, I thought combining this with the page breakability was impossible, or really annoying to do, because you had to hijack the headers and footers for the page. Recently however, repeatable table headers and footers were added, and I think I can now come up with a much better solution.
I am currently therefore working on an official implementation of your feature suggestion.
I would like to highlight certain lines with a certain colors, e.g.: lines 3-5 in a light purple.
A simple interface would take a
highlighted-lines
parameter, which is a list of all lines to highlight, and there would be ahighlight-color
parameter with the color.A more complex interface would take a color for each lines, so that there could be different highlight colors in the same code block.
I currently have a small sketch that wraps around the code function:
The current problems are:
1fr
solves the problem, but then the box expands to use more space. Same with 100%, but then the line is moved into the next line, as the language box seems to take up space.Using the line-spacing solves the problem of white spaces between highlighted lines. The new container now has the same line height as before, but extends slightly above and below with the highlighted background, while showing the line in the middle using the inset.
What seems to find the correct width for all lines is using
measure
to find the width of the child raw element.Maybe some of that behavior could be integrated into the sourcerer library.
~ Update ~: The following logic currently solves the line width problem, line spacing and allows different highlight colors: