Viae.Fluid.Markdown 0.1.5

dotnet add package Viae.Fluid.Markdown --version 0.1.5
                    
NuGet\Install-Package Viae.Fluid.Markdown -Version 0.1.5
                    
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="Viae.Fluid.Markdown" Version="0.1.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Viae.Fluid.Markdown" Version="0.1.5" />
                    
Directory.Packages.props
<PackageReference Include="Viae.Fluid.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 Viae.Fluid.Markdown --version 0.1.5
                    
#r "nuget: Viae.Fluid.Markdown, 0.1.5"
                    
#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 Viae.Fluid.Markdown@0.1.5
                    
#: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=Viae.Fluid.Markdown&version=0.1.5
                    
Install as a Cake Addin
#tool nuget:?package=Viae.Fluid.Markdown&version=0.1.5
                    
Install as a Cake Tool

Viae.Fluid.Markdown

A .NET library that provides Markdown rendering support for Fluid template engine, with special support for ASP.NET MVC applications.

License: MIT .NET

Features

  • πŸš€ Easy Integration - Simple setup with Fluid templates
  • πŸ“ GitHub Flavored Markdown - Full support via Markdig's advanced extensions
  • 🎨 MVC Support - Special adapter for ASP.NET MVC to prevent double-encoding
  • βš™οΈ Customizable - Configure Markdig pipeline extensions as needed
  • πŸ§ͺ Well Tested - Comprehensive test coverage with 60+ unit tests
  • πŸ“– Fully Documented - Complete XML documentation for IntelliSense

Supported Markdown Features

With the default configuration, this library supports:

  • Basic Markdown: Bold, italic, headings, links, images, code blocks
  • Tables: Pipe tables and grid tables
  • Task Lists: - [ ] and - [x] checkboxes
  • Strikethrough: ~~text~~
  • Auto-identifiers: Automatic heading IDs
  • Footnotes: [^1] style footnotes
  • Definition Lists: Term and definition syntax
  • Abbreviations: Automatic abbreviation expansion
  • And more via Markdig's advanced extensions

Installation

dotnet add package Viae.Fluid.Markdown

Quick Start

Basic Usage (Non-MVC)

using Viae.Fluid.Markdown;

// Create the filter and template options
var (filter, options) = FluidMarkdownCoreRegistration.CreateCore();

// Create a Fluid template context
var context = new TemplateContext(options);
context.SetValue("content", "**Hello** from _Markdown_!");

// Parse and render the template
var parser = new FluidParser();
if (parser.TryParse("{{ content | markdown }}", out var template, out var error))
{
    var output = await template.RenderAsync(context);
    Console.WriteLine(output);
    // Output: <p><strong>Hello</strong> from <em>Markdown</em>!</p>
}

ASP.NET MVC Usage

For MVC applications, use the MarkdownMvcAdapter to prevent HTML double-encoding:

using Viae.Fluid.Markdown;

// In your Startup.cs or Program.cs
public void ConfigureServices(IServiceCollection services)
{
    services.AddSingleton(sp =>
    {
        var (coreFilter, _) = FluidMarkdownCoreRegistration.CreateCore();
        var mvcAdapter = new MarkdownMvcAdapter(coreFilter);
        var options = new TemplateOptions();
        mvcAdapter.Register(options);
        return options;
    });
}

Then in your Razor views with Fluid:

@* The markdown filter will render HTML without double-encoding *@
@await RenderAsync("{{ post.content | markdown }}")

Custom Configuration

Customize the Markdig pipeline to enable specific extensions:

using Viae.Fluid.Markdown;
using Markdig;

var customOptions = new MarkdownFilterOptions
{
    ConfigurePipeline = builder => builder
        .UseAdvancedExtensions()      // GitHub Flavored Markdown
        .UseEmphasisExtras()           // Extra emphasis features
        .UseGridTables()               // Grid-style tables
        .UsePipeTables()               // Pipe-style tables
        .UseTaskLists()                // Task list checkboxes
        .UseAutoIdentifiers()          // Auto heading IDs
};

var (filter, templateOptions) = FluidMarkdownCoreRegistration.CreateCore(customOptions);

API Overview

Core Classes

IMarkdownRenderer

Interface for Markdown rendering implementations.

public interface IMarkdownRenderer
{
    string ToHtml(string markdown);
}
MarkdigMarkdownRenderer

Markdig-based implementation of IMarkdownRenderer.

var pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build();
var renderer = new MarkdigMarkdownRenderer(pipeline);
var html = renderer.ToHtml("**bold text**");
MarkdownFilter

Fluid filter for Markdown rendering (returns plain strings).

