|
NAMEcode2html - Converts a program source code to HTMLSYNOPSIS(1) code2html [options] [input-file [output-file]](2) code2html -p [file [alternate-outfile]] (3) code2html (as a CGI script; see the section on CGI) DESCRIPTIONcode2html is a perl script which converts a program source code to syntax highlighted HTML, or any other format for wich rules are defined.(1) OPTIONS
(2) HTML patchingcode2html -p [file [alternate-outfile]]code2html also allows you to have inline source code in an html file. It can then take this html file and insert the syntax highlighted code. If no file is given, code2html reads from STDIN and writes to STDOUT. If just one file is given it replaces this file with the output. If two files are provided, the first one is read from and the second one written to. To use this feature, just insert a like like this into your html file:
the syntax highlighted file will be inserted at this position enclosed in <pre> tags. All options that can be given on the command line like --linenumbers etc. work. --help, --version, etc. work too however it is not very intelligent to use them :). Using --output-format to choose a non-HTML outputformat is not adviseable. --content-type is ignored. You may also write the program's source code directly in the html file with the following syntax:
It is usually a good idea to at least give the --language-mode option to specify the language. (3) CGIIf the the script is used as a CGI script (GATEWAY_INTERFACE environment set and no command line arguments given) code2html reads the arguments either from the query string or from SDTIN. (methods POST and GET).--content-type is switched on automatically and the output always goes to STDOUT. The following parameters/options are accepted:
Why two cgi-inputs you may ask: This is to allow your users to choose vie a <form> interface whether they want to insert their file into a <textarea> or user a <browse> button to select their file. See the example on my home- page. Note that if $FILES_DISALLOWED_IN_CGI is 0 it is possbile for your users to read all the files the httpd can read (if you don't run a cgi- wrapper or something like this. By default this value is set to 1, so file reading via cgi should not be allowed. You can allow it with setting $FILES_DISALLOWED_IN_CGI to 0 at the top of the script. The input selector REDIRECT_URL needs a special explaination. The file name is formed from the two enviroment variables DOCUMENT_ROOT and REDIRECT_URL. If you want apache to automatically call code2html for all program source code files you may do this by adding these two lines to your srm.conf:
or something similar to this. In the AddHandle line you can choose which extensions to pass through code2html. WARNING: Do not add .pl to this line and name this script “code2html.pl”. This will result in a loop. Also make sure that you load the Action module (srm.conf). Replace /cgi-bin/code2html with the virtual location under which the file can be accessed. Note the “foo=” part. Apache appends the URL of the file to display at the end of the action part. We do not need this since we use the environment variable REDIRECT_URL however we do not want to get the url addes to the input-selector string. Therefore we append the “&foo=” part. Tnx to Kevin Burton <burton@relativity.yi.org> for the idea. He also states that > It is more powerfull if you use it in an Apache
EXAMPLEassuming code2html is in the current directory, you may type
FILESCode2html looks for it's configuration in several places.
Entries in a file that is mentioned earlier in this list override rules from later files. The file structure must be valid perl code. The global variables %LANGUAGE and %STYLESHEET are already defined, so you should not redeclare them using “my”. When you are looking for a model configuration to serve as a basis for your own configuration file, it is probably best to start out by checking the built-in definitions at the bottom of code2html. If your pattern includes back references like a lot patterns do in perl for example, then you have to use \2 instead of \1, \3 instead of \2 and so on. I really don't like this hack but it is a lot faster. Example:
In this example the perl << stuff is matched, i.e. everything from a << until a line that consists of exactly the same string as behind the << was. The \2 references the matched chars in the parentenses. If you ever write language specific rule files yourself, I'd be grateful if you could send those to me, so I could make them available (with full credits of course) on my homepage for anyone to grab, whenever some of those files suit someone else's needs. Before you do so you might also have a look at my site to check wheter someone has already written a rule file for your favourite language. NOTESThe language recognition mechanism relies on specific patterns within the file name and the content of the processed file, such as file name extensions and shebangs (#!). This means that if the input is a pipe or a socket, the file name does not follow traditional naming conventions, or the content of the processed file is incomplete, the input language name should be specified using the --language-mode command line parameter.BUGSPlease report bugs to code2html@palfrader.org. This program is still a beta release, so you should expect to find some.Also have a look at my web-site, perhaps a new version is available already at http://www.palfrader.org/code2html/. AUTHORPeter Palfrader, <code2html@palfrader.org> A lot of other people. See contributers in the file itself.LICENSECopyright (c) 1999, 2000 by Peter Palfrader & others.Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”, to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Visit the GSP FreeBSD Man Page Interface. |