CodeFormatter Class

Provides source code syntax highlighting functionality.

Definition

Namespace: Ookii.FormatC
Assembly: Ookii.FormatC (in Ookii.FormatC.dll) Version: 2.3.2+a0abe9e363271833c90424d1444b43a67fa5858f
C#
public class CodeFormatter
Inheritance
Object    CodeFormatter

Remarks

The CodeFormatter class will format source code based on the information provided by an implementation of the IFormattingInfo interface.

The result will be HTML source code that will display the formatted source code when combined with the appropriate style sheet.

Example

The following code sample shows how to use the CodeFormatter class to format C# source code.

C#
CodeFormatter formatter = new CodeFormatter();
formatter.FormattingInfo = new CSharpFormattingInfo();
string formattedHtml = formatter.FormatCode(System.IO.File.ReadAllText("MySourceFile.cs"));

Constructors

CodeFormatter Initializes a new instance of the CodeFormatter class.

Properties

CssClass Gets or sets the CSS class name to use on the <pre> element in the output HTML.
FormattingInfo Gets or sets the IFormattingInfo that provides information hot to format the source code.
IncludePreElement Gets or sets a value that indicates whether to emit the <pre> element in the output HTML.
LineNumberCssClass Gets or sets the CSS class used for <span> elements wrapping line numbers.
LineNumberFormat Gets or sets the format string used to format the line numbers.
LineNumberMode Gets or sets the line number mode.
TabSpaces Gets or sets the number of spaces that a tab character should be replaced with.
UsedFallbackFormatting Gets a value indicating whether fallback formatting was used by the last call to FormatCode(String).

Methods

EqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
FinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object)
FormatCode(String) Formats the specified source code as HTML.
FormatCode(String, TextWriter) Formats the specified source code as HTML, writing the result to the specified TextWriter.
GetHashCodeServes as the default hash function.
(Inherited from Object)
GetTypeGets the Type of the current instance.
(Inherited from Object)
MemberwiseCloneCreates a shallow copy of the current Object.
(Inherited from Object)
ToStringReturns a string that represents the current object.
(Inherited from Object)

Fields

DefaultCssClass The default CSS class for the <pre> element wrapping the formatted output. The value is "code".
DefaultLineNumberCssClass The default CSS class for the <span> elements wrapping line numbers. The value is "lineNumber".
DefaultLineNumberFormat The default format string used for line numbers. The value is "{0,3}. ".

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

Other Resources

Sample output of of the FormatCode(String) method for various languages.