Avalonia.Controls.Documents.Serialization.Html 12.3.0

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Avalonia.Controls.Documents.Serialization.Html --version 12.3.0
                    
NuGet\Install-Package Avalonia.Controls.Documents.Serialization.Html -Version 12.3.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="Avalonia.Controls.Documents.Serialization.Html" Version="12.3.0" />
                    
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.3.0" />
                    
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.3.0
                    
#r "nuget: Avalonia.Controls.Documents.Serialization.Html, 12.3.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 Avalonia.Controls.Documents.Serialization.Html@12.3.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=Avalonia.Controls.Documents.Serialization.Html&version=12.3.0
                    
Install as a Cake Addin
#tool nuget:?package=Avalonia.Controls.Documents.Serialization.Html&version=12.3.0
                    
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.3.0

Adds to 12.2.3 and removes nothing: every type and member a 12.2.3 build could reference is still there with the same signature, checked against the released packages on every build.

### Features
- `<img>` is read. A `data:` source with a base64 payload is decoded into the document as an embedded image; any other source travels as an image reference the host resolves at render time, the way a Markdown image does. The `alt` text and the `width`/`height` attributes (or the matching CSS lengths) come with it. A registered tag handler for `img` still wins, so an application that supplied its own image policy keeps it.
- CSS `text-decoration-style` raises to `InlineFormatting.UnderlineStyle` on read: `solid`, `double`, `dotted`, `dashed` and `wavy` map to `Single`, `Double`, `Dotted`, `Dashed` and `Wave`. The keyword is read from either the longhand or the `text-decoration` shorthand (`text-decoration: underline dotted`), whichever the page spells, and in either declaration order. The style only lands where the declarations also left an underline on, since it qualifies an underline rather than switching one on; on a strikethrough-only element it is discarded. CSS has no spelling for `Thick`, `DashDot`, `DashDotDot` or `Word`, so those never arrive from HTML.
- CSS keep rules raise to the model on read: `break-inside`/`page-break-inside: avoid` to `KeepTogether`, `break-after`/`page-break-after: avoid` to `KeepWithNext`, and `orphans`/`widows` counts collapse onto `WidowControl` (a minimum below 2 turns it off, 2 or more turns it on explicitly).
- `break-before: page` and the legacy `page-break-before: always` (plus the `left`/`right` page forms) on a block tag now raise to `Block.BreakPageBefore` on read, so CSS page breaks survive HTML import.

### Fixes
- A bare `&` in text corrupted the characters after it. The entity scan ran on for up to 10 characters and stopped only at `;`, `<` or end of input, then re-emitted a `;` that was never in the source, so `Tom & Jerry went home` imported as `Tom & Jerry wen;t home`. The scan now stops before whitespace and a second `&`, and puts back only the characters it consumed.
- The block CSS - `text-align`, the `break-before`/`break-inside`/`break-after` rules, `orphans` and `widows` - was read only on `<p>` and `<div>`. It now applies on `<h1>`-`<h6>`, `<blockquote>`, `<pre>`, `<li>` and `<td>`/`<th>` as well, so `<h1 style="break-before: page">` starts a page and a centred heading stays centred. A cell's declarations land on the content it holds, the way CSS inheritance puts them there.
- `text-decoration` on a `<span style="...">` produced no decoration at all. The parse folded the keyword into `InlineFormatting.TextDecorations` with `|`, and that property is nullable, so the lifted operator returned null for the empty formatting an inline style parse starts from: every `text-decoration: underline` and `line-through` on a span was silently dropped. Only the `<u>`, `<s>` and `<del>` tag paths, which build their own formatting, carried a decoration through.