var filter = new MarkdownFilter(renderer);
var options = new TemplateOptions();
filter.Register(options);
// Registers filters: "markdown" and "markdownify"
MarkdownMvcAdapter

MVC-specific adapter that wraps output in HtmlString.

var adapter = new MarkdownMvcAdapter(coreFilter);
var options = new TemplateOptions();
adapter.Register(options);
// Use in MVC views to prevent double-encoding
MarkdownFilterOptions

Configuration options for the Markdown pipeline.

var options = new MarkdownFilterOptions
{
    ConfigurePipeline = builder => builder.UseAdvancedExtensions()
};
FluidMarkdownCoreRegistration

Factory class for easy setup.

var (filter, options) = FluidMarkdownCoreRegistration.CreateCore();

Filter Names

Both filters are registered under two names for compatibility:

  • markdown - Standard filter name
  • markdownify - Jekyll/Liquid compatible alias

Both can be used interchangeably:

{{ content | markdown }}
{{ content | markdownify }}

Architecture

When to Use What

Scenario Use Reason
ASP.NET MVC with Razor MarkdownMvcAdapter Returns HtmlString to prevent double-encoding
Console apps, APIs, tests MarkdownFilter Returns plain strings
Custom rendering logic IMarkdownRenderer Direct access to rendering
Quick setup FluidMarkdownCoreRegistration.CreateCore() Factory method handles all setup

Class Hierarchy

IMarkdownRenderer (interface)
└── MarkdigMarkdownRenderer (Markdig implementation)
    └── MarkdownFilter (Fluid filter, returns string)
        └── MarkdownMvcAdapter (MVC adapter, returns HtmlString)

Examples

Example 1: Blog Post Rendering

var (filter, options) = FluidMarkdownCoreRegistration.CreateCore();
var context = new TemplateContext(options);

var blogPost = @"
# My Blog Post

This is a **markdown** blog post with:

- Bullet points
- *Italic text*
- [Links](https://example.com)

## Code Example

```csharp
Console.WriteLine(""Hello World"");

";

context.SetValue("post", blogPost); var template = FluidTemplate.Parse("{{ post | markdown }}"); var html = await template.RenderAsync(context);


### Example 2: Multiple Markdown Fields

```csharp
var context = new TemplateContext(options);
context.SetValue("title", "# Welcome");
context.SetValue("excerpt", "This is a **short** excerpt.");
context.SetValue("content", "Full article content here...");

var template = FluidTemplate.Parse(@"
<article>
    <header>{{ title | markdown }}</header>
    <aside>{{ excerpt | markdown }}</aside>
    <main>{{ content | markdown }}</main>
</article>
");

var html = await template.RenderAsync(context);

Example 3: Custom Pipeline (Minimal Extensions)

// Create a minimal Markdown renderer with only basic features
var minimalOptions = new MarkdownFilterOptions
{
    ConfigurePipeline = builder => builder
        .UseEmphasisExtras()  // Bold and italic only
        .UsePipeTables()      // Tables only
};

var (filter, options) = FluidMarkdownCoreRegistration.CreateCore(minimalOptions);

Testing

The library includes comprehensive tests (60+ test cases) using MSTest and FluentAssertions:

cd tests/Viae.Fluid.Markdown.Tests
dotnet test

Test coverage includes:

  • All Markdown features (bold, italic, links, tables, etc.)
  • Null and empty string handling
  • Custom pipeline configurations
  • Filter registration
  • MVC adapter HtmlString wrapping

Dependencies

Target Framework

  • .NET Standard 2.0 (compatible with .NET Core 2.0+, .NET Framework 4.6.1+, .NET 5+)

Contributing

This library is part of the Viae project. Contributions are welcome!

License

This project is licensed under the MIT License - see the LICENSE file for details.

Credits

  • Built with Fluid by SΓ©bastien Ros
  • Markdown processing by Markdig by Alexandre Mutel
  • Fluid - .NET Liquid template engine
  • Markdig - Fast, powerful Markdown processor
  • Viae - Parent project

Support

For questions, issues, or feature requests:

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Viae.Fluid.Markdown:

Package Downloads
Viae.Fluid.Markdown.Mvc

MVC view engine extensions for the Viae.Fluid.Markdown filter

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.5 288 10/29/2025
0.1.4-g74ff342 217 10/29/2025
0.1.3-g5a6d330 218 10/29/2025
0.1.2-gb6155a2 214 10/29/2025
0.1.1-g4645b0a 217 10/29/2025
0.0.0-dev.9.g4a5c5df 171 10/29/2025
0.0.0-dev.9 165 10/29/2025
0.0.0-dev.2.g07cad15 166 10/29/2025