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
<PackageReference Include="Meziantou.Framework.HtmlToMarkdown" Version="2.0.12" />
<PackageVersion Include="Meziantou.Framework.HtmlToMarkdown" Version="2.0.12" />
<PackageReference Include="Meziantou.Framework.HtmlToMarkdown" />
paket add Meziantou.Framework.HtmlToMarkdown --version 2.0.12
#r "nuget: Meziantou.Framework.HtmlToMarkdown, 2.0.12"
#:package Meziantou.Framework.HtmlToMarkdown@2.0.12
#addin nuget:?package=Meziantou.Framework.HtmlToMarkdown&version=2.0.12
#tool nuget:?package=Meziantou.Framework.HtmlToMarkdown&version=2.0.12
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 HTMLStrip: remove the element and its contentStripKeepContent: 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 | Versions 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. |
-
net10.0
- Meziantou.Framework.WebPlatform (>= 1.0.1)
-
net11.0
- Meziantou.Framework.WebPlatform (>= 1.0.1)
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 |