views:

208

answers:

4

In my application, I have a requirement to convert Java/VB/VB.net/etc program to HTML, and then use that HTML page (to insert in Word doc).

Sure we can write code for this, but this will entail programming for this too, and from more than one programming languages, and dealing with bugs. Whereas it needs to be released ASAP. Using 3rd party tool for this HTML generation is not an issue.

However this 3rd party tool, code to html formatter, should be free, robust, and should convert upto Java 1.5, and other language's recent version.

Do you know of any such converter (code to html converter/formatter) which is free, distributable, robust, and converts upto recent versions of more than one languages (including Java)?

To elaborate further, I am interested in a utility which will take source code file as input, and will generate HTML file as output. The HTML file should not use javascript to color the code, because then inserting in Word the coloring will be lost.

A: 

Javadoc will convert your code to HTML (along with the associated class trees and linkages, etc), but doesn't syntax highlight the code unfortunately. What you could do is add the Google Code Prettifier to each page, which could work.

nickf
Well I thought that Javadoc only works on doc comments - will it really work on source code and generate html of code?
vikramsjn
It's been a while since I've used it myself, but IIRC, it generates a number of things: class trees, function lists, etc, as well as syntax highlighted code.
nickf
Just confirmed that Javadoc links to source, but that source is not syntax colored
vikramsjn
+1  A: 

Pygments

Java example: http://pygments.org/demo/1476/

vartec
This based on Python - how can I distribute this?Will this require generating EXE of the python module?
vikramsjn
You could use Jython. It's a JAR.
vartec
You mean Jython is a JAR? Does that mean pygments will have to be installed in Jython, and then executed from command line (using Jython)?Could you kindly elaborate your last comment.
vikramsjn
Yes, I mean Jython is a JAR. It's a Python interpreter written in Java. Pygments are Python module, which can by interpreted by Jython
vartec
Thanks a lot. Will try this approach.
vikramsjn
A: 

If you want to go with the JavaDoc way, I would recommend using Natural Docs. However, if you want to simply show the Java and convert into a CSS formatted HTML section on your page, I would recommend using Google's Code Prettify. Check out the link to README for examples. You can also check out the Java Test Page to see how the Java will look.

Ascalonian
A: 

I'm using Java2HTML. It runs as Eclipse plugin, and also from commandline or as ant script.

It can also convert to TeX and XML.

Herman Lintvelt