Is there any way I can style the data fetched from API as keywords in Codemirror 6?
I have also gone through the custom language package too but could not find a way to implement it.
You could use an external tokenizer or specializer in a Lezer grammar that depends on some data you give it as a parameter (when configuring the parser), if this fetched data is expected to be stable during an editing session. (And I guess even if it is not, you could recreate the parser and update the editor configuration whenever it changes.)
I tried with the external tokenizers but it seems I could not get it to work.
Can you please provide me an example… Thanks in advance!!
I am doing something similar and I have used a simple custom stream language. Hopefully this will help you.
export const yourLang = StreamLanguage.define({
token(stream: StringStream) {// say, this returns array of token object with value and style tag info
const tokens = callMyApi(stream.string);for (const tkn of tokens) { if (stream.match(tkn.value)) return tkn.styleTag; } stream.next(); return null;
},
});
Style tags are defined here
or you can define your own tags
or you can use mark decorations as completely custom solution.