Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Make Mime\BodyRenderer markdown conversion configurable #46295

Closed
@mhujer

Description

@mhujer

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:

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions