- How do I install HTML to Markdown for Laravel with Composer?
- Install the current Packagist package with composer require league/html-to-markdown; the README lists Nick Cernis as original author and league as the maintained package. The library requires PHP 7.2 or newer. In Laravel, use HtmlConverter directly or bind it in a service provider. Pin the constraint to ^5.1.4 so Composer cannot resolve a version below the security fix.
- Does league/html-to-markdown support Laravel 9, 10, and 11?
- The package is framework-agnostic and requires PHP 7.2+, so Laravel versions running on a supported PHP release can use it. Laravel 9, 10, and 11 require PHP 8+, which satisfies the package requirement. Confirm your application's PHP and Composer constraints before installing. Use ^5.1.4 as the minimum version for untrusted HTML.
- What is the minimum secure version of league/html-to-markdown?
- Version 5.1.4 is the minimum viable version for untrusted input because it removes a quadratic-time worst case that made adversarial HTML a CPU-exhaustion vector. The issue affected list items, pre, code, table rows and cells, and preserved HTML tags on all PHP versions, plus other elements on PHP 8.0 and below. Pin ^5.1.4 and audit for transitive or shadow installs pinned to older majors. Add input size caps and conversion timeouts as defense in depth.
- Can I use league/html-to-markdown to convert user-submitted HTML safely?
- The package converts HTML to Markdown but does not sanitize the input for you. Sanitize HTML first, for example with HTMLPurifier, to reduce XSS risk in the resulting Markdown. Sanitization alone does not mitigate algorithmic complexity, so run 5.1.4+ with input limits and timeouts. Review generated links and output before displaying or storing it.
- How do I configure the HTML to Markdown converter in Laravel?
- Create an HtmlConverter instance and use its getConfig method to tweak conversion rules, such as preserving specific tags. You can wrap the converter in a Laravel service provider or facade for cleaner dependency injection. Put any project-specific options in a config file or singleton binding. The 5.1.4 security release does not change Markdown output, so existing configuration needs no revalidation.
- How do I test HTML to Markdown conversion in a Laravel app?
- Write unit or feature tests with representative HTML snippets, including malformed HTML, nested tags, custom attributes, tables, and lists. Assert the expected Markdown output and add tests for your configured rules. Include adversarial input tests with size caps and timeout expectations. Laravel's testing tools can call your service or facade and compare the returned Markdown.
- What are the main limitations of HTML to Markdown conversion?
- Complex document layouts such as tables and nested lists may need post-processing if precision is non-negotiable. Real-time collaborative editing with bidirectional Markdown and HTML sync is not a good fit. Performance-critical pipelines should benchmark conversion latency and consider caching converted Markdown. The package is PHP-based, so test with production-scale payloads before adoption.
- Can I convert HTML email to plain text Markdown with this package?
- Yes, the README lists converting HTML email to plain text email as a typical use case. Create an HtmlConverter and pass the email HTML to its convert method. Email HTML is often messy, so test with real templates and sanitize untrusted content. Review the Markdown output for links and formatting before sending or storing it.
- How does league/html-to-markdown compare with alternatives like Markdownify or Pandoc?
- The provided context does not directly benchmark alternatives, so compare them on PHP and Laravel fit, maintenance activity, security posture, and output fidelity. This package integrates easily into Laravel through a service provider, facade, Artisan command, or Blade directive. Benchmark with your own HTML and test edge cases before choosing. For heavy document conversion, evaluate specialist tools alongside this library.
- Is league/html-to-markdown actively maintained?
- The earlier note that the package was unmaintained post-2023 is no longer accurate; the project is actively shipping security fixes, including 5.1.4. Track upstream advisories rather than planning a fork by default. Pin ^5.1.4 and audit dependencies for older versions. The 5.1.4 release is a dependency bump with unchanged Markdown output.