Soenneker.Extensions.String.Html
4.0.933
Prefix Reserved
dotnet add package Soenneker.Extensions.String.Html --version 4.0.933
NuGet\Install-Package Soenneker.Extensions.String.Html -Version 4.0.933
<PackageReference Include="Soenneker.Extensions.String.Html" Version="4.0.933" />
<PackageVersion Include="Soenneker.Extensions.String.Html" Version="4.0.933" />
<PackageReference Include="Soenneker.Extensions.String.Html" />
paket add Soenneker.Extensions.String.Html --version 4.0.933
#r "nuget: Soenneker.Extensions.String.Html, 4.0.933"
#:package Soenneker.Extensions.String.Html@4.0.933
#addin nuget:?package=Soenneker.Extensions.String.Html&version=4.0.933
#tool nuget:?package=Soenneker.Extensions.String.Html&version=4.0.933
Soenneker.Extensions.String.Html
Parse HTML strings to format or minify markup, extract text, convert common elements to Markdown, and find elements.
Installation
dotnet add package Soenneker.Extensions.String.Html
Convert HTML to Markdown
using Soenneker.Extensions.String.Html;
string html = "<h2>Status</h2><p>Build <strong>passed</strong>.</p>";
string? markdown = await html.ToMarkdownFromHtml();
The converter handles paragraphs, headings, emphasis, links, ordered and unordered lists, block quotes, inline code, preformatted blocks, and line breaks. Other elements contribute their child content. Whitespace is normalized, so this is intended for readable Markdown rather than lossless round-tripping.
Link destinations are copied as written. The method is not an HTML sanitizer or a Markdown-security boundary; sanitize untrusted markup and validate links before rendering the result as active content.
Format or minify markup
string? formatted = await html.FormatAsHtml();
string? compact = await html.MinifyHtml();
Both methods parse with AngleSharp and serialize the resulting document. Parsing can repair malformed markup and can add document structure such as html, head, and body; the output is not guaranteed to preserve the input byte-for-byte. Formatting changes layout, while minification uses AngleSharp's compact formatter.
Null and whitespace inputs are returned unchanged. Text that does not pass the package's lightweight HTML sniff is also returned unchanged.
Extract text
string? text = await "<p>Hello <b>world</b></p>".StripTagsFromHtml();
// "Hello world"
StripTagsFromHtml() returns the parsed body element's trimmed TextContent. This removes markup but is not sanitization, and text inside elements such as script or style may still be present. For non-HTML input it returns Trim() of the original text.
Detect content and elements
bool containsMarkup = html.ContainsHtml();
bool hasHeading = await html.HasHtmlElement("h2");
ContainsHtml() is a syntax sniff, not validation. HasHtmlElement() first performs an allocation-free opening-tag check, then parses the document and compares actual element names case-insensitively. It returns false for null/whitespace HTML or tag names.
| 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. |
-
net10.0
- Soenneker.AngleSharp.Parser (>= 4.0.85)
- Soenneker.Extensions.Spans.ReadOnly.Chars.Html (>= 4.0.90)
- Soenneker.Extensions.String (>= 4.0.762)
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 |
|---|---|---|
| 4.0.933 | 0 | 9/16/2026 |
| 4.0.932 | 7 | 9/16/2026 |
| 4.0.931 | 20 | 9/16/2026 |
| 4.0.930 | 44 | 9/16/2026 |
| 4.0.928 | 42 | 9/15/2026 |
| 4.0.927 | 96 | 9/13/2026 |
| 4.0.925 | 84 | 9/13/2026 |
| 4.0.924 | 81 | 9/13/2026 |
| 4.0.923 | 82 | 9/12/2026 |
| 4.0.922 | 78 | 9/12/2026 |
| 4.0.921 | 83 | 9/12/2026 |
| 4.0.920 | 84 | 9/12/2026 |
| 4.0.919 | 81 | 9/12/2026 |
| 4.0.917 | 78 | 9/12/2026 |
| 4.0.915 | 88 | 9/12/2026 |
| 4.0.914 | 89 | 9/11/2026 |
| 4.0.913 | 97 | 9/9/2026 |
| 4.0.912 | 90 | 9/9/2026 |
| 4.0.911 | 87 | 9/9/2026 |
| 4.0.910 | 106 | 9/8/2026 |
Updated Multiple NuGet packages