$handlers = new HandlerContainer(); $handlers->add('b', function(ShortcodeInterface $s) { return ''.$s->getContent().''; }); $parser = new RegularParser(); $processor = new Processor($handlers, $parser); $text = 'My name is Bold. Text [b]Bold[/b].'; $result = $processor->process($text); // My name is Bold. Text Bold.
$syntax = new Syntax('[[', ']]', '//', '==', '""'); $parser = new RegexParser($syntax); $processor = new Processor($handlers, $parser); $text = 'My name is Bold. Text [[b]]Bold[[//b]].'; $result = $processor->process($text);
final class ShortcodeTwigExtension extends \Twig_Extension { public function getFilters() { return [new \Twig_SimpleFilter('shortcode', [$this, 'processShortcodes'])]; } public function processShortcodes($text) { $handlers = new HandlerContainer(); $handlers->add('b', new WrapHandler('', '')); $parser = new RegularParser(); $processor = new Processor($handlers, $parser); return $processor->process($text); } }