composer require league/html-to-markdown
dom, xml, libxml) are enabled.use League\HTMLToMarkdown\HtmlConverter;
$converter = new HtmlConverter();
$markdown = $converter->convert('<h1>Hello World</h1>');
echo $markdown; // => "# Hello World"
First use case: convert rich-text HTML content (e.g., from a CMS or user input) into clean Markdown for storage, editing, or export (e.g., to plain-text email).
HTMLPurifier and use strip_tags/remove_nodes options:
$converter = new HtmlConverter([
'strip_tags' => true,
'remove_nodes' => 'script iframe object',
]);
TableConverter for table support):
$converter->getEnvironment()->addConverter(new MyCustomConverter());
$converter = new HtmlConverter([
'header_style' => 'atx',
'italic_style' => '*',
'bold_style' => '**',
'hard_break' => true, // GitHub-style line breaks
]);
preserve_comments to retain CMS-specific comments (e.g., <!-- {title} -->) for round-trip editing workflows.* and _ in text nodes by default (v4.0.1+), but still may mangle math or code blocks—test with edge cases.Converter\TableConverter (and custom handling for nested lists—see To-Do list in README).convert() in libxml_use_internal_errors(true) + libxml_get_errors() if pre-parsing is needed.div is treated as block-level (v3.0.0+); newlines appear around div content—configure line-break behavior via hard_break and test with <div><p>...</p></div>.strip_placeholder_links to remove empty links (e.g., <a href="#">), and use_autolinks to control link syntax ([text](url) vs <url>).How can I help you explore Laravel packages today?