Meziantou.Framework.HtmlToMarkdown 2.0.12

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

Meziantou.Framework.HtmlToMarkdown

A .NET library to convert HTML fragments to Markdown.

Usage

Basic conversion

HtmlToMarkdown and its options are in the Meziantou.Framework namespace.

var html = "<h1>Title</h1><p>Hello <strong>world</strong></p>";
var markdown = HtmlToMarkdown.Convert(html);
Assert.Equal("""
    # Title

    Hello **world**
    """, markdown);

Configure conversion options

var html = "<h1>Title</h1><p>Line 1<br>Line 2</p>";

var markdown = HtmlToMarkdown.Convert(html, new HtmlToMarkdownOptions
{
    HeadingStyle = HeadingStyle.Setext,
    EmphasisMarker = EmphasisMarker.Underscore,
    CodeBlockStyle = CodeBlockStyle.Fenced,
    CodeBlockFenceCharacter = '~',
    UnorderedListMarker = '*',
    ThematicBreak = "***",
    LineBreakStyle = LineBreakStyle.Backslash,
    UseSimplePunctuation = true,
    EmojiShortcodeMode = EmojiShortcodeMode.GitHub,
    UnknownElementHandling = UnknownElementHandling.StripKeepContent,
});
Assert.Equal("""
    Title
    =====

    Line 1\
    Line 2
    """, markdown);

Replace SmartyPants punctuation with simple ASCII

You can opt in to convert smart punctuation in regular text nodes:

var markdown = HtmlToMarkdown.Convert(
    "<p>“Hello” ‘Hello’ — – … « »</p>",
    new HtmlToMarkdownOptions { UseSimplePunctuation = true });
Assert.Equal("""
    "Hello" 'Hello' \-\-\- \-\- ... \<\< \>\>
    """, markdown);

Emoji shortcode replacement

var markdown = HtmlToMarkdown.Convert("<p>I ❤️ Markdown</p>", new HtmlToMarkdownOptions
{
    EmojiShortcodeMode = EmojiShortcodeMode.GitHub,
});
Assert.Equal("I :heart: Markdown", markdown);

var unicodeMarkdown = HtmlToMarkdown.Convert("<p>I ❤️ Markdown</p>", new HtmlToMarkdownOptions
{
    EmojiShortcodeMode = EmojiShortcodeMode.Unicode,
});
Assert.Equal("I :red_heart: Markdown", unicodeMarkdown);

Supported HTML elements

The converter supports common Markdown-related elements, including:

  • Headings (h1-h6)
  • Paragraphs and line breaks (p, br)
  • Emphasis (strong, b, em, i, del, s, strike)
  • Links and images (a, img)
  • Lists (ul, ol, li) including task list checkboxes (input type="checkbox")
  • Blockquotes (blockquote)
  • Code (code, pre) with fenced or indented blocks
  • Tables (table, thead, tbody, tfoot, tr, th, td) with alignment support
  • Definition lists (dl, dt, dd)

script, style, and noscript elements are always stripped, including when they appear inside an element that is passed through as raw HTML.

Unknown elements are handled using UnknownElementHandling:

  • PassThrough (default): keep raw HTML
  • Strip: remove the element and its content
  • StripKeepContent: remove the element but keep converted child content

This library is a converter, not an HTML sanitizer. With PassThrough, an unknown element is emitted as raw HTML with its attributes intact, so event handlers such as onclick and onerror and URLs such as javascript: survive the conversion. If you convert untrusted HTML and render the resulting Markdown with a renderer that allows raw HTML, run a sanitizer over the input or the output, or use Strip or StripKeepContent.

Product Compatible and additional computed target framework versions.
.NET 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.  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
2.0.12 20 10/21/2026
2.0.11 63 10/16/2026
2.0.10 130 10/5/2026
2.0.9 110 9/27/2026
2.0.8 129 9/11/2026
2.0.7 122 9/9/2026
2.0.6 128 9/6/2026
2.0.5 121 9/3/2026
2.0.4 136 8/23/2026
2.0.3 132 8/16/2026
2.0.2 113 8/16/2026
2.0.1 136 8/9/2026
2.0.0 303 7/5/2026
1.0.6 153 6/28/2026
1.0.5 146 6/13/2026
1.0.4 138 5/31/2026
1.0.3 179 5/23/2026
1.0.2 400 4/12/2026
1.0.1 145 4/8/2026
1.0.0 167 4/4/2026