m2nj.MarkdownConverter 1.0.0

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

m2nj.MarkdownConverter

m2nj.MarkdownConverter is a dependency-free .NET 8 library for converting HTML to Markdown and Markdown to HTML. It supports common content such as links, lists, code, blockquotes, and simple tables. This release is version 1.0.0.

Install

dotnet add package m2nj.MarkdownConverter --version 1.0.0

HTML to Markdown

Call MarkdownConverter.ConvertToMarkdown(string) with an HTML fragment or a complete HTML page. For a full document, the converter extracts the <body> content; the doctype, <head>, title, and metadata are not included in the Markdown result.

using m2nj.MarkdownConverter;

const string html = """
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Product list</title>
    </head>
    <body>
        <h1>Fruit</h1>
        <p>Fresh fruit, including a <a href="https://example.com">supplier link</a>.</p>

        <h2>Available fruit</h2>
        <ul>
            <li>Apples</li>
            <li>Pears</li>
        </ul>

        <h2>Shopping steps</h2>
        <ol>
            <li>Choose fruit</li>
            <li>Place an order</li>
        </ol>

        <table>
            <thead>
                <tr><th>Fruit</th><th>Quantity</th></tr>
            </thead>
            <tbody>
                <tr><td>Apples</td><td>3</td></tr>
                <tr><td>Pears</td><td>12</td></tr>
            </tbody>
        </table>
    </body>
    </html>
    """;

string markdown = MarkdownConverter.ConvertToMarkdown(html);
Console.WriteLine(markdown);

The body content converts to Markdown similar to:

# Fruit

Fresh fruit, including a [supplier link](https://example.com).

## Available fruit

- Apples
- Pears

## Shopping steps

1. Choose fruit
2. Place an order

| Fruit | Quantity |
| --- | --- |
| Apples | 3 |
| Pears | 12 |

Simple tables convert to GitHub Flavored Markdown pipe tables. Ordered lists preserve their start value where possible. Links retain their URL and optional title. Unsupported HTML and attributes may be retained as raw HTML rather than silently discarded.

Markdown to HTML

Call MarkdownConverter.ReverseToHtml(string) to convert Markdown to an HTML fragment:

using m2nj.MarkdownConverter;

const string markdown = """
    # Fruit

    Fresh fruit, including a [supplier link](https://example.com).

    - Apples
    - Pears

    | Fruit | Quantity |
    |:------|---------:|
    | Apples | 3 |
    | Pears | 12 |
    """;

string html = MarkdownConverter.ReverseToHtml(markdown);
Console.WriteLine(html);

Use the returned fragment inside an HTML page or pass it to another component for rendering. The method does not create the surrounding <!DOCTYPE html>, <html>, <head>, or <body> elements.

Supported mappings

The converter supports common headings, paragraphs, emphasis, strong emphasis, strikethrough, inline and fenced code, links, images, hard line breaks, thematic breaks, blockquotes, ordered and unordered lists, task-list checkboxes, and simple tables. Table conversion supports rectangular tables with inline cell content; merged cells and complex table layouts are not represented by pipe tables.

The Markdown parser is a small, dependency-free implementation, not a complete CommonMark or GFM parser. The HTML parser handles common well-formed HTML but is not a complete HTML5 parser. Complex or malformed input, deeply nested lists, and uncommon Markdown syntax may not convert as expected. Conversion is not generally lossless: CSS, many attributes, document metadata, and unsupported element semantics do not have standard Markdown equivalents.

Markdown-to-HTML escapes raw HTML rather than passing it through. Link destinations are restricted to http, https, mailto, and ftp schemes; unsupported schemes are not emitted as clickable links. Applications displaying the output should still apply their own HTML sanitization policy when handling untrusted input.

Sample project

The package includes a runnable consumer sample in samples/MarkdownConverter.Sample. It shows a complete HTML page (DOCTYPE, html, head, and body) converted to Markdown, including paragraphs, links, tables, unordered and ordered lists, plus Markdown converted back to HTML.

After unpacking the package, run:

dotnet run --project samples/MarkdownConverter.Sample/MarkdownConverter.Sample.csproj

The sample source is also available in Samples/MarkdownConverter.Sample/Program.cs in the source repository.

Maintainer

Created and maintained by m2nj. Package ownership and copyright: m2nj, 2026. Use and redistribution are governed by the custom license in License.txt; it is not an OSI-approved open-source license. Review the terms before adopting or redistributing the package.

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

    • No dependencies.

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
1.0.0 133 10/24/2026

Initial release. Convert common HTML fragments and full HTML page bodies to Markdown, and Markdown to HTML.