Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
458 views
in Technique[技术] by (71.8m points)

monaco editor - New tokens to existing language

I am using Monaco editor in our project and I have issue I am not able to overcome. At our scenario , user can add new words to the editor once he clicks on a button, for example, user has editor with language javascript and he now wants to add new word 'workTest', it should be highlighted in custom color. How do I add new tokens to the editor with highlighted colors? I already have my 'newTheme' with rules {token: 'asToken', foreground: 'FFA500', fontStyle: 'bold'} How do I add the tokens to an existing language? I tried everything and nothing works.

question from:https://stackoverflow.com/questions/65922242/new-tokens-to-existing-language

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The tokenization is done using a dynamic tokenizer (see the Monarch declarative syntax highlighter documentation). All keywords are specified in JS code, via a Regex rule.

You could create your own tokenizer and update that with each new keyword.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...