-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[twig-extra-bundle] markdown_to_html: Passing configuration to League\CommonMark\CommonMarkConverter #3725
Comments
Same problem. How to pass configuration to Converter or Environment? Extensions work with configuration from Environment too. We currently cannot set up CommonMark and Extensions at all. |
I've found a way to pass configuration to CommonMark Environment. Basically you need to override Put the following in services:
twig.markdown.league_common_mark_converter_factory:
class: App\Twig\LeagueCommonMarkConverterFactory
arguments:
- !tagged_iterator twig.markdown.league_extension Then grab You can now add your own configuration like this : <?php
namespace App\Twig;
use League\CommonMark\CommonMarkConverter;
use League\CommonMark\Extension\ExtensionInterface;
/**
* @internal
*/
final class LeagueCommonMarkConverterFactory
{
private $extensions;
/**
* @param ExtensionInterface[] $extensions
*/
public function __construct(iterable $extensions)
{
$this->extensions = $extensions;
}
public function __invoke(): CommonMarkConverter
{
$config = [
'renderer' => [
'allow_unsafe_links' => false,
],
'table' => [
'wrap' => [
'enabled' => true,
'tag' => 'div',
'attributes' => ['class' => 'table-responsive'],
],
],
];
$converter = new CommonMarkConverter($config);
foreach ($this->extensions as $extension) {
$converter->getEnvironment()->addExtension($extension);
}
return $converter;
}
} |
Looks like in the meantime (actually quite some time ago), someone opened a pull request that tries to address the same issue: #3737 |
#3737 has been merged now. |
I'm using the twig extra bundle's
markdown_to_html
filter on Symfony 6.1 with League/CommonMark as the markdown parser library.The library has a few configuration options that can be passed to the
CommonMarkConverter
constructor and cannot be adjusted after theCommonMarkConverter
object has been constructed. See https://commonmark.thephpleague.com/2.3/configuration/Currently however, the
LeagueCommonMarkConverterFactory
class seems to call theCommonMarkConverter
without any parameters:Twig/extra/twig-extra-bundle/LeagueCommonMarkConverterFactory.php
Line 34 in 3cefeba
Is there therefore currently no simple way to pass configuration to the library or have I missed something obvious?
I have been able to bypass the factory class by manually declaring the
CommonMarkConverter
constructor arguments in theservices.yaml
file as such:However as this bypasses the Factory class I then lose the capability of including any CommonMark extensions.
The text was updated successfully, but these errors were encountered: