Fuju.Markdown 0.1.0-preview.1

This is a prerelease version of Fuju.Markdown.
dotnet add package Fuju.Markdown --version 0.1.0-preview.1
                    
NuGet\Install-Package Fuju.Markdown -Version 0.1.0-preview.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Fuju.Markdown" Version="0.1.0-preview.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Fuju.Markdown" Version="0.1.0-preview.1" />
                    
Directory.Packages.props
<PackageReference Include="Fuju.Markdown" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Fuju.Markdown --version 0.1.0-preview.1
                    
#r "nuget: Fuju.Markdown, 0.1.0-preview.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Fuju.Markdown@0.1.0-preview.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Fuju.Markdown&version=0.1.0-preview.1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Fuju.Markdown&version=0.1.0-preview.1&prerelease
                    
Install as a Cake Tool

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.FadeAndRise or 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 than maximumLag (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 Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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