-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Closed
Labels
Description
Description
Symfony can already automatically generate a text version of an e-mail in \Symfony\Bridge\Twig\Mime\BodyRenderer using league/html-to-markdown (see https://symfony.com/doc/current/mailer.html#text-content)
But there is no way to configure the conversion options (e.g. we would like to remove the img tags as well). The instantiation is hardcoded in the constructor and the BodyRenderer itself is marked as final:
symfony/src/Symfony/Bridge/Twig/Mime/BodyRenderer.php
Lines 23 to 37 in 1ac98fc
| final class BodyRenderer implements BodyRendererInterface | |
| { | |
| private $twig; | |
| private array $context; | |
| private $converter; | |
| public function __construct(Environment $twig, array $context = []) | |
| { | |
| $this->twig = $twig; | |
| $this->context = $context; | |
| if (class_exists(HtmlConverter::class)) { | |
| $this->converter = new HtmlConverter([ | |
| 'hard_break' => true, | |
| 'strip_tags' => true, | |
| 'remove_nodes' => 'head style', |
(The only way I see as an extension option is to copy the
BodyRenderer to MyBodyRenderer, modify it and try to keep up with the changes in Symfony)
I suggest that the League\HTMLToMarkdown\HtmlConverter is wrapped behind some HtmlToTextConverter interface, so it would be possible to either replace it with other convertor or at least configure it differently.