![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /usr/share/doc/source-highlight/ |
<!DOCTYPE doctype PUBLIC "-//w3c//dtd html 4.0 transitional//en"> <html><head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta name="Author" content="Lorenzo Bettini"><title>GNU Source-highlight Examples - GNU Project - Free Software Foundation (FSF)</title></head> <body style="background-color: rgb(255, 255, 255);"> <h1><a class="mozTocH1" name="mozTocId593827"></a> GNU Source-highlight Examples</h1> <p>by <a href="http://www.lorenzobettini.it">Lorenzo Bettini</a> <h2>Usage and examples</h2> source-highlight only does a lexical analysis of the source code, so the program source is assumed to be correct!<br> <br> Finally, there is texinfo documentation. It is also available as an html file, and it is also <a href="source-highlight.html">available on-line</a>.<br> <p>Here we only show some examples of generated files.<br> </p> <p>Here are some links to some of the C and C++ sources of source-highlight colored with source-highlight itself: </p> <blockquote><a href="source-highlight.cc.html">source-highlight.cc.html</a></blockquote> generated with the following command <blockquote> <pre>source-highlight -s cpp -f html --doc source-highlight.cc</pre> </blockquote> And obviously it works with header file as well: <blockquote><a href="cmdline.h.html">cmdline.h.html</a></blockquote> created with the command: <blockquote> <pre>source-highlight -s cpp -f html *.h --css="mono.css"</pre> </blockquote> Here are some examples of Java files processed with source-highlight (in most of them we have used the <a href="Hello.java" hello.java="">Hello.java</a> to make some test). Here's how <a href="Hello1.html">Hello1.html</a>, <a href="Hello2.html">Hello2.html</a>, <a href="Hello3.html">Hello3.html</a>, <a href="Hello4.html">Hello4.html</a>, <a href="Hello5.html">Hello5.html</a>, <a href="Hello_h_f.html">Hello_h_f.html</a>, <a href="Hello_lines.html">Hello_lines.html</a>, <a href="Hello_xhtml.html">Hello_xhtml.html</a>, <a href="Hello_xhtml2.html">Hello_xhtml2.html</a>, <a href="Hello_notfixed.html">Hello_notfixed.html</a> were created: <pre>source-highlight -s java -f html -i Hello.java -o Hello1.html<br>source-highlight -s java -f html --input Hello.java --output Hello2.html --doc<br>source-highlight -s java -f html -i Hello.java -o Hello3.html --title "Happy Java with java2html :-)" --tab 3<br>source-highlight -s java -f html < Hello.java > Hello4.html --title "and what about CSS :-)" --css "Hello.css"<br>source-highlight -s java -f html < Hello.java > Hello5.html --title "Wooo... this is quite dark ;-D" --css "mono-alt.css"<br>source-highlight -s java -f html --doc *.java<br>Processed Hello.java <i>(creates Hello.java.html)<br></i>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"<br>source-highlight -s java -f html --line-number --doc -i Hello.java -o Hello_lines.html<br>source-highlight -s java -f xhtml --doc -i Hello.java -o Hello_xhtml.html --css xhtml.css<br>source-highlight -s java -f xhtml --doc -i Hello.java -o Hello_xhtml2.html --style-file default.style<br>source-highlight -s java --outlang-def=html_notfixed.outlang -i Hello.java -o Hello_notfixed.html --style-file default.style</pre> Here's another example: <blockquote><a href="Hello_h_f.html">Hello_h_f.html</a></blockquote> Created with the command (notice that this one uses both CSS file and headers and footers): <blockquote> <pre>source-highlight -s java -f html -i Hello.java -o Hello_h_f.html <br> --css="cpp2html.css"<br> --header="./header.html" --footer="./footer.html"</pre> </blockquote> 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, <a href="UsageExample.html">UsageExample.java</a>, 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 <span style="font-family: monospace;">-f javadoc</span> and we copy the result into the comment, as illustrated in <a href="SimpleClass.html">SimpleClass.java</a>. When we process this file with javadoc, we obtain that code formatted in the documentation html file: <a href="SimpleClass-doc.html">SimpleClass-doc.html</a>. Doesn't it look nice :-)<br><br> You can also specify several line ranges, so that you produce an output only with those specific lines of your input file; you can specify a number of lines for the sorrounding context, and the separator of ranges; for instance, this <a href="test_linerange_sep.html">output</a> was produced, starting from this <a href="test.java.html">input</a>, with the following command (note how the context is shown in gray, as specified in the style file):<br><blockquote> <pre>source-highlight -s java -f html <br> --line-range="12-18","29-34" --line-number --range-context=3 --range-separator="<...>" <br> -i test.java -o test_linerange_sep.html</pre></blockquote> <p> Range of output can also be specified using regular expressions: the beginning of the range will be detected by a line containing (in any point) a string matching the specified regular expression; the end will be detected by a line containing a string matching the same regular expression that started the range. This feature is very useful when we want to document some code (e.g., in this very manual) by showing only specific parts, that are delimited in a ad-hoc way in the source code (e.g., with specific comment patterns). for instance, this <a href="test_regexrange4.html">output</a> was produced, starting from this <a href="test.java.html">input</a>, with the following command<br><blockquote> <pre> ssource-highlight -s java -f html --regex-range="/\* [[:alpha:]]+ \*/" --line-number -i test.java -o test_regexrange4.html </pre></blockquote> <p>Here's the output of source-highlight applied to a Prolog program (through the option `<tt>source-highlight -s prolog</tt>`: <a href="test.pl.html">test.pl.html</a>. This one is an highlighted Perl program (through the option `<tt>source-highlight -s prolog</tt>`): <a href="test.pm.html">test.pm.html</a>. Here's an highlighted PHP3 program: <a href="test.php3.html">test.php3.html</a>. And here's a Python program: <a href="test.py.html">test.py.html</a>. This the flex scanner for flex files <a href="flex_scanner.ll.html">flex_scanner.ll.html</a>. This is a Ruby program: <a href="test.rb.html">test.rb.html</a>. This is a Javascript program <a href="test.js.html">test.js.html</a>. This is a Lua test program <a href="test.lua.html">test.lua.html</a>. This is a Caml test program <a href="test.ml.html">test.ml.html</a> and this is an Sml test program <a href="test.sml.html">test.sml.html</a>. <br> <br> Here are some log files formatted using the color file <a href="syslog.style.html">syslog.style</a>: <br> <ul> <li><a href="test.log.html">test.log.html</a>,</li> <li><a href="access.log.html">access.log.html</a>,</li> <li><a href="auth.log.html">auth.log.html</a>,</li> <li><a href="error.log.html">error.log.html</a>,</li> <li><a href="syslog.log.html">syslog.log.html</a>.</li> </ul> <p> This is the language definition file for C/C++: <a href="cpp.lang.html">cpp.lang.html</a>, the one for the log files above, <a href="log.lang.html">log.lang.html</a>, and the language definition file for the language definition syntax itself: <a href="langdef.lang.html">langdef.lang.html</a>. </p> <p> Here's the html output of test.java.html formatted in html itself: <a href="test.htm.html">test.htm.html</a>.<br> <br> and here's the output of test.java.tex formatted in html: <a href="test.java.tex.html">test.java.tex.html</a> </p> <p>These HTML outputs contain cross references, <a href="test_refs.h.html">test_refs.h.html</a>, <a href="test_refs.cpp.html">test_refs.cpp.html</a>, generated with the following command: </p> <blockquote> <pre>source-highlight -s cpp -f html --title="Contains references to tags" <br> --gen-references=inline test_refs.h test_refs.cpp</pre> </blockquote> <h2><a class="mozTocH2" name="mozTocId323328"></a>Style files</h2> <p>Since version 2.6, source-highlight can use CSS style files (limited support) as style files for coloring and formatting the output. Here you can find the output using all these files shipped with source-highlight (these were adapted from those provided by <a href="http://shjs.sourceforge.net">SHJS</a>):</p> <p><a href="style_examples.html">Style examples</a> (huge file). </body></html>