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.
CodeString—Source code to highlight.
LanguageString—Programming language of the code. If null, attempts automatic detection. Supported: "csharp", "javascript", "python", "sql", etc.
OptionsSyntaxOptions—Additional syntax highlighting options. If null, uses Default.
ShowLineNumbersBoolean—Whether line numbers should be displayed. Default is false.
ThemeString—Color theme for syntax highlighting. If null, uses default theme.

API