Skip to content

Markdown

Markdown replaces the HTML in Content with Markdown.

var result = DefuddleParser.ParseHtml(
html,
new DefuddleOptions { Url = "https://example.com/blog/tide-pools", Markdown = true }
);
Console.WriteLine(result.Content); // Markdown

snippet source | anchor

SeparateMarkdown keeps the HTML in Content and adds ContentMarkdown.

var both = DefuddleParser.ParseHtml(
html,
new DefuddleOptions { Url = "https://example.com/blog/tide-pools", SeparateMarkdown = true }
);
Console.WriteLine(both.Content); // HTML
Console.WriteLine(both.ContentMarkdown); // Markdown

snippet source | anchor

Both options apply to ParseAsync, ParseHtml, and ParseHtmlAsync. The synchronous Parse method returns HTML.

MarkdownConverter.CreateMarkdownContent runs the conversion on its own. As upstream, it takes the URL of the page but does not use it, so relative links stay as written. When the conversion fails, for example on HTML nested more than 1024 levels deep, the result starts with “Partial conversion completed with errors” and holds the original HTML.

var markdown = MarkdownConverter.CreateMarkdownContent(
"<h2>Tide pools</h2><p>Look at the <em>shaded</em> side first.</p>",
"https://example.com/blog/tide-pools"
);
Console.WriteLine(markdown);

snippet source | anchor

Before the conversion, Defuddle standardizes elements so that different sites produce consistent output. Set Standardize to false to skip it.

  • The first H1 or H2 heading is removed if it matches the title.
  • H1s are converted to H2s.
  • Anchor links in headings are removed, and the headings become plain headings.

Line numbers and syntax highlighting are removed. The language is kept as a data attribute and a class, and becomes the language of the fenced block in Markdown.

Inline references and footnotes are converted to one format, which becomes [^1] references and definitions in Markdown.

Math elements, including MathJax and KaTeX, are converted to a standard math element, and become $...$ and $$...$$ in Markdown. When a page has MathML without a LaTeX source, the LaTeX is derived from the MathML, with a port of mathml-to-latex. The other direction is not ported: upstream’s full bundle builds MathML from LaTeX with temml, while this package keeps LaTeX-only math as LaTeX text.

Callouts and alerts become blockquotes with a data-callout attribute. In Markdown they are Obsidian-style callouts:

> [!info] Info
> This is an informational callout.

Supported sources are GitHub Markdown alerts, Obsidian callouts, callout asides, and Bootstrap alerts.

MIT · Copyright 2025 Steph Ango (@kepano) · unofficial community port of defuddle