CodeToHtml Sample

Sample Overview

This sample program can be used to create an HTML file containing color-coded source code, in various languages including JScript and C#.

This sample was written in JScript.

Some features:

Extensible Architecture

Anything you add in the .ini file or on the command-line gets added to the global g_objOptions object, so you can use it in a dynamic replacement as specified in the file replace.ini.

The default behavior is that extensions .cs and .js are recognized and the correct .ini files loaded for that language. To support another language, copy the js_* files and rename them to <lang_extention>_*. Then modify the files to match the correct values for the new language.

Examine the default js_replace.ini and header.txt files to see the sorts of things that you can do to with the .ini files.

Sample Source and Build Output Locations

The sample source is found in rotor\samples\utilities\codetohtml.

The source file is:

The build output location is %TARGETCOMPLUS%\samples\utilities\codetohtml.  The output file is an executable assembly named codetohtml.exe.

Building the Sample

All samples are built from the buildall script. 

You can also build all the samples by switching to the root of the sample directory, sscli\samples, and typing build -c.

You can build this specific sample by switching to the sample directory and typing build -c.

Running the Sample

These steps require that the Shared Source CLI (SSCLI) be already built and functional.

This sample requires the files <lang>_codetohtml.ini, <lang>_keywords.ini, <lang>_userdefined.ini, and <lang>_futurereserved.ini to be present in the current directory where the application is launched.

  1. Run env.bat or source the env.csh or env.sh script files, depending on your platform.
  2. Switch to the %TARGETCOMPLUS%\samples\utilities\codetohtml directory.
  3. Type the following command:

    clix codetohtml sourcefilename

where sourcefilename is the full path to a C# or JScript source file.  The generated HTML file will be placed in the same directory as the source file.


Copyright (c) 2002 Microsoft Corporation. All rights reserved.