Java API for source formatting

白昼怎懂夜的黑 提交于 2019-12-21 18:36:10

问题


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.


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/2585446/java-api-for-source-formatting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!