English | 繁體中文
Markdown viewers for .NET that show the same text the same way on different front ends, and a Markdown source editor for Avalonia. One package parses the text and applies the safety policy; a viewer package for each UI framework renders the result.
| Package | For |
|---|---|
Polhem.Markdown |
Parsing (with Markdig) and the safety policy shared by the viewers |
Polhem.Markdown.Avalonia |
A viewer control and a source editor control for Avalonia |
Polhem.Markdown.Blazor |
A viewer component for Blazor, rendering semantic HTML styled with CSS variables |
The packages are published on nuget.org; the changes of each release are in the CHANGELOG. They are at 0.x: a minor version may still change the API, and the CHANGELOG says when it does.
Both viewers render the same model, so a reply looks alike in a browser and in a desktop or mobile app. The picture shows the start of the sample text in each.
-
GitHub Flavored Markdown: headings, emphasis,
strikethrough, lists and task lists, quotes, tables with column alignment, footnotes, emoji shortcodes such as:wave:, and GitHub alerts (> [!NOTE],> [!TIP],> [!IMPORTANT],> [!WARNING],> [!CAUTION]). YAML front matter is hidden, and a link to a heading of the same text scrolls to it. -
Code blocks show their language and a copy button, and code in common languages such as C#, JSON, SQL, XML, JavaScript and Python is highlighted. Light and dark themes are both supported:
-
Mermaid diagrams: flowcharts and sequence diagrams are drawn by the viewer itself, with no script. A diagram of another type shows as code.
-
Math written as on GitHub,
$…$in a line and$$…$$or a```mathblock on its own, also without a script. Dollar signs in prose, such as prices, stay text. -
The HTML README files use, such as
<div align="center">,<details>,<sup>,<kbd>and<img>, becomes part of the text; any other HTML is dropped, and scripts with their content. -
Safety: only links with an allowed scheme (by default
http,httpsandmailto) can be clicked, and only images from an allowed scheme (by defaulthttps) load. A host can add a scheme of its own and decide what such a link does. -
Streaming: the text can be set again as a reply arrives; the gallery's replay shows it.
Each viewer's README lists what it supports in detail, and how to set its colors: Avalonia, Blazor.
MarkdownEditor in Polhem.Markdown.Avalonia edits Markdown as source, with a live preview in MarkdownViewer beside
it, not as rich text.
- Colours the source the way the viewer reads it: markers, headings, emphasis, inline code, links and their addresses, raw HTML and formulas, and fenced code with the viewer's highlighting.
- Formats and list keys:
ApplyFormattoggles bold, italic, strikethrough, inline code, links, headings, lists, task lists, quotes and code blocks, with Ctrl or Cmd and B, I, K or E for the inline ones. Enter continues a list, and Tab and Shift+Tab move an item in and out. - Keeps in step with the viewer: the editor reports the source at the top of its view and scrolls to a source offset; the viewer maps source offsets to positions and back, and a command-click asks for the source of what was clicked. The gallery wires the two together.
- Works under any theme with no styles from the host, and its links cannot be opened from the source: the viewer checks their scheme.
The Avalonia README has the details. There is no Blazor editor yet.
samples/MarkdownGallery shows every kind of node on a Semi theme, light or dark, with a replay that types the text in
chunks as a streamed reply arrives. Its Edit switch puts the editor beside the viewer, scrolling together.
dotnet run --project samples/MarkdownGallery.Desktop
dotnet run --project samples/MarkdownGallery.BlazorThe Blazor gallery shows the same text, so the two viewers can be compared side by side.
The iOS head is not in the solution, because it needs the iOS workload. On a Mac, build and start it on a simulator:
dotnet build samples/MarkdownGallery.iOS -c Release -p:RuntimeIdentifier=iossimulator-arm64
dotnet build samples/MarkdownGallery.iOS -c Release -t:Run -p:RuntimeIdentifier=iossimulator-arm64 -p:_DeviceName=":v2:udid=<simulator UDID>"If the build says the iOS workload needs another Xcode version, point DEVELOPER_DIR at that version for the build.
dotnet build Polhem.Markdown.slnx --configuration Release
dotnet test Polhem.Markdown.slnx --configuration Release --no-build




