FormatC source code formatting

FormatC is a utility that allows you to add syntax highlighting to your C#, Visual Basic, C++, XML, HTML, Transact-SQL or PowerShell source code, so you can publish it on a web page or blog post.

FormatC supports the new features introduced in C# 3.0 and Visual Basic 9.0. Some of the new keywords of those languages are contextual keywords; this means that they are only keywords in certain contexts. FormatC will treat these identifiers as keywords (and highlight them as such) regardless of context.

Visual Basic XML literals are supported, however the XML literals must be marked explicitly with with [xml][/xml]. For example, this would look like this with a simple XML literal: Dim xmlLiteral = [xml]<Foo />[/xml]

The [xml][/xml] tags will not be included in the output, and the contents of those tags will be formatted as XML literals. Embedded expressions in XML literals (which are delimited by <%= %> blocks) are also supported, and the contents of embedded expressions will be formatted as Visual Basic code. However, having an XML literal inside an embedded expression in another XML literal is not supported.

A default stylesheet is provided. You can customize the syntax highlighting by modifying this stylesheet.

Format source code


You can specify a space-delimited list of names that should be treated as type names by the formatter (e.g. "Console String List"). These names will be highlighted as type names regardless of the context in which they occur.

Download

You can download FormatC as a .Net class library to use in your own application. The source code is also available. You can also view the documentation.

Download FormatC 1.2.1 (binary and source code)

Change Log

Version 1.2.1:
  • Fixed: XML formatter didn't support element or attribute names containing periods.
Version1.2:
  • Added support for escaped keywords in C# and VB.
  • Added support for PowerShell and T-SQL.
  • Improved string handling in C# and C++.
  • Improved XML formatter.
  • Added support for line numbers.
Version 1.1:
  • Support for VB 9.0.
  • Support for C# 3.0.