- How do I integrate **bicpi/html-converter** into a Laravel project?
- Register the package as a service provider in `config/app.php` and optionally create a facade for cleaner syntax. Use the `ChainConverter` to prioritize backends like Lynx for best results. Example: `$converter = new ChainConverter(); $converter->addConverter(new LynxConverter());`
- Which Laravel versions does this package support?
- The package is PHP 7.4+ compatible and works with Laravel 8.x, 9.x, and 10.x. No Laravel-specific dependencies mean it’s framework-agnostic but fully interoperable with modern Laravel apps.
- Can I use this for converting HTML emails in Laravel Mailables?
- Yes. Hook into Laravel’s `Mailable` class to generate plain-text versions of HTML emails. Example: `$this->with(['text_version' => HtmlConverter::convert($this->htmlContent)])` in your `build()` method.
- What’s the best converter backend for preserving links in emails?
- Use the `LynxConverter`—it mimics Lynx’s text browser output, preserving links as references. Requires the `lynx` system package (`apt-get install lynx` on Ubuntu). Fall back to `SimpleConverter` if Lynx isn’t available.
- How do I handle malformed HTML (e.g., unclosed tags) in production?
- Preprocess HTML with `filter_var($html, FILTER_VALIDATE_HTML)` or use Laravel’s `Str::of($html)->markdown()` for basic sanitization. For edge cases, chain `LynxConverter` with `SimpleConverter` as a fallback.
- Is this package suitable for high-volume API responses (e.g., 10K+ requests/day)?
- Yes, but benchmark with large payloads. The `SimpleConverter` is fastest (uses `strip_tags()`), while `LynxConverter` adds minimal overhead. Cache converted results if reprocessing is common.
- Can I test this package with PHPUnit in Laravel?
- Absolutely. Mock HTML inputs (e.g., `<h1>Test</h1>`) and assert outputs with `assertEquals()`. Example: `$converter = new SimpleConverter(); $this->assertEquals('Test', $converter->convert('<h1>Test</h1>'));`
- What are the alternatives to **bicpi/html-converter** for Laravel?
- For lightweight needs, this package is ideal. For advanced HTML parsing (CSS/JS), consider `symfony/dom` or `masterminds/html5`. For email-specific needs, Laravel’s built-in `Mailable` text templates may suffice.
- How do I convert HTML fields in Eloquent models before saving?
- Use a model observer or accessor. Example: `public function getTextContentAttribute() { return HtmlConverter::convert($this->html_content); }` or in an observer: `$model->text_content = HtmlConverter::convert($model->html_content);`.
- Does this package support converting tables or complex layouts?
- Basic support exists, but results vary by backend. `LynxConverter` handles tables decently, while `SimpleConverter` flattens them. For precise control, preprocess HTML with DOMDocument or use `masterminds/html5` for advanced layouts.