$ show Taritsyn/WebMarkupMin
WebMarkupMin is a comprehensive .NET library for minifying HTML, XHTML, XML, CSS, and JavaScript markup to optimize web application performance. It provides a core minification engine with parsers and output writers, plus extensive integration with ASP.NET (both classic .NET Framework and .NET Core/5+) through middleware, HTTP modules, MVC action filters, and WebForms base page classes. The library supports multiple minifier backends: built-in Crockford JS and Kristensen CSS minifiers, plus wrappers for Microsoft Ajax Minifier, YUI Compressor, and NUglify. It also includes compression support for GZip, Deflate, and Brotli. The architecture is modular, with clear interfaces (IMarkupMinifier, ICssMinifier, IJsMinifier, ICompressor) and factory patterns, enabling pluggable backends and easy extension. Configuration is exposed via strongly-typed settings classes. The codebase is well-tested with hundreds of unit tests covering edge cases in markup parsing, whitespace handling, attribute optimization, and framework-specific features (Angular, Knockout, Blazor). The repository is primarily a library (not a standalone application), and its samples demonstrate integration with various ASP.NET versions.
The LLM identified 3 files worth highlighting for reuse:
A self-contained utility class that provides efficient forward/backward navigation through source code strings with line and column tracking. It supports common operations like finding next non-whitespace character, skipping ahead, and peeking. This component is highly reusable for any text processing tool that needs to report positions (line/column) without external dependencies. It demonstrates clean API design and is easily extractable.
Implements IUrlMatcher to match URLs against a wildcard pattern (supports '*' and '?' placeholders). It converts the wildcard pattern into a compiled regex internally but does not require the caller to know regex syntax. The class is fully self-contained with no internal dependencies, making it directly reusable in any project needing URL path matching with a simple syntax. Similar reusable matchers exist for exact and regex patterns in the same folder.
A custom output writer extending MarkupMinificationOutputWriterBase that accumulates minified HTML output with advanced trimming capabilities: TrimEnd (removes trailing whitespace/newlines), CollapseLastWhitespace (collapses last whitespace to a single space), and RemoveLastEndTag (removes last written end tag for optional end tag handling). It uses a StringBuilder internally and provides efficient buffer-level control. This pattern is reusable for any streaming text transformation where post-processing of written segments is required.