This element can be used to display a code fragment in a conceptual topic. For single lines or
keywords, you can use the codeInline element.
Note |
The Sandcastle Help File Builder comes with a custom build component (the Code Block
Component) that can colorize the code, add line numbering, collapsible sections, supports many other
languages, and has several other features. It is also available in a standalone download for use in other
third-party build tools or your own custom scripts. Refer to its help file for more information. The examples
below were rendered using it.
|
Usage
Enter the element in the topic and specify a language using the language
attribute. An optional title element can be added to provide an alternate title that is
more descriptive. If the title attribute is set to a single space, it will effectively
remove the title for the given code element.
Place the code within the element. Because it is XML, the code must either be HTML encoded or must
be enclosed within a CDATA element to preserve the formatting and any special characters
that would normally require encoding.
Example
|
Copy
|
An encoded example:
<code language="c#">
/// <summary>
/// A sample method
/// </summary>
public void Test()
{
}
</code>
An example that uses CDATA to avoid the need to encode the sample and the optional title element:
<code language="vb" title="A VB.NET Example"><![CDATA[
''' <summary>
''' A sample method
''' <summary>
Public Sub Test()
End Sub]]>
</code>
|
Example Output
An encoded example:
C# |
Copy
|
public void Test()
{
}
|
An example that uses CDATA to avoid the need to encode the sample and the optional title element:
A VB.NET Example |
Copy
|
Public Sub Test()
End Sub
|
See Also