serdarciplak / BlazorMonaco

Blazor component for Microsoft's Monaco Editor which powers Visual Studio Code.
https://serdarciplak.github.io/BlazorMonaco/
MIT License
441 stars 99 forks source link

Add support for registering new language and tokenization highlight #65

Closed bub-bl closed 6 months ago

owaits commented 9 months ago

Is there any possibility this might get merged into the main branch? This functionality is something I use and would really like to see in the main version.

thatplatypus commented 9 months ago

Is there any possibility this might get merged into the main branch? This functionality is something I use and would really like to see in the main version.

I also started dabbling with some custom language support and was excited to see a PR out that looks like it adds the functionality as I was looking to do some more complex things. It would be great to see some first-class C# support for it.

This is what I was doing in my project just with the JS interop and anonymous objects if you wanted to try something like that given this branch looks old and has some conflicts now. Just some basic highlighting of things inside of string format and comments in mine and you'd have to find the symbols you want to put in the first part of the registrations.

await _jsRuntime.InvokeVoidAsync("monaco.languages.register", new { id = "your_language" });

await _jsRuntime.InvokeVoidAsync("monaco.languages.setMonarchTokensProvider", "your_language", new
{
    tokenizer = new
    {
        root = new object[]
        {
            new object[] { @"string", "_string", "@string" },
            new object[] { @"block_comment", "comment", "@comment" },
            new object[] { @"inline_comment", "comment" },
        },
        @string = new object[]
        {
            new object[] { @"escape_string", "variable" },
            new object[] { @"_string", "string", "@pop" },
            new object[] { @".", "string" },
        },
        comment = new object[]
        {
            new object[] { @"block_comment_end", "comment", "@pop" },
            new object[] { @".", "comment" },
        }
    }
});
serdarciplak commented 6 months ago

This PR is based on BlazorMonaco v2.x and it's not compatible with the latest version of the project and the repo. Some of the functionality here is already added to the project. For the rest, we need a new PR based on the latest version.