$ show thephpleague/html-to-markdown
This is a PHP library that converts HTML strings to Markdown. It parses HTML into a DOMDocument, then recursively traverses the DOM tree, converting each node to its Markdown equivalent using a registry of converter classes. The architecture is clean: an `HtmlConverter` orchestrates the process, an `Environment` manages configuration and converter registration, and individual converter classes handle specific HTML elements (headers, links, lists, tables, etc.). The library supports extensive configuration options including stripping tags, preserving comments, customizing emphasis styles, and enabling table conversion. It provides both a programmatic API and a CLI binary. The code is well-structured with strict typing, interfaces, and comprehensive test coverage. It demonstrates solid software engineering practices and is actively maintained.
The LLM identified 2 files worth highlighting for reuse:
A clean, self-contained configuration class that manages key-value options with merge, replace, set, and get methods. It includes deprecation warning logic for specific options. This class is isolated (no internal imports) and could be extracted into any PHP project needing a simple configuration object with merge semantics and deprecation handling.
A small utility class that safely coerces mixed values to strings, handling strings, booleans, floats, integers, null, and objects with __toString(). It throws an InvalidArgumentException for uncoercable values. This is a reusable pattern for input sanitization in PHP applications.