nickcernis/html-to-markdown
Converts HTML to Markdown for PHP 7.2+, letting you edit existing HTML content as Markdown, store HTML while editing in Markdown, or turn HTML email into plain text. Install via Composer.
composer require league/html-to-markdown answer to "we need HTML → Markdown." Building an in-house converter with regex or bespoke DOM walking is a multi-week sink with a long tail of edge cases (whitespace between inline elements, placeholder links, <pre> blocks). MIT-licensed, no cost, no vendor negotiation — the decision is essentially "do we need this capability at all," not "can we afford it."strip_tags, remove_nodes, preserve_comments, and strip_placeholder_links tuned per legacy source to avoid dragging along editor cruft (<span style="...">, <div> layout wrappers, tracking pixels).league/commonmark for the reverse direction and treat one format as source of truth.text/plain alternative part is expected.Adopt when:
xml, libxml, dom extensions are present (watch slim/Alpine/CentOS-based containers where php-xml is stripped out — a common "works locally, fatal in prod" trap).strip_tags/remove_nodes at the boundary. Default behavior preserves <script>, <iframe>, <span>, <div> — so sanitization is a hard prerequisite, not a nice-to-have.getEnvironment()->addConverter() covers custom elements; TableConverter opt-in covers GFM tables; header_style, bold_style, italic_style, hard_break, use_autolinks cover output-house-style differences.Look elsewhere when:
turndown is the equivalent and would avoid a PHP↔Node hop.To executives: This is a mature, MIT-licensed, zero-cost component from The PHP League that removes a build-vs-buy question entirely. It unlocks three roadmap items cheaply — legacy content migration, customer-facing Markdown export, and AI-ready content ingestion — without new vendor contracts, licensing fees, or lock-in. Because it's MIT and small-surface, it's replaceable: we wrap it behind our own interface so switching costs stay low.
To engineering: One Composer dependency, PHP 7.2+, standard dom/xml extensions. Small API: instantiate HtmlConverter, call convert(), tune via config options; extend via custom converters on the Environment. No service dependency, deterministic output, trivially testable. Integration plan: a Laravel service provider + published config file for house defaults (strip_tags, header_style, use_autolinks, hard_break), an adapter interface around it, a sanitization step (HTML Purifier) upstream of any user-supplied HTML, queued jobs for bulk migration, and a golden-file test suite built from our actual content corpus to catch fidelity regressions early.
Shared risk to state up front: conversion is lossy and sanitization is mandatory — we scope it for structured content, not pixel-perfect reproduction. Known gaps (nested lists, lists in blockquotes, Markdown flavors) get validated against a real content sample in week one, before we commit the roadmap item.
How can I help you explore Laravel packages today?