rehype-pretty / rehype-pretty-code

Beautiful code blocks for Markdown or MDX.

Home Page:https://rehype-pretty.pages.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature: Code Diff Support

heychazza opened this issue · comments

Hi,

It would be great to have code diff support to the highlighting system, e.g. being able to specify {-1-4,+5-10} which would highlight the first few rows with a red - and background, with a green + for the others.

+ like
- this

But spans the entire code line

I'd also like something like this! I took a look at the repo to see how doable implementing it myself would be, and it looks like the proposed syntax might risk colliding with the current implementation. This library parses anything in {} blocks and passes it to parse-numeric-range, which allows for negative numbers. I'm not clear on if this would actually trigger anything (I believe it checks to see if a line number is in the range, so I suspect it wouldn't) but I think a safer syntax might be:

```jsx +{1-2} -{3-4}
import { thing } from "lib";
thing();
const thing = require("lib");
thing();

I might give implementing this a shot; if the maintainers are ok with a feature for this, changing the syntax based on feedback shouldn't be too difficult if I'm able to make it work!

Fixed with v0.12.0, you can use shikiji-transformers

Screenshot 2023-12-03 at 6 22 42 pm