-
-
Notifications
You must be signed in to change notification settings - Fork 467
Description
Clear and concise description of the problem
I would like to decorate (for example) lines 75 and 76 with Shiki. Currently that means I must also know the precise length of line 76, which means I have to split lines myself to determine what the line length is in order to produce a Position for the DecorationItem's start and end positions. This is something Shiki already has to do. Adding this feature would make things easier from a library user point of view.
Suggested solution
Can we have some way of describing "I want to highlight the whole line"? A simple solution would be to accept a negative character index as a Position and treat that as line.length + character. So if you want to highlight lines 75 and 76, you would use
...
start: {
line: 75,
character: 0,
},
end: {
line: 76,
character: -1,
}We would just need to modify this bit to accept it:
shiki/packages/core/src/transformer-decorations.ts
Lines 41 to 52 in d25afc2
| else { | |
| const line = converter.lines[p.line] | |
| if (line === undefined) | |
| throw new ShikiError(`Invalid decoration position ${JSON.stringify(p)}. Lines length: ${converter.lines.length}`) | |
| if (p.character < 0 || p.character > line.length) | |
| throw new ShikiError(`Invalid decoration position ${JSON.stringify(p)}. Line ${p.line} length: ${line.length}`) | |
| return { | |
| ...p, | |
| offset: converter.posToIndex(p.line, p.character), | |
| } | |
| } |
Alternative
Alternatively, we can derive some other object that accounts for an entire line.
Additional context
I'd be happy to make a PR for this simple change myself if I get the OK from a maintainer.
Validations
- Follow our Code of Conduct
- Read the Contributing Guide.
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.