carta icon indicating copy to clipboard operation
carta copied to clipboard

HIghlight based on condition

Open gagan-bansal opened this issue 1 year ago • 2 comments

I liked this library, simple to use and elegant. I was thinking is there a way we can highlight a text based on the text string? If you tell me the approach I can also try to contribute for this feature.

gagan-bansal avatar Nov 13 '24 17:11 gagan-bansal

Hi, can you explain a bit more what you're trying to achieve? Would you like to modify how text is highlighted in the input? If that's the case, you need to inject some custom grammar and highlighting rules. Carta uses Shiki, which itself uses TextMate grammar. Here is an example taken from the emoji plugin:

https://github.com/BearToCode/carta/blob/bd45020cfd4e9a8bb1c16dc50115b1bdb2d0c60d/packages/plugin-emoji/src/lib/index.ts#L64-L86

BearToCode avatar Nov 14 '24 10:11 BearToCode

Before saving the text, I am parsing the data, and if there is some word not satisfying the condition (yes similar to grammar check) then want to highlight it. I think what you have explained that should work. I'll study more and implement. I will update you soon. Thanks

gagan-bansal avatar Nov 15 '24 10:11 gagan-bansal