Skip to content

Repository files navigation

MarkView.Avalonia

NuGet Version NuGet Downloads Avalonia License CI

Markview.Avalonia logo

A Markdig-powered markdown viewer control for Avalonia UI v12. Drop MarkdownViewer into any Avalonia window or panel to render rich markdown — headings, code blocks, tables, task lists, links, images, and more — using native Avalonia controls with a fully customisable theme.

Documentation: kryptos-fr.github.io/MarkView.Avalonia · Try it in your browser: demo

Installation

dotnet add package MarkView.Avalonia

The package targets .NET 10 and Avalonia 12.

Quick start

Include the theme in App.axaml, after Avalonia's own theme. It holds the viewer's template, which makes the document scroll:

<Application.Styles>
  <FluentTheme />
  <StyleInclude Source="avares://MarkView.Avalonia/Themes/MarkdownTheme.axaml" />
</Application.Styles>

Then put a MarkdownViewer in a window, and give it a string or a file:

<Window xmlns="https://github.com/avaloniaui"
        xmlns:mv="using:MarkView.Avalonia">
  <mv:MarkdownViewer Markdown="# Hello, MarkView!" />
  <!-- or Source="avares://MyApp/Docs/readme.md" -->
</Window>

Stream a language model's answer as it arrives:

viewer.Markdown = "";
using var session = viewer.BeginStreaming();
foreach (var token in tokens)
    session.Append(token);

See Getting started for the next steps.

Features

  • GitHub-flavoured Markdown out of the box: tables, task lists, alerts, footnotes, <details> and the HTML subset that READMEs use, plus Markdig's opt-in syntax. Markdown syntax
  • Built for AI chat: streaming that re-renders only the end of the document and closes unfinished syntax, foldable thinking blocks, and a compact chat preset. Chat and AI answers
  • Code blocks with a copy button, language label, line numbers, wrapping and TextMate syntax highlighting, or your own control for any fence language. Code blocks
  • Images and diagrams: sizing, a zoomable lightbox, saving, an image cache, SVG and Mermaid diagrams, all in .NET. Images and diagrams
  • Math: $…$ and $$…$$ LaTeX formulas. Math
  • Themes: GitHub, Chat and Docs presets, light and dark switching live, and every colour and size a resource you can redefine. Themes and presets
  • Selection, copy and find across the whole document, with copy as Markdown and as HTML. Selection and copy · Find in document
  • Navigation: heading anchors, a table of contents, foldable headings and interactive task lists. Displaying documents
  • Accessible: keyboard navigation, screen reader roles, WCAG AA colours, a high-contrast palette and right-to-left text. Accessibility
  • Lazy rendering: images, formulas, diagrams and code colours are built as they come near the visible area. Lazy rendering
  • Extensible: renderers, image loaders and code highlighters are extension points. Custom extensions

Packages

All five packages are released together under the same version.

Package Adds Enable with
MarkView.Avalonia The MarkdownViewer control and its theme
MarkView.Avalonia.SyntaxHighlighting TextMate syntax highlighting of code blocks UseTextMateHighlighting()
MarkView.Avalonia.Svg SVG images UseSvg()
MarkView.Avalonia.Mermaid Mermaid diagrams, rendered in .NET UseMermaid()
MarkView.Avalonia.Math LaTeX math UseMath()

Enable an extension on one viewer (viewer.UseMermaid()), or on every viewer of the application at startup (MarkdownViewerDefaults.Extensions.AddMermaid()). See Choosing packages.

Versioning

Versions read 12.MAJOR.MINOR: 12 is the Avalonia version, the second number changes with breaking changes, and the third with features and fixes. To receive only compatible updates, use a floating version such as 12.4.*. See Versioning and, when upgrading from 12.3, Upgrading to 12.4.

Contributing

Issues and pull requests are welcome. The demo app shows every feature, and CLAUDE.md describes how to build and test the repository and how the code is organised.

License

MIT © Nicolas Musset

Releases

Used by

Contributors

Languages