mirror of
https://github.com/KnpLabs/KnpMarkdownBundle.git
synced 2024-05-04 14:43:17 +02:00
3c541b580b
Refactored way how parsers are initialized, and allow to select parser while rendering Interface `MarkdownParserInterface` method name was changed from `#transform($text)` to `#transformMarkdown($text)`
38 lines
1.3 KiB
PHP
38 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Knp\Bundle\MarkdownBundle\DependencyInjection\Compiler;
|
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
|
use Symfony\Component\DependencyInjection\Reference;
|
|
|
|
class ParsersCompilerPass implements CompilerPassInterface
|
|
{
|
|
public function process(ContainerBuilder $container)
|
|
{
|
|
if (!$container->hasDefinition('templating.helper.markdown')) {
|
|
return;
|
|
}
|
|
|
|
if (!$container->hasDefinition('markdown.parser')) {
|
|
return;
|
|
}
|
|
|
|
$defaultParserTag = $container->getDefinition('markdown.parser')->getTag('markdown.parser');
|
|
|
|
$definition = $container->getDefinition('templating.helper.markdown');
|
|
|
|
foreach ($container->findTaggedServiceIds('markdown.parser') as $id => $tags) {
|
|
if ($defaultParserTag == $id) {
|
|
$definition->addMethodCall('addParser', array(new Reference($id), 'default'));
|
|
continue;
|
|
}
|
|
|
|
foreach ($tags as $attributes) {
|
|
$alias = empty($attributes['alias']) ? $id : $attributes['alias'];
|
|
$definition->addMethodCall('addParser', array(new Reference($id), $alias));
|
|
}
|
|
}
|
|
}
|
|
}
|