Avalonia.Controls.Documents.Serialization.Html
12.3.1
Prefix Reserved
See the version list below for details.
dotnet add package Avalonia.Controls.Documents.Serialization.Html --version 12.3.1
NuGet\Install-Package Avalonia.Controls.Documents.Serialization.Html -Version 12.3.1
<PackageReference Include="Avalonia.Controls.Documents.Serialization.Html" Version="12.3.1" />
<PackageVersion Include="Avalonia.Controls.Documents.Serialization.Html" Version="12.3.1" />
<PackageReference Include="Avalonia.Controls.Documents.Serialization.Html" />
paket add Avalonia.Controls.Documents.Serialization.Html --version 12.3.1
#r "nuget: Avalonia.Controls.Documents.Serialization.Html, 12.3.1"
#:package Avalonia.Controls.Documents.Serialization.Html@12.3.1
#addin nuget:?package=Avalonia.Controls.Documents.Serialization.Html&version=12.3.1
#tool nuget:?package=Avalonia.Controls.Documents.Serialization.Html&version=12.3.1
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 aFlowDocumentor aTextDocument - Custom tag handling through
IHtmlTagHandler - Implements the
IDocumentSerializerinterface
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 | Versions 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. |
-
net10.0
- Avalonia.Controls.Documents (>= 12.3.1)
- AvaloniaUI.Licensing (>= 3.1.2)
-
net8.0
- Avalonia.Controls.Documents (>= 12.3.1)
- AvaloniaUI.Licensing (>= 3.1.2)
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.