Huskui.Avalonia.Code 1.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Huskui.Avalonia.Code --version 1.1.0
                    
NuGet\Install-Package Huskui.Avalonia.Code -Version 1.1.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="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Huskui.Avalonia.Code" Version="1.1.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 1.1.0
                    
#r "nuget: Huskui.Avalonia.Code, 1.1.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@1.1.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=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Huskui.Avalonia.Code&version=1.1.0
                    
Install as a Cake Tool

Huskui.Avalonia.Code

A syntax-highlighted code viewer extension for Huskui.Avalonia, powered by TextMate grammars with a lightweight inline renderer.

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 TextMate grammars through TextMateSharp.Grammars. Languages are resolved through built-in aliases and file-extension-style mappings, then fall back to plain text if no grammar is available.

Supported Languages

Language Identifiers
Bash bash, sh, shell, zsh
C# csharp, cs
C++ cpp
C c
CSS css
F# fsharp, fs
HTML html
Java java
JavaScript javascript, js
JSON json
Markdown markdown, md
Less less
Lua lua
PHP php
PowerShell powershell, ps1
Python python, py
Rust rust, rs
SCSS scss
SQL sql
TypeScript typescript, ts, tsx
XML xml, xaml, axaml
YAML yaml, yml
Visual Basic visualbasic, vb
ASP.NET aspx
CoffeeScript coffeescript
Ruby ruby

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

Features

  • Syntax Highlighting — TextMate-based tokenization with Huskui Radix light/dark token themes
  • Line Numbers — Optional lightweight line number gutter
  • Copy to Clipboard — Header bar with language label and copy button
  • Lightweight Rendering — Code content is rendered as Avalonia inlines without embedding an editor control
  • 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
1.2.0 82 5/26/2026
1.1.3 85 5/21/2026
1.1.2 161 5/7/2026
1.1.1 118 5/5/2026
1.1.0 129 5/3/2026
1.0.1 114 4/22/2026
1.0.0 118 4/22/2026
0.17.0 110 4/21/2026
0.16.1 110 4/17/2026
0.16.0 105 4/16/2026
0.15.0 114 4/13/2026
0.14.2 116 4/9/2026
0.14.1 110 4/8/2026
0.14.0 118 4/2/2026

# Changelog

All notable changes to this project will be documented in this file.

## [1.1.0] - 2026-05-03

### 🚀 Features

- *(Mvvm)* Add GetRequiredParameter to IViewContext<T>
- *(Controls)* Add variant classes to SplitButton
- *(Controls)* Buttons in ButtonGroup have primary variants
- *(Gallery)* Add brushes page
- *(Ui)* Add Groupbox theme

### 💼 Other

- *(format)* Format
- *(format)* Format
- *(format)* Format
- Feat: 添加 Java Detection 相关能力

### 🚜 Refactor

- *(Gallery)* Add tag outline
- 优化 Overlay 的布局,现在允许 Modal 类自己规定对其方式
- *(Markdown)* Make bullet no dot

### ⚙️ Miscellaneous Tasks

- *(ci)* Add mvvm workflow
- *(ci)* Add mvvm workflow

<!-- generated by git-cliff -->