rehype-pretty / rehype-pretty-code

Beautiful code blocks for Markdown or MDX.
https://rehype-pretty.pages.dev
MIT License
998 stars 63 forks source link

Feature: Highlight char ranges by line/column #211

Open thesilican opened 3 months ago

thesilican commented 3 months ago

In addition to highlighting chars using a search string, allow the user to specify char ranges to be highlighted using a line/column syntax. This would provide a way to work around #70.

The meta string {a:b-c:d} would highlight characters from line a column b to line c column d.

For example, the following would highlight the string "Hello, world!":

```python {2:11-2:25}
def main():
    print("Hello, world!")
```

This could be integrated together with line highlighting syntax, for example

{1,2-3,4:2-4:10}

Some other considerations include handling the case for highlighting a single char {4:10}, as well as ranges that mix line and char indexes {4-5:8} or {3:20-8}.

I used the colon for the delimiting character as an example 1:2-3:4, other possible options include a slash 1/2-3/4, dot 1.2-3.4, or pipe 1|2-3|4.