Example #1
0
 /**
  * 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 SmartyPantsTypographer($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;
 }
Example #2
0
 /**
  * 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 SmartyPantsTypographer($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);
         }
     }
     return $output;
 }
Example #3
0
 /**
  * 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 = \Yii::$app->getModule('markdown');
     if ($module === null) {
         throw new InvalidConfigException("The module 'markdown' was not found. Ensure you have setup the 'markdown' module in your Yii configuration file.");
     }
     $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 SmartyPantsTypographer($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);
         }
     }
     return $output;
 }