Pmad.Markitdown 0.0.2

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

Pmad.Markitdown

A lightweight, pure managed .NET library to convert documents (HTML, PDF, DOCX, and plain text) into clean Markdown with zero external or Docker dependencies.

Targeting .NET 10 and .NET 8.


Features

  • Pure .NET (Managed): Runs fully in-process. No Python, no Docker, no Node.js required.
  • HTML to Markdown:
    • Full DOM parsing and sanitization powered by AngleSharp.
    • High-fidelity Markdown generation powered by ReverseMarkdown.
    • Automatically extracts <title> as a top-level # heading if not already present.
    • Strips noisy boilerplate elements (<script>, <style>, <nav>, <svg>, <footer>).
  • PDF to Markdown:
    • Extracted via PdfPig (Apache-2.0).
    • Robust text and structure extraction handling font CMaps, subsetted fonts, and reading order layout analysis.
  • Word (DOCX) to Markdown:
    • Semantic document extraction via Mammoth piped into clean Markdown.
  • Plain Text / Code / JSON:
    • Line ending and encoding normalization.
  • Extensible Architecture:
    • Implements a pluggable converter strategy (IFormatConverter) allowing custom formats to be easily registered.

Installation

Install via NuGet:

dotnet add package Pmad.Markitdown

Or via Package Manager Console:

Install-Package Pmad.Markitdown

Quick Start

1. Basic Conversion

using Pmad.Markitdown;

IMarkitdown markitdown = new Markitdown();

// Convert a local file (.html, .pdf, .docx, .txt, etc.)
string markdown = await markitdown.ConvertFileAsync("document.pdf");
Console.WriteLine(markdown);

2. Convert from a Stream

Pass a Stream alongside a file extension or MIME media type:

using var stream = File.OpenRead("report.docx");

// By extension
string mdFromDocx = await markitdown.ConvertAsync(stream, ".docx");

// Or by MIME type
string mdFromPdf = await markitdown.ConvertAsync(pdfStream, "application/pdf");

3. Convert Raw HTML or Text

string html = "<html><head><title>My Article</title></head><body><p>Hello <strong>World</strong>!</p></body></html>";

string markdown = await markitdown.ConvertTextAsync(html, "text/html");
// Output:
// # My Article
//
// Hello **World**!

Configuration Options

Customize conversion behavior using MarkitdownOptions:

var options = new MarkitdownOptions
{
    // Extract document title as an H1 heading if missing from the body (default: true)
    IncludeTitle = true,

    // Strip scripts, styles, navigation, and footer tags from HTML (default: true)
    CleanHtml = true,

    // Resolve relative links and images into absolute URLs (default: null)
    BaseUrl = new Uri("https://example.com/")
};

string markdown = await markitdown.ConvertFileAsync("article.html", options);

You can also pass default options directly to the Markitdown constructor:

var markitdown = new Markitdown(new MarkitdownOptions
{
    IncludeTitle = false
});

Dependency Injection

Register Pmad.Markitdown in your IServiceCollection:

// Program.cs
builder.Services.AddSingleton<IMarkitdown, Markitdown>();

Inject and use in your services:

public class DocumentProcessor
{
    private readonly IMarkitdown _markitdown;

    public DocumentProcessor(IMarkitdown markitdown)
    {
        _markitdown = markitdown;
    }

    public async Task ProcessAsync(Stream stream, string contentType)
    {
        string markdown = await _markitdown.ConvertAsync(stream, contentType);
        // ...
    }
}

Adding Custom Format Converters

You can extend Pmad.Markitdown with your own custom converters by implementing IFormatConverter:

using Pmad.Markitdown.Converters;

public class CustomCsvConverter : IFormatConverter
{
    public bool CanHandle(string? extension, string? mediaType) =>
        string.Equals(extension, ".csv", StringComparison.OrdinalIgnoreCase) ||
        string.Equals(mediaType, "text/csv", StringComparison.OrdinalIgnoreCase);

    public async Task<string> ConvertAsync(Stream stream, MarkitdownOptions options, CancellationToken cancellationToken)
    {
        using var reader = new StreamReader(stream);
        var csv = await reader.ReadToEndAsync(cancellationToken);
        // Convert CSV to Markdown table...
        return "| Header 1 | Header 2 |\n| --- | --- |\n";
    }
}

// Register custom converters:
var converters = new IFormatConverter[]
{
    new CustomCsvConverter(),
    new HtmlToMarkdownConverter(),
    new PdfToMarkdownConverter()
};

var markitdown = new Markitdown(converters);

Supported Formats

Format Extensions MIME Types Engine
HTML .html, .htm, .xhtml text/html, application/xhtml+xml AngleSharp + ReverseMarkdown
PDF .pdf application/pdf PdfPig
Word .docx application/vnd.openxmlformats-officedocument.wordprocessingml.document Mammoth
Plain Text .txt, .text text/plain Managed
Markdown .md, .markdown text/markdown Managed
JSON .json application/json Managed

License

This project is licensed under the MIT License.

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 is compatible.  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.

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.0.2 105 10/25/2026
0.0.1 95 10/22/2026