1. Go to this page and download the library: Download kartik-v/yii2-markdown library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
'modules' => [
'markdown' => [
// the module class
'class' => 'kartik\markdown\Module',
// the controller action route used for markdown editor preview
'previewAction' => '/markdown/parse/preview',
// the list of custom conversion patterns for post processing
'customConversion' => [
'<table>' => '<table class="table table-bordered table-striped">'
],
// whether to use PHP SmartyPantsTypographer to process Markdown output
'smartyPants' => true
]
/* other modules */
];
use kartik\markdown\Markdown;
// default call
echo Markdown::convert($content);
// with custom post processing
echo Markdown::convert($content, ['custom' => [
'<h1>' => '<h1 class="custom-h1">',
'<h2>' => '<h2 class="custom-h2">',
'<p>' => Html::beginTag('p', $options),
]]);
// add this in your view
use kartik\markdown\MarkdownEditor;
// usage with model
echo MarkdownEditor::widget([
'model' => $model,
'attribute' => 'markdown',
]);
// usage without model
echo MarkdownEditor::widget([
'name' => 'markdown',
'value' => $value,
]);
'modules' => [
'markdown' => [
'class' => 'kartik\markdown\Module',
'smarty' => true,
// Smarty class configuration
'smartyParams' => [],
// provide Yii::$app to the Smarty template as variable
'smartyYiiApp' => true,
// provide Yii::$app->params to the Smarty template as config variables
'smartyYiiParams' => true,
],
/* other modules */
];