kartik\markdown\Markdown::convert PHP Method

convert() public static method

Converts markdown into HTML
public static convert ( string $content, array $config = [], integer $smartyMode = self::SMARTYPANTS_ATTR_LONG_EM_DASH_SHORT_EN ) : string
$content string
$config array . Options to configure MarkdownExtra and smarty - markdown: array for MarkdownExtra configuration parameters - smarty: array for SmartyPantsTypographer configuration parameters - custom: array for Custom configuration parameters
$smartyMode integer the SmartyPantsTypographer processing mode
return string
    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;
    }

Usage Example

Example #1
0
 /**
  * Convert markdown text to HTML for preview
  *
  * @returns JSON encoded HTML output
  */
 public function actionPreview()
 {
     $output = '';
     $module = Yii::$app->controller->module;
     if (isset($_POST['source'])) {
         $output = strlen($_POST['source']) > 0 ? Markdown::convert($_POST['source'], ['custom' => $module->customConversion]) : $_POST['nullMsg'];
     }
     echo Json::encode(HtmlPurifier::process($output));
 }
All Usage Examples Of kartik\markdown\Markdown::convert