Skip to content

Make Mime\BodyRenderer markdown conversion configurable #46295

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mhujer opened this issue May 9, 2022 · 2 comments · Fixed by #47201
Closed

Make Mime\BodyRenderer markdown conversion configurable #46295

mhujer opened this issue May 9, 2022 · 2 comments · Fixed by #47201

Comments

@mhujer
Copy link
Contributor

mhujer commented May 9, 2022

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.

@fabpot
Copy link
Member

fabpot commented Aug 5, 2022

See #47201

@fabpot fabpot closed this as completed Aug 7, 2022
fabpot added a commit that referenced this issue Aug 7, 2022
…n (fabpot)

This PR was squashed before being merged into the 6.2 branch.

Discussion
----------

[Mime] Add a way to control the HTML to text conversion

| Q             | A
| ------------- | ---
| Branch?       | 6.2
| Bug fix?      | no
| New feature?  | yes <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       | Fix #46295 <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead -->
| License       | MIT
| Doc PR        |

Commits
-------

f3789b3 [Mime] Add a way to control the HTML to text conversion
@mhujer
Copy link
Contributor Author

mhujer commented Aug 13, 2022

@fabpot awesome, thanks! 🌞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants