Skip to content

Extract main content ​

ReverseMarkdown.Readability gets the main content of a web page: the article, without navigation, ads, sidebars, cookie banners and other page furniture, as clean Markdown, together with the page's title, author, publication date and other metadata. It works like Firefox Reader View (Readability) and Defuddle, written from scratch on AngleSharp and ReverseMarkdown.

Early version

ReverseMarkdown.Readability is an early version (0.x). The API may change before 1.0, and extraction results improve between versions.

Install ​

It is a separate package that builds on ReverseMarkdown:

bash
dotnet add package ReverseMarkdown.Readability

Quick start ​

ExtractMainContent is an extension method on Converter, so the converter's flavor and options decide how the Markdown is written. Given the HTML of a blog post with a navigation bar, a share bar, a sidebar and a footer:

csharp
var converter = new Converter(new Config { Flavor = Config.MarkdownFlavor.GitHub });

MainContent article = converter.ExtractMainContent(html, new ExtractOptions
{
    BaseUrl = new Uri("https://blog.example.com/posts/caching"), // resolves relative links
});

var markdown = article.Markdown;
// Caching is the cheapest performance win most applications never fully use. Done well, it cuts latency and makes traffic spikes boring.
//
// ## Cache-aside
//
// The application checks the cache first, and on a miss it reads from the [database](https://blog.example.com/glossary/database) and writes the result back.
snippet source | anchor

Only the article remains. The page title is returned separately (see below), so the heading that repeats it is dropped from the content.

Links and emphasis always come out as Markdown, even in the GitHub and CommonMark flavors, whose default for ordinary conversion is to keep inline tags as HTML.

Fetching a page ​

ExtractMainContent takes the page's HTML rather than a URL. Getting the HTML is a separate job with many valid answers (a plain HTTP request, a headless browser for pages that render with JavaScript, a crawler, a proxy service, a cache or an archive), so it stays yours to choose. It also keeps extraction free of network calls: synchronous, deterministic and safe to run on untrusted input.

With HttpClient, pass the page's URL as BaseUrl so its relative links and images resolve:

csharp
var url = "https://blog.example.com/posts/caching";
var html = await http.GetStringAsync(url);

var article = new Converter().ExtractMainContent(html, new ExtractOptions
{
    BaseUrl = new Uri(url), // the page's own URL, to resolve its relative links and images
});
snippet source | anchor

For going through a proxy, identifying your client, and pages that render with JavaScript, see Converting a web page, which applies here too.

Metadata ​

The page's metadata comes back alongside the content. Each field is read from the most specific source available: OpenGraph and article tags, JSON-LD (schema.org), standard meta tags, and finally the page itself (a byline or date written next to the headline, the nearest <time>).

csharp
var article = converter.ExtractMainContent(html);

var summary = $"{article.Title} | {article.Author} | {article.SiteName} | " +
              $"{article.PublishedDate:yyyy-MM-dd} | {article.Language} | {article.WordCount} words";
// Five Caching Strategies | Priya Raman | The Example Blog | 2026-03-14 | en | 42 words
snippet source | anchor
PropertyWhat it holds
Markdown, Html, TextThe main content as Markdown, as cleaned HTML, and as plain text
DocumentThe parsed Markdown DOM, to reshape or chunk before rendering
TitleThe headline, without a trailing site name ("- Wikipedia", "| Site")
Author, Description, SiteNameByline, summary and publisher
Published, PublishedDateThe date as written, and parsed
Language, Image, Favicon, Url, DomainPage language, lead image, icon, canonical URL and host
WordCountWords in the main content
SchemaOrg, MetaTagsThe raw JSON-LD blocks and meta tags, for anything else you need
Source, DiagnosticsHow the content was chosen, and why (see Diagnostics)

Flavors that write front matter (Pandoc and MultiMarkdown) include the title, author, date and description in it:

csharp
// Flavors that write front matter (Pandoc, MultiMarkdown) get the page's metadata.
var converter = new Converter(new Config { Flavor = Config.MarkdownFlavor.Pandoc });

var markdown = converter.ExtractMainContent(html).Markdown;
// ---
// title: Five Caching Strategies
// author: Priya Raman
// date: 2026-03-14T09:30:00Z
// description: A practical tour of five caching strategies.
// ---
//
// Caching is the cheapest performance win most applications never fully use. Done well, it cuts latency and makes traffic spikes boring.
// ...
snippet source | anchor

