function transform($text) { $text = str_replace("\n!#", "\n#", $text); $text = str_replace("\n!!#", "\n##", $text); $text = str_replace("\n!!!#", "\n###", $text); $text = parent::transform($text); return $text; }
/** * Markdown Parser functional interface */ function markdown($text) { static $parser; if (!isset($parser)) { $parser = new MarkdownExtraParser(); } return $parser->transform($text); }
/** * Transform * * @param mixed $text * @return void */ public function transform($text) { $text = parent::transform($text); return $text; }
public function getFormattedContent() { $parser = new MarkdownExtraParser(); return $parser->transform($this->contents); }
public function getFilters() { $extension = $this; $routers = $this->routers; $parser = new MarkdownExtraParser(); $translator = $this->translator; return array('markdown' => new \Twig_SimpleFilter('markdown', function ($value) use($parser) { return $parser->transform($value); }), 'trans' => new \Twig_SimpleFilter('trans', function ($value, $context) use($translator) { if (!$context) { $context = array(); } return vsprintf($translator->translate($value), $context); }), 'route' => new \Twig_SimpleFilter('route', function ($value, $presentation = 'normal') use($extension, $routers) { // FIXME: this code is suboptimal and needs refactoring $result = array(); if ($value instanceof Collection) { $value = $value->getAll(); } $singleResult = !is_array($value); $value = !is_array($value) ? array($value) : $value; foreach ($value as $path) { $rule = $routers->match($path); $url = $rule ? ltrim($rule->generate($path), '/') : false; if ($url && $url[0] != '/') { $url = $extension->convertToRootPath($url); } switch ($presentation) { case 'url': // return the first url return $url; case 'class:short': $parts = explode('\\', $path); $path = end($parts); break; } $result[] = $url ? sprintf('<a href="%s">%s</a>', $url, $path) : $path; } return $singleResult ? reset($result) : $result; })); }