Polhem.Markdown: A Markdown Viewer and Editor for Avalonia and Blazor A developer released Polhem.Markdown, an MIT-licensed set of .NET Markdown packages that provide matching MarkdownViewer and MarkdownEditor components for both Avalonia and Blazor, built on Markdig and a shared document model. The core package parses Markdown and applies a single security policy, while the viewers render GitHub Flavored Markdown, Mermaid diagrams, math and syntax highlighting entirely in C#, so the Blazor side loads no third-party scripts or CDN assets. Tests verify that every document-model node renders on both front ends, and that Markdig types stay out of the public API. The same text renders the same way in both front ends, with no extra syntax packages to install This post is based on version 0.3.1. The packages are still 0.x, so a minor release may still change the API; any change will be noted in the CHANGELOG https://github.com/polhem-dev/polhem-markdown/blob/main/CHANGELOG.md . Polhem.Markdown is a set of Markdown packages for .NET. It provides two components each for Avalonia and Blazor: MarkdownViewer : displays Markdown, with support for GitHub Flavored Markdown, syntax highlighting, Mermaid diagrams and math. MarkdownEditor : edits the Markdown source, with a My project has Avalonia desktop and mobile apps as well as a Blazor web front end, and both need to display Markdown replies from AI. My first plan was to pick an existing package for each side. But two packages parse on their own and decide on their own how things look, so the same text ends up looking different in the two front ends, and the security rules have to be written twice. So I decided to build my own set. The source is on GitHub https://github.com/polhem-dev/polhem-markdown under the MIT license. It does not depend on the Polhem framework https://github.com/polhem-dev/polhem , so other projects can use it directly. | Package | Contents | |---|---| | Polhem.Markdown https://www.nuget.org/packages/Polhem.Markdown | Parses with Markdig https://github.com/xoofx/markdig , converts the result into its own document model, and applies the security policy | | Polhem.Markdown.Avalonia https://www.nuget.org/packages/Polhem.Markdown.Avalonia | The MarkdownViewer and MarkdownEditor controls for Avalonia | | Polhem.Markdown.Blazor https://www.nuget.org/packages/Polhem.Markdown.Blazor | The MarkdownViewer and MarkdownEditor components for Blazor | An application references only the package for its own front end, and Polhem.Markdown comes along with it: dotnet add package Polhem.Markdown.Avalonia dotnet add package Polhem.Markdown.Blazor The target framework is net10.0 , and the Avalonia side uses Avalonia 12. In November 2026, I looked through the open-source Markdown packages for Avalonia and Blazor on NuGet and read the source of a few of the more downloaded ones. There are plenty of viewers that support a single front end. Here is what this set deliberately does differently. I did not find an open-source package that supports both Avalonia and Blazor. With one package on each side, the parser, the supported syntax and the handling of unrecognized syntax may all differ. The core package of Polhem.Markdown converts Markdig's syntax tree into its own model, and both viewers draw only that model. Tests guard this too: each side takes the same sample text, which covers every node, and checks that every kind of node is drawn including the shapes of Mermaid diagrams and the parts of math formulas . If the model gains a node and one viewer does not keep up, its tests fail, so new syntax cannot show up on only one side. Also, Markdig's types do not appear in the public API, which is also checked by a test, so switching parsers later would not affect consumers. A common approach is for the main package to handle only the basic syntax, with Mermaid, math and syntax highlighting in separate extension packages. On the Blazor side, scripts such as mermaid.js and highlight.js are usually loaded in the browser. This set puts all of it in the main package. The viewers lay out and draw Mermaid flowcharts and sequence diagrams themselves. Math is parsed once in the core; Blazor outputs MathML, which browsers support natively, and Avalonia does its own layout the reasons are in ADR-002 https://github.com/polhem-dev/polhem-markdown/blob/main/maintainers/adr/adr-002-math-one-structure-two-layouts.md . Syntax highlighting is also done in C . So the Blazor viewer does not need to load any third-party scripts, and there is no CDN that might be unreachable. Only browser operations such as scrolling to a heading or copying code go through Blazor's JS interop. What the viewer displays is mostly replies from AI models, and a model's output can be steered by a third party for example, through instructions hidden in a web page it read . So the links, images and HTML in the text have to be treated as untrusted input. A common approach on the Blazor side is to put the HTML produced by Markdig straight into the page. Raw HTML embedded in the Markdown is output as well, and links starting with javascript: can still be clicked. This set puts the rules in the core package, and both viewers apply the same ones: