Robert Važan

Syntax highlighting libraries for Java

Syntax highlighting is usually done at UI level, because highlighter output must match capabilities of the media. There is however a need for reusable highlighters that are not tied to any UI platform or that at least produce output that can be filtered to remove anything platform-specific. Here I am looking for such reusable highlighters that can be invoked from Java.

There are several situations when you would want to use platform-agnostic highlighter:

I have searched a lot of places: syntax-highlighting and syntax-highlighter topics on GitHub, several SO questions (1, 2, 3), as well as the internet. It looks like people are mostly using platform-specific highlighters, specifically Highlight.js in the browser, RSyntaxTextArea in Swing, and CodeView on Android. None of them can be directly adapted as a reusable platform-independent highlighter.

There are several half-dead and dead pure Java highlighters:

Since pure Java highlighters are rather poor, let's consider cross-language integration options:

Tradeoffs everywhere. Pick your poison. It's not that hard to write a modern syntax-highlighting Java library using Scintillua or Sublime syntax definitions. It's an interesting idea for a new opensource project, but I am busy, so I will probably just shell out to pygmentize or something. Let me know if you develop proper Java library for syntax highlighting.