Curated Examples
Parse and format HTML
Use HtmlTinkerX from C# to parse HTML and format markup.
This pattern is useful when a .NET application needs to turn HTML into structured data before saving, comparing, or reporting on it.
It is adapted from the quick-start patterns in the HtmlTinkerX README.
When to use this pattern
- You need HTML table data in a .NET workflow.
- You want consistent formatting before storing or comparing markup.
- You prefer the C# API instead of shelling out to PowerShell.
Example
using HtmlTinkerX;
string html = await File.ReadAllTextAsync("page.html");
var tables = HtmlParser.ParseTablesWithAngleSharp(html);
string formatted = HtmlFormatter.FormatHtml(html);
string minified = HtmlOptimizer.OptimizeHtml(html);
Console.WriteLine($"Tables found: {tables.Count}");
await File.WriteAllTextAsync("page.formatted.html", formatted);
await File.WriteAllTextAsync("page.min.html", minified);
What this demonstrates
- parsing HTML into structured table data
- formatting markup for readable output
- minifying the same document for compact output