nickcernis/html-to-markdown
Convert HTML into clean, readable Markdown in PHP. Parse tags and structure into Markdown output with configurable rules, custom converters, and strong defaults—handy for scraping, email content, CMS migrations, and turning rich text into Markdown for storage or editing.
HtmlToMarkdown::convert($html)).MarkdownConverter) for cleaner syntax.php artisan markdown:convert resources/views/**/*.html).@markdown($html)) for template-based conversions.ContentUpdated event → convert HTML to Markdown before saving).| Risk Area | Mitigation Strategy |
|---|---|
| Inconsistent Output | Test edge cases (e.g., malformed HTML, nested tags, custom attributes) with a suite of HTML snippets. Use HtmlToMarkdown::getConfig() to tweak rules (e.g., preserve specific tags). |
| Performance Overhead | Benchmark with production-scale HTML payloads. Consider caching converted Markdown (e.g., Redis) if conversions are frequent. |
| Dependency Conflicts | Check for PHP version compatibility (package supports PHP 7.4+). Use Laravel’s composer.json constraints to avoid version skew. |
| Maintenance Burden | Monitor for upstream updates (last release: 2023-07-12). Fork if critical fixes are needed. |
| Security Vulnerabilities | Sanitize HTML input before conversion (e.g., with htmlpurifier) to prevent XSS in Markdown output. |
<code> blocks with syntax highlighting (e.g., <code class="language-js">) be handled?commonmark/commonmark).HtmlToMarkdown::setConfig()) be required?composer require nickcernis/html-to-markdown.$this->app->singleton(HtmlToMarkdownConverter::class, function ($app) {
return new HtmlToMarkdown();
});
saved model events).fallback_to_html flag in configurations to revert to raw HTML if conversion fails.<font>, <center>), configure custom rules.str_get_html() (from simplehtmldom) or HTMLPurifier to preprocess input if untrusted.markdownlint if strict formatting is required.<img> tags but strip <script>).app/Services/MarkdownConverter.php).config('markdown.enabled')).HtmlToMarkdown::setConfig() for future maintainers.config/markdown.php).michelf/php-markdown if critical).dd($converter->getConfig()) to inspect active rules.<figure> tags).queue:work) for large datasets.parallel:for or pest for testing.| Failure Scenario | Detection | Mitigation |
|---|---|---|
| Malformed HTML Input | Conversion errors/exceptions | Pre-sanitize with HTMLPurifier or |
How can I help you explore Laravel packages today?