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:
dotnet add package ReverseMarkdown.ReadabilityQuick 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:
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.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:
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
});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>).
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| Property | What it holds |
|---|---|
Markdown, Html, Text | The main content as Markdown, as cleaned HTML, and as plain text |
Document | The parsed Markdown DOM, to reshape or chunk before rendering |
Title | The headline, without a trailing site name ("- Wikipedia", "| Site") |
Author, Description, SiteName | Byline, summary and publisher |
Published, PublishedDate | The date as written, and parsed |
Language, Image, Favicon, Url, Domain | Page language, lead image, icon, canonical URL and host |
WordCount | Words in the main content |
SchemaOrg, MetaTags | The raw JSON-LD blocks and meta tags, for anything else you need |
Source, Diagnostics | How 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:
// 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.
// ...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:
// 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)RemoveSelectors removes more, and KeepSelectors protects elements from every removal pass:
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.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.
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 StrategiesDiagnostics.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
- Standardize. Math, footnotes and code blocks from common generators are rewritten into shapes the converter reads, using the core standardizing steps:
StandardizeMath,StandardizeFootnotesandStandardizeCodeBlocks. - 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. - 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.
- 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.
- Convert with the converter's flavor and options. Its own
Config.Preprocesssteps run on the extracted content.
Coming from Readability or Defuddle
The result's fields line up with both:
| ReverseMarkdown.Readability | Readability (Firefox Reader View) | Defuddle |
|---|---|---|
Markdown | contentMarkdown | |
Html | content | content |
Text | textContent | |
Title | title | title |
Author | byline | author |
Description | excerpt | description |
SiteName | siteName | site |
Published | publishedTime | published |
Language | lang | language |
Image, Favicon, Domain | image, favicon, domain | |
WordCount | length (characters) | wordCount |
SchemaOrg, MetaTags | schemaOrgData, metaTags | |
Diagnostics | debug | |
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.
