Monaco-editor: Is it possible to use the language highlighter from the commandline?

Created on 15 May 2017  路  8Comments  路  Source: microsoft/monaco-editor

Is it possible to use the language colorizer from the commandline? We want to be able to use the same language definition for development and for the documentation. But this would require integrating the language colorizer into a static site build (also based on node.js). Atom did something similar by extracting highlights out of the core. Would you (or have you) considered doing the same? I'm just looking for some pointers about what would be required.

api feature-request integration

Most helpful comment

:+1: The colorization engine is browser agnostic, this is just a packaging problem.

All 8 comments

If this question should be posted elsewhere, just let me know.

There is monaco.editor.colorizeElement to colorize a content of some HTMLElement.

Yep, I saw that API. The question is, what needs to be done to bootstrap the editor from the a commandline script, or is there a way to bypass loading the whole editor just to get at that method?

After all, you must need something like that to unit test the language definitions anyway, right?

I'm also interested in this. I'd love to use Monaco's syntax highlighter as part of my static site building pipeline, but monaco-editor needs to be run in a browser environment (loading vs/editor/editor.main makes an immediate call to navigator.userAgent, for example).

Extracting monaco.editor.colorize into something that could be run in a node environment would be amazing!

:+1: The colorization engine is browser agnostic, this is just a packaging problem.

@alexandrudima Any hints about how to do that? What needs to be done to bootstrap the editor from the a commandline script? Even some pseudo-code would help.

Here are the tricks I do for testing monaco-languages under nodejs:

But yeah, this thing is not packaged as a server-side colorizer, so this is all pretty crazy just to get colorization working... The alternative would be to start from sources (compile them with TS to the /out folder in VS Code) and then load only the needed code to get colorization working. A good entry point would be the Colorizer, like it is used here.

Was this page helpful?
0 / 5 - 0 ratings