Huskui.Avalonia.Code 0.14.0

dotnet add package Huskui.Avalonia.Code --version 0.14.0
                    
NuGet\Install-Package Huskui.Avalonia.Code -Version 0.14.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Huskui.Avalonia.Code" Version="0.14.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Huskui.Avalonia.Code" Version="0.14.0" />
                    
Directory.Packages.props
<PackageReference Include="Huskui.Avalonia.Code" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Huskui.Avalonia.Code --version 0.14.0
                    
#r "nuget: Huskui.Avalonia.Code, 0.14.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Huskui.Avalonia.Code@0.14.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Huskui.Avalonia.Code&version=0.14.0
                    
Install as a Cake Addin
#tool nuget:?package=Huskui.Avalonia.Code&version=0.14.0
                    
Install as a Cake Tool

Huskui.Avalonia.Code

A syntax-highlighted code viewer extension for Huskui.Avalonia, powered by ColorCode.Core.

Relationship to Huskui.Avalonia

Huskui.Avalonia.Code is an extension library for Huskui.Avalonia — it cannot be used standalone.

  • Prerequisite: You must install Huskui.Avalonia and use HuskuiTheme in your application
  • Auto-loading: Once the assembly is loaded, HuskuiTheme automatically merges the extension's theme resources via the [HuskuiExtension] mechanism — no manual style includes needed
  • Shared namespace: Controls are mapped to https://github.com/d3ara1n/Huskui.Avalonia, using the same husk: XAML prefix as the core library

Installation

dotnet add package Huskui.Avalonia
dotnet add package Huskui.Avalonia.Code

Usage

Basic

<husk:CodeViewer Code="{Binding SourceCode}" Language="csharp" />

Properties

Property Type Default Description
Code string "" Source code text to display
Language string "xml" Language identifier for syntax highlighting
IsLineNumbersVisible bool true Show line numbers column
IsCopyButtonVisible bool true Show copy button in the header bar
Inlines InlineCollection? null Custom inline collection; overrides Code-based rendering when set

XAML Example

<UserControl xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:husk="https://github.com/d3ara1n/Huskui.Avalonia"
             x:Class="YourApp.CodePage">

    <StackPanel Spacing="16">
        
        <husk:CodeViewer
            Language="csharp"
            Code='public class Hello&#x0a;{&#x0a;    public void Greet() => Console.WriteLine(&quot;Hello!&quot;);&#x0a;}' />

        
        <husk:CodeViewer
            Language="xml"
            IsLineNumbersVisible="False"
            Code="&lt;Button Content=&quot;Click me&quot; /&gt;" />

        
        <husk:CodeViewer
            Language="js"
            IsCopyButtonVisible="False"
            Code="console.log(&quot;Hello&quot;);" />
    </StackPanel>
</UserControl>

C# Example

var viewer = new CodeViewer
{
    Language = "csharp",
    Code = """
        public class Hello
        {
            public void Greet() => Console.WriteLine("Hello!");
        }
        """
};

Language Support

CodeViewer uses ColorCode.Core for syntax highlighting. Languages are resolved in the following order:

  1. Languages.FindById() — direct ColorCode language ID lookup
  2. Languages.AllHasAlias() — alias-based lookup
  3. Built-in convenience aliases (see table below)

Supported Languages

Language Identifiers
C# csharp, cs
C++ cpp
CSS css
F# fsharp, fs
HTML html
Java java
JavaScript javascript, js
Markdown markdown, md
PHP php
PowerShell powershell, ps1
Python python, py
SQL sql
TypeScript typescript, ts, tsx
XML xml, xaml, axaml
ASP.NET aspx
CoffeeScript coffeescript
Ruby ruby

Note: The full list of supported languages depends on ColorCode.Core. If a language is not recognized, the code is rendered as plain text without syntax highlighting.

Features

  • Syntax Highlighting — ColorCode-based tokenization with dark theme styling
  • Line Numbers(WIP) — Optional line number gutter
  • Copy to Clipboard — Header bar with language label and copy button
  • Selectable Text — Code content is rendered in a SelectableTextBlock for easy text selection
  • Custom Inlines — Override rendering by providing your own InlineCollection
  • Monospace Font — Defaults to Cascadia Code, Consolas, Courier New, monospace

Dependencies

License

MIT

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Huskui.Avalonia.Code:

Package Downloads
Huskui.Avalonia.Markdown

Markdown rendering extension for Huskui.Avalonia, converting Markdown text to native Avalonia controls using Markdig.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.14.0 30 4/2/2026