LiveMarkdown.Avalonia is a High-performance Markdown viewer for Avalonia applications.
It supports real-time rendering of Markdown content, so it's ideal for applications that require dynamic text updating, especially when streaming large model outputs.
- 🚀 High-performance rendering powered by Markdig
- 🔄 Real-time updates: Automatically re-renders changes in Markdown content
- 🎨 Customizable styles: Easily style Markdown elements using Avalonia's powerful styling system
- 🔗 Link support: Clickable links with customizable behavior
- 📊 Table support: Render tables with proper formatting
- 📜 Code block syntax highlighting: Supports multiple languages with TextMateSharp
- 🖼️ Image support: Load online, local even
avaresimages asynchronously - ✍️ Selectable text: Text can be selected across different Markdown elements
Note
This library currently only supports Append and Clear operations on the Markdown content, which is enough for LLM streaming scenarios.
Warning
Known issue: Avalonia 11.3.5 and 11.3.6 changed text layout behavior, which may cause some text offset issues in certain scenarios. e.g. code inline has extra bottom margin, wried italic font rendering, etc.
Please use 11.3.0 ~ 11.3.4 or >= 11.3.7 to avoid this problem.
This project is fully open-source and free. Your support will improve this project a lot. I sincerely thank all my sponsors!
- Basic Markdown rendering
- Real-time updates
- Link support
- Table support
- Code block syntax highlighting
- Image support
- Bitmap
- SVG
- Online images
- Local images
-
avaresimages
- Selectable text across elements
- LaTeX support
- HTML rendering
You can install the latest version from NuGet CLI:
dotnet add package LiveMarkdown.Avaloniaor use the NuGet Package Manager in your IDE.
<Application
x:Class="YourAppClass" xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" RequestedThemeVariant="Default">
<Application.Styles>
<!-- Your other styles here -->
<StyleInclude Source="avares://LiveMarkdown.Avalonia/Styles.axaml"/>
</Application.Styles>
<Application.Resources>
<!-- Your other resources here -->
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceInclude Source="avares://LiveMarkdown.Avalonia/Defaults.axaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>Add the MarkdownRenderer control to your .axaml file:
<YourControl
xmlns:md="clr-namespace:LiveMarkdown.Avalonia;assembly=LiveMarkdown.Avalonia">
<md:MarkdownRenderer x:Name="MarkdownRenderer"/>
</YourControl>Then you can manage the Markdown content in your code-behind:
// ObservableStringBuilder is used for efficient string updates
var markdownBuilder = new ObservableStringBuilder();
MarkdownRenderer.MarkdownBuilder = markdownBuilder;
// Append Markdown content, this will trigger re-rendering
markdownBuilder.Append("# Hello, Markdown!");
markdownBuilder.Append("\n\nThis is a **live** Markdown viewer for Avalonia applications.");
// Clear the content
markdownBuilder.Clear();If you want to load local images with relative paths, you can set the MarkdownRenderer.ImageBasePath property.
LaTeX is supported via the LiveMarkdown.Avalonia.Math package. You can install it via NuGet:
dotnet add package LiveMarkdown.Avalonia.MathThen register both the MathInlineNode and MathBlockNode before using LaTeX in your Markdown content:
using LiveMarkdown.Avalonia;
MarkdownNode.Register<MathInlineNode>();
MarkdownNode.Register<MathBlockNode>();Markdown elements can be styled using Avalonia's powerful styling system. You can override the default styles by defining your own styles in your application styles.
Avalonia Styling Docs:
The <ResourceInclude Source="avares://LiveMarkdown.Avalonia/Defaults.axaml"/> line in your App.axaml imports the default resources used by the renderer. You can override these resources in your application to customize the look and feel.
Here are the available resource keys:
| Key | Type | Description |
|---|---|---|
BorderColor |
Color |
Color of borders (e.g., code blocks, tables) |
ForegroundColor |
Color |
Default text color |
CardBackgroundColor |
Color |
Background color for tables |
SecondaryCardBackgroundColor |
Color |
Background color for code blocks and quotes |
CodeInlineColor |
Color |
Text color for inline code |
QuoteBorderColor |
Color |
Border color for blockquotes |
FontSizeS |
Double |
Small font size (not used yet) |
FontSizeM |
Double |
Medium font size (default text size) |
FontSizeL |
Double |
Large font size for Heading4, Heading5 and Heading6 |
FontSizeXl |
Double |
Extra large font size for Heading3 |
FontSize2Xl |
Double |
2XL font size for Heading2 |
FontSize3Xl |
Double |
3XL font size for Heading1 |
You can customize the syntax highlighting theme for code blocks. The default theme is DarkPlus.
To set the theme globally for a MarkdownRenderer instance, use the CodeBlockColorTheme property:
<md:MarkdownRenderer CodeBlockColorTheme="LightPlus" />You can also use Avalonia styles to set the theme for specific code blocks or based on conditions:
<Style Selector="md|CodeBlock">
<Setter Property="ColorTheme" Value="SolarizedDark"/>
</Style>Supported themes are defined in TextMateSharp.Grammars.ThemeName.
- Q: Why some emojis not rendered correctly (rendered in single color)?
- A: This is a known issue caused by Skia (the render backend of Avalonia). You can upgrade SkiaSharp version (e.g. >= 3.117.0) to fix this. Related issue
We welcome issues, feature ideas, and PRs! See CONTRIBUTING.md for guidelines.
Distributed under the Apache 2.0 License. See LICENSE for more information.
- markdig - BSD-2-Clause License
- Markdown parser for Everywhere.Markdown rendering
- Source repo: https://github.com/xoofx/markdig
- Svg.Skia - MIT License
- Svg rendering for images
- Source repo: https://github.com/wieslawsoltes/Svg.Skia
- TextMateSharp - MIT License
- Syntax highlighting for code blocks
- Source repo: https://github.com/danipen/TextMateSharp
- CSharpMath - MIT License
- LaTeX rendering support
- Source repo: https://github.com/verybadcat/CSharpMath

