SyntaxHighlighter
DisplayRenders highlighted code blocks with SyntaxHighlightingService.
@using Spectre.Console
@using RazorConsole.Components
<SyntaxHighlighter Language="csharp"
Code="@codeSnippet"
ShowLineNumbers="true" />
@code {
private string codeSnippet = @"
public class HelloWorld
{
public void SayHello()
{
Console.WriteLine(""Hello, World!"");
}
}
".Trim();
}Parameters
7| Name | Type | Default | Description |
|---|---|---|---|
Appearance | |||
TabWidth | Nullable<Int32> | — | Width of tab characters in spaces. When specified and greater than 0, overrides tab width in Options. |
Other | |||
AdditionalAttributes | IReadOnlyDictionary<String, Object> | — | Additional HTML attributes for the syntax highlighter element. |
Code | String | — | Source code to highlight. |
Language | String | — | Programming language of the code. If null , attempts automatic detection. Supported: "csharp", "javascript", "python", "sql", etc. |
Options | SyntaxOptions | — | Additional syntax highlighting options. If null , uses Default. |
ShowLineNumbers | Boolean | — | Whether line numbers should be displayed. Default is false . |
Theme | String | — | Color theme for syntax highlighting. If null , uses default theme. |