Steering the extraction ​

The heuristics fit most article pages. When a page comes out wrong, three options take over.

ContentSelector names the content element outright, skipping scoring:

csharp
// The escape hatch for a page the heuristics get wrong: name the content element.
var article = converter.ExtractMainContent(html, new ExtractOptions { ContentSelector = "aside.sidebar" });

var result = $"{article.Source}: {article.Markdown}";
// ContentSelector: ### Popular
//
// [Post A](/a) [Post B](/b)
snippet source | anchor

RemoveSelectors removes more, and KeepSelectors protects elements from every removal pass:

csharp
var options = new ExtractOptions();
options.RemoveSelectors.Add("h2");        // also remove these
options.KeepSelectors.Add(".share-bar");  // never remove these

var markdown = converter.ExtractMainContent(html, options).Markdown;
// [Share](/share/x) [Post](/share/y)
//
// Caching is the cheapest performance win most applications never fully use. Done well, it cuts latency and makes traffic spikes boring.
//
// The application checks the cache first, and on a miss it reads from the [database](/glossary/database) and writes the result back.
snippet source | anchor

Each removal pass can also be switched off on its own: RemoveHiddenElements, RemoveExactSelectors, RemovePartialSelectors and RemoveLowScoring, as well as RemoveTitleHeading and RemoveImages.

Diagnostics ​

Turn on Diagnostics to see which element was chosen as the content and every element removed, with the pass that removed it and why. Attach this to a bug report and the cause is usually obvious.

csharp
var article = converter.ExtractMainContent(html, new ExtractOptions { Diagnostics = true });

var report = article.Diagnostics!.ContentElement + "\n" +
             string.Join("\n", article.Diagnostics.Removals.Select(r => r.ToString()));
// html > body > article
// [partial] div.share-bar (share): Share Post
// [title] h1 (repeats the page title): Five Caching Strategies
snippet source | anchor

Diagnostics.Attempts also lists the runs made: when too little text survives, extraction runs again with gentler settings and keeps the result only if it recovers substantially more.

How it works ​

  1. Standardize. Math, footnotes and code blocks from common generators are rewritten into shapes the converter reads, using the core standardizing steps: StandardizeMath, StandardizeFootnotes and StandardizeCodeBlocks.
  2. Choose the container. Well-known content containers (article, main, .entry-content, classes named for an article body) are scored on their prose; without one, paragraphs vote for their parents. Listing pages and page-builder layouts that split an article across sections are recognized.
  3. Clean inside it. Separate passes remove hidden elements, navigation and other clutter by role and class, blocks that score as boilerplate (link lists, "subscribe" boxes), and author blocks and datelines before the article.
  4. Normalize. Lazy-loaded images get their real source, relative URLs become absolute, card links and heading permalinks are tidied, and whitespace is collapsed as a browser renders it.
  5. Convert with the converter's flavor and options. Its own Config.Preprocess steps run on the extracted content.

Coming from Readability or Defuddle ​

The result's fields line up with both:

ReverseMarkdown.ReadabilityReadability (Firefox Reader View)Defuddle
MarkdowncontentMarkdown
Htmlcontentcontent
TexttextContent
Titletitletitle
Authorbylineauthor
Descriptionexcerptdescription
SiteNamesiteNamesite
PublishedpublishedTimepublished
Languagelanglanguage
Image, Favicon, Domainimage, favicon, domain
WordCountlength (characters)wordCount
SchemaOrg, MetaTagsschemaOrgData, metaTags
Diagnosticsdebug
Document (Markdown DOM)

It runs in .NET with no JavaScript runtime or browser, works on HTML you already have, and is trimming and Native AOT ready.

Quality ​

Extraction is tested against all 250 pages of Defuddle's own test corpus, comparing the words of the extracted content and the metadata with Defuddle's expected output. Each page's score is kept as a baseline, and any change that lowers one fails the build. The current mean content F1 is 96%.

Limitations ​

  • It works on HTML you pass in; it does not fetch pages.
  • Site-specific layouts (social media posts, issue trackers, comment threads) are extracted with the general rules, which fit them less well than articles.
  • The boilerplate phrases it recognizes ("subscribe to our", "all rights reserved") are English.

Released under the MIT License.