by Lorenzo Bettini
This program, given a source file, produces a document with syntax highlighting.
Source-highlight reads source language specifications dynamically, thus it can be easily extended (without recompiling the sources) for handling new languages. It also reads output format specifications dynamically, and thus it can be easily extended (without recompiling the sources) for handling new output formats. The syntax for these specifications is quite easy (take a look at the manual).
Notice that source-highlight can also be used as a formatter (i.e., without highlighting): you can, for instance, format a txt file in HTML (and it will take care of translating special characters, such as, <, >, &).
Since version 2.2, source-highlight can also generate cross references; in order to do this it relies on GNU Ctags, http://ctags.sourceforge.net.
These are the output formats already supported:
These are the input languages (or input formats) already supported
(in alphabetical order):
NOTICE: now the name of the program is source-highlight: there are no two separate programs, namely java2html and cpp2html, anymore. However there are two shell scripts with the same name in order to facilitate the migration (however their use is not advised).
GNU Source-highlight is free software. Please see the file COPYING for details. For documentation, please read this file.
GNU Source-highlight is a GNU
program and its main home page is at GNU site:
I do not distribute Windows binaries anymore; since, they can be
easily built by using Cygnus C/C++ compiler, available at http://www.cygwin.com/. However, if
you don't feel like downloading such compiler, you can request such
binaries directly to me, by e-mail (find my e-mail at my home page)
and I can send them to you.
An MS-Windows port of Source-highlight is available from http://gnuwin32.sourceforge.net/.
cvs -z3 -d:pserver:email@example.com:/sources/src-highlite co src-highliteFurther instructions can be found at the address: http://savannah.gnu.org/projects/src-highlite.
Please notice that this way you will get the latest development sources of Source-highlight, which may also be unstable. This solution is the best if you intend to correct/extend this program: you should send me patches against the latest cvs repository sources.
If, on the contrary, you want to get the sources of a given release, through cvs, say, e.g., version X.Y.Z, you must specify the tag rel_X_Y_Z when you run the cvs command or the cvs update command.
When you compile the sources that you get through the cvs repository, before running the configure and make commands, you should, at least the first time, run the command:
This will run the autotools commands in the correct order, and also copy possibly missing files. You should have installed recent versions of automake and autoconf in order for this to succeed. You will also need flex and bison.
NOTICE: This convention holds since release 2.1.
Here we only show some examples of generated files.
Here are some links to some of the C and C++ sources of source-highlight colored with source-highlight itself:
startapp.cc.htmlgenerated with the following command
And obviously it works with header file as well:source-highlight -s cpp -f html --doc startapp.cc
cmdline.h.htmlcreated with the command:
Here are some examples of Java files processed with source-highlight (in most of them we have used the Hello.java to make some test). Here's how Hello1.html, Hello2.html, Hello3.html, Hello4.html, Hello5.html, Hello_h_f.html, Hello_lines.html, Hello_xhtml.html, Hello_xhtml2.html, Hello_notfixed.html were created:source-highlight -s cpp -f html *.h --css="mono.css"
source-highlight -s java -f html -i Hello.java -o Hello1.htmlHere's another example:
source-highlight -s java -f html --input Hello.java --output Hello2.html --doc
source-highlight -s java -f html -i Hello.java -o Hello3.html --title "Happy Java with java2html :-)" --tab 3
source-highlight -s java -f html < Hello.java > Hello4.html --title "and what about CSS :-)" --css "Hello.css"
source-highlight -s java -f html < Hello.java > Hello5.html --title "Wooo... this is quite dark ;-D" --css "mono-alt.css"
source-highlight -s java -f html --doc *.java
Processed Hello.java (creates Hello.java.html)
source-highlight -s java -f html --doc -i Hello.java -o Hello_h_f.html --style-file="default.style" --header="header.html" --footer="footer.html"
source-highlight -s java -f html --line-number --doc -i Hello.java -o Hello_lines.html
source-highlight -s java -f xhtml --doc -i Hello.java -o Hello_xhtml.html --css xhtml.css
source-highlight -s java -f xhtml --doc -i Hello.java -o Hello_xhtml2.html --style-file default.style
source-highlight -s java --outlang-def=html_notfixed.outlang -i Hello.java -o Hello_notfixed.html --style-file default.style
Hello_h_f.htmlCreated with the command (notice that this one uses both CSS file and headers and footers):
Source-highlight can also generate HTML code to be embedded (i.e., copied and pasted) inside a Javadoc comment (or another kind of comment framework such as Doxygen). This way, when you run javadoc on such a file, the resulting generated html documentation files will have the code snippets highlighted. For instance, consider this piece of code, UsageExample.java, representing an example of usage of the class SimpleClass; we would like to embed this code (formatted) into a javadoc comment of SimpleClass, so we process it with the option -f javadoc and we copy the result into the comment, as illustrated in SimpleClass.java. When we process this file with javadoc, we obtain that code formatted in the documentation html file: SimpleClass-doc.html. Doesn't it look nice :-)source-highlight -s java -f html -i Hello.java -o Hello_h_f.html
This is the language definition file for C/C++: cpp.lang.html, the one for the log files above, log.lang.html, and the language definition file for the language definition syntax itself: langdef.lang.html.
Here's the html output of test.java.html formatted in html
and here's the output of test.java.tex formatted in html: test.java.tex.html
Finally, these HTML outputs contain cross references, test_refs.h.html, test_refs.cpp.html, generated with the following command:
source-highlight -s cpp -f html --title="Contains references to tags"
--gen-references=inline test_refs.h test_refs.cpp
Actually I want to extend it, so if you have some ideas...
The most import one will be to make source-highlight more powerful :-)
Please send all bug reports by electronic mail to:
bug-source-highlight at gnu dot org
My home page is http://www.lorenzobettini.it
source-highlight is free software. See the file COPYING for copying conditions. Anyway I won't get offended if you send me a postcard :-)
Return to GNU's home page.
Please send FSF & GNU inquiries & questions to firstname.lastname@example.org. There are also other ways to contact the FSF.
Please send comments on these web pages to email@example.com, send other questions to firstname.lastname@example.org.
Copyright (C) 2001 Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA
Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved.
Updated:9 Jan 2001 mhw