Avalonia.Controls.Documents.Serialization.Html 12.4.1

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

Avalonia.Controls.Documents.Html

HTML import for Avalonia.Controls.Documents. Reads a curated set of HTML into a DocumentSnapshot.

Features

  • Import HTML content into a DocumentSnapshot, which materializes as a FlowDocument or a TextDocument
  • Custom tag handling through IHtmlTagHandler
  • Implements the IDocumentSerializer interface

Export is not supported: HtmlSerializer.CanWrite is false and Serialize throws NotSupportedException. Use the RTF, DOCX, XAML or PDF serializers to write.

Quick Start

var serializer = new HtmlSerializer();
var snapshot = serializer.Deserialize(stream);
var document = FlowDocument.FromSnapshot(snapshot);

Teach it a tag the built-in mapping does not know:

sealed class DetailsHandler : IHtmlTagHandler
{
    public bool IsBlockLevel => true;

    public void HandleOpenTag(HtmlReaderContext context, ReadOnlySpan<char> tagName, HtmlTagAttributes attributes)
    {
        context.CloseParagraph();
        context.EnsureParagraph();
        if (attributes.TryGetValue("open", out _))
            context.WriteText("(expanded) ");
    }

    public void HandleCloseTag(HtmlReaderContext context, ReadOnlySpan<char> tagName) => context.CloseParagraph();

    public void HandleSelfClosingTag(HtmlReaderContext context, ReadOnlySpan<char> tagName, HtmlTagAttributes attributes) { }
}

var options = new HtmlSerializerOptions(new Dictionary<string, IHtmlTagHandler> { ["details"] = new DetailsHandler() });
var serializer = new HtmlSerializer(options);

Dependencies

  • Avalonia.Controls.Documents

Documentation

See the documentation for more details.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  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 Avalonia.Controls.Documents.Serialization.Html:

Package Downloads
Avalonia.Controls.Markdown

Markdown rendering control for Avalonia applications

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
13.0.0-rc2 185 9/10/2026
12.4.1 398 11/5/2026
12.4.0 22,842 10/28/2026
12.3.1 22,126 10/8/2026
12.3.0 7,627 9/11/2026
12.2.3 2,489 8/20/2026
12.2.2 35,821 7/31/2026
12.2.1 540 7/29/2026
12.2.0 10,089 7/23/2026
12.1.5 9,154 6/29/2026
12.1.4 4,878 6/22/2026
12.1.3 659 6/9/2026
12.1.2 721 6/2/2026
12.1.1 1,167 5/14/2026
12.1.0 410 5/12/2026

## 12.4.0

### Features
- Link targets import as bookmarks (`Block.Bookmarks`), so a `#name` link navigates: the `id` of a paragraph or heading names it, the `id` of a container (list item, cell, quote) names its first paragraph, and an `a` element's `name` or `id` names the paragraph it sits in.

### Fixes
- Attribute values kept their character references verbatim, so `<a href="?a=1&amp;b=2">` imported a link to `?a=1&amp;b=2` and `alt="Tom &amp; Jerry"` kept the `&amp;`. Values are now decoded the same way as text, for the reader's own attributes and for the values an `IHtmlTagHandler` receives through `HtmlTagAttributes`. A bare `&` that starts no known reference stays as it is.
- A quoted `font-family` list lost only its first and last quote, so `font-family: 'Segoe UI', Arial` imported the family `Segoe UI', Arial`. Each family is now unquoted on its own and the list is joined the way the model spells one (`Segoe UI,Arial`). An empty list leaves the family unset instead of setting it to an empty name.
- A full page's `<title>` imported as the document's first paragraph, because the tag was passed through like `<head>` and `<body>`. Its content is now skipped the way `<script>` and `<style>` content is.
- `font-style: oblique` imported as `FontStyle.Italic`, and the angle form `oblique 10deg` was ignored. Both now map to `FontStyle.Oblique`.
- A `>` inside a quoted attribute value ended the tag, so `<a href="?q=a>b">` linked to `?q=a` and imported the rest of the tag as text. A quote right after `=` now holds the tag open until the matching quote closes the value.