public function convert($content) { $content = $this->markdown->transform($content); if (!is_null($this->smartypants)) { $content = $this->smartypants->transform($content); } $content = trim($content); return $content; }
/** * Converts markdown into HTML * * @param string $content * @param array $config . Options to configure MarkdownExtra and smarty * - markdown: array for MarkdownExtra configuration parameters * - smarty: array for SmartyPantsTypographer configuration parameters * - custom: array for Custom configuration parameters * @param int $smartyMode the SmartyPantsTypographer processing mode * * @return string * @throws InvalidConfigException if module not set */ public static function convert($content, $config = [], $smartyMode = self::SMARTYPANTS_ATTR_LONG_EM_DASH_SHORT_EN) { $module = Config::initModule(Module::classname()); $output = $content; if (strlen($output) > 0) { $mdConfig = empty($config['markdown']) ? [] : $config['markdown']; $output = static::process($content, $mdConfig); if ($module->smartyPants) { $smConfig = empty($config['smarty']) ? [] : $config['smarty']; $smarty = new SmartyPants($smartyMode); foreach ($smConfig as $name => $value) { $smarty->{$name} = $value; } $output = $smarty->transform($output); $cuConfig = empty($config['custom']) ? $module->customConversion : $config['custom']; $output = static::customProcess($output, $cuConfig); } if (is_bool($module->smarty) && $module->smarty || (is_string($module->smarty) || is_callable($module->smarty)) && call_user_func($module->smarty, $module)) { $smarty = new \Smarty(); if ($module->smartyYiiApp) { $smarty->assign('app', Yii::$app); } if ($module->smartyYiiParams) { $smarty->config_vars = Yii::$app->params; } $output = $smarty->fetch('string:' . $output, null, null, $module->smartyParams); } } return $output; }
public function it_should_throw_an_exception_on_an_exception(SmartyPants $smartyPants) { $smartyPants->transform('bar')->willThrow('Exception'); $this->shouldThrow('TheWilkyBarKid\\TextFilter\\Exception\\TextFilterFailedException')->during('filter', array('foo')); }
protected function doFilter($text) { return $this->smartyPants->transform($text); }