Anyone have good (has to be free!) ways of displaying Java code in the browser in a nice pretty format? I’ve seen many examples on various websites but have no experience with using any. What are your favorites? Easy to use is a plus!
Features wanted:
- free
- easy to use with a tag (not required)
- color coded syntax
Gist is my favorite.
If you want to host your own code, check SyntaxHighlighter
If you want a server-side one, Java2Html could be an option (don’t think it supports html tough), or I made one long time back called jrainbow (development is abandoned).
Gist is easy: you paste the code on the gist website then you grab the html code to embed on your website.
SyntaxHighlighter is also simple: just include some javascript in your website, then put your code within
<pre class="brush:java"> your code here </pre>and specify the language afterbrush:, there are many supported. You can also have line numbers and other things.For jrainbow, checkout the code via svn, then do
mvn jetty:runand open the browser athttp://localhost:8081/jrainbow/to try it. I was planning to make some JSP tag to ease usage.