views:

83

answers:

2

Hi

There are several PHP or js code formatting libs out there -- does anyone know if similar libs exist in Java?

Ie., Given a string of code, return a formatted string with syntax colouring etc.

It'd be ideal if it auto detected the language, but I might be pushing my luck there...

The text will ultimately be displayed within a Flex application, so while I could use a js lib, we'll be parsing large files (up to 6000 lines), so I'd like to keep client side processing minimal.

Ideal output is HTML without CSS, although I'll take what I can get.

+3  A: 

That are two distinct tasks. With regard to code formatting, look around using the keyword "java beautifier". Here is a list. I myself have had good experiences with Jalopy which also ships with an Eclipse plugin. With regard to syntax highlighting, it depends on where you'd like to use it. If programmatically, use JHighlight, or if on a webpage, use Prettify (Stackoverflow also uses it and it can detect languages), or as an Eclipse export plugin, use Java2HTML.

BalusC
Very good answer!
Tomislav Nakic-Alfirevic
A: 

Perhaps try to see the Colorer Project: http://colorer.sourceforge.net/

Matthieu FAURE