Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HIghlight based on condition #136

Open
gagan-bansal opened this issue Nov 13, 2024 · 2 comments
Open

HIghlight based on condition #136

gagan-bansal opened this issue Nov 13, 2024 · 2 comments

Comments

@gagan-bansal
Copy link

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.

@BearToCode
Copy link
Owner

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:

const grammar = {
name: 'emoji',
type: 'inline',
definition: {
match: ':(?:\\+1|[-\\w]+):',
name: 'markup.emoji.markdown'
}
} satisfies GrammarRule;
const highlighting = {
light: {
scope: 'markup.emoji',
settings: {
foreground: '#3bf'
}
},
dark: {
scope: 'markup.emoji',
settings: {
foreground: '#4dacfa'
}
}
} satisfies HighlightingRule;

@gagan-bansal
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants