SyntaxHighlighter

Display

Renders 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
NameTypeDefaultDescription
Appearance
TabWidthNullable<Int32>Width of tab characters in spaces. When specified and greater than 0, overrides tab width in Options.
Other
AdditionalAttributesIReadOnlyDictionary<String, Object>Additional HTML attributes for the syntax highlighter element.
CodeStringSource code to highlight.
LanguageStringProgramming language of the code. If null , attempts automatic detection. Supported: "csharp", "javascript", "python", "sql", etc.
OptionsSyntaxOptionsAdditional syntax highlighting options. If null , uses Default.
ShowLineNumbersBooleanWhether line numbers should be displayed. Default is false .
ThemeStringColor theme for syntax highlighting. If null , uses default theme.

API