Fuju.Markdown
0.1.0-preview.1
dotnet add package Fuju.Markdown --version 0.1.0-preview.1
NuGet\Install-Package Fuju.Markdown -Version 0.1.0-preview.1
<PackageReference Include="Fuju.Markdown" Version="0.1.0-preview.1" />
<PackageVersion Include="Fuju.Markdown" Version="0.1.0-preview.1" />
<PackageReference Include="Fuju.Markdown" />
paket add Fuju.Markdown --version 0.1.0-preview.1
#r "nuget: Fuju.Markdown, 0.1.0-preview.1"
#:package Fuju.Markdown@0.1.0-preview.1
#addin nuget:?package=Fuju.Markdown&version=0.1.0-preview.1&prerelease
#tool nuget:?package=Fuju.Markdown&version=0.1.0-preview.1&prerelease
Fuju.Markdown
Markdown for Fuju: a view that renders GitHub Flavored Markdown in Fluent's style. The text is parsed incrementally, so a document that changes (an editor's preview, an AI's answer arriving piece by piece) is parsed again only from the block a change reaches, and the blocks before it keep their nodes. The whole document is selectable and copyable.
It follows CommonMark 0.31.2 and GitHub's extensions: tables, task lists, strikethrough and autolinks.
Install
dotnet add package Fuju.Markdown --prerelease
The package needs Fuju and Fuju.Fluent, which an application built with Fuju.Sdk already references.
Showing Markdown
using static Fuju.Markdown.MarkdownUI;
Node readme = Markdown("# Hello\n\nSome **bold** text and a [link](https://example.com).");
Markdown(Func<string>) follows a tracked function instead, for text that changes, such as the preview beside an
editor:
[State] public partial string Source { get; set; } = "";
protected override Node Build() =>
Row(
TextArea(() => Source, v => Source = v).Grow(),
ScrollView(Markdown(() => Source)).Grow());
Streaming an answer
Markdown(text, isStreaming) shows text that is still arriving. While isStreaming returns true, constructs open at
the end of the text (an unclosed **, a link whose destination is still arriving) are shown as they will most likely
end, and a last line that could still become something else (a lone - or #, a fence, a table's header row) waits
for its line break; when it returns false, the text is shown exactly as GitHub Flavored Markdown says.
[State] public partial string Answer { get; set; } = "";
[State] public partial bool Answering { get; set; }
protected override Node Build() =>
Markdown(() => Answer, () => Answering)
.Reveal(TextEffects.FadeAndRise(Motion.Milliseconds(350, Easing.FastOutSlowIn), 8, TimeSpan.FromMilliseconds(40), TextEffectUnit.Word))
.Pacing(MarkdownPacing.Smooth(200));
private async Task Ask(string question, CancellationToken cancellationToken)
{
Answer = "";
Answering = true;
await foreach (string piece in client.StreamAsync(question, cancellationToken))
Answer += piece;
Answering = false;
}
Reveal(TextEffect): how new text appears while streaming. Each new stretch of a paragraph, heading, table cell or code block plays the effect (TextEffects.Fade,TextEffects.FadeAndRiseor one of your own, per grapheme cluster, word or line); other new blocks fade in. Text that is there when the view opens, or that changes while not streaming, is never revealed. With reduced motion the text appears at once.Pacing(MarkdownPacing): how streamed text is let out onto the screen.MarkdownPacing.Immediate(the default) shows it as it arrives;MarkdownPacing.Smooth(charactersPerSecond, maximumLag)lets it out at a steady pace, so that bursts do not jump, but never more thanmaximumLag(half a second by default) behind what has arrived.
Setting up the view
Each method returns the view, and is called before the view is shown:
| Method | What it does |
|---|---|
OnLinkClick(Action<string>) |
Called with a link's destination when the user clicks it or presses Enter on it, in place of opening it. Without it, a link opens in the system's program for its address (UriLauncher.Open: http, https and mailto only). |
OnTaskToggle(Action<ListItem, bool>) |
Lets the user check and uncheck task list items (- [ ]). It is called with the item and its new state; the view does not change the text, so change it yourself. ListItem.TaskMarkerStart is the index of the item's [ in the text. Without it, the check boxes are shown but cannot be changed. |
Images(Func<string, string, Node?>) |
Makes the node for an image, given its address and description, for example Image(ImageSource.FromUri(new Uri(url))).Width(320). Returning null shows the description. Without it, every image is shown as its description. |
Render<TBlock>(Func<TBlock, Node?>) |
Shows blocks of one kind (CodeBlock, Table, Paragraph...) with a node of your own, such as a code block with syntax highlighting; returning null shows the block as the view would. |
CopyLabel(string) |
The label of a code block's copy button; "Copy" by default. |
Reveal(TextEffect), Pacing(MarkdownPacing) |
See Streaming an answer. |
Toggling a task in the text:
Markdown(() => Source).OnTaskToggle((item, isChecked) =>
{
int at = item.TaskMarkerStart + 1;
Source = string.Concat(Source.AsSpan(0, at), isChecked ? "x" : " ", Source.AsSpan(at + 1));
});
Selecting and copying
The text can be selected across the whole document, from one block into the next, and the view joins a selection area
around it where there is one (.SelectionArea()). A copy puts three formats on the clipboard: the text as shown
(text/plain), the HTML of the blocks the selection touches (text/html, as cmark-gfm renders it), and their Markdown
source (text/markdown). A code block's copy button copies its code.
What is not supported
- Math: LaTeX (
$...$,$$...$$) is shown as written. Support is planned. - Raw HTML: HTML blocks and inline HTML are shown as text, as written; only
<br>breaks a line. - Images load only through
Images(...); the view makes no network or file access of its own. - Syntax highlighting: code blocks are shown in one colour; use
Render<CodeBlock>(...)for your own.
Licensed under the Apache License 2.0.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- Fuju (>= 0.1.0-preview.3)
- Fuju.Fluent (>= 0.1.0-preview.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.1.0-preview.1 | 36 | 12/2/2026 |