The yii2-markdown module provides Markdown Editing and Conversion utilities for Yii Framework 2.0. It implements markdown conversion using PHP Markdown Extra and PHP Smarty Pants Typographer. In addition, you can customize the flavor of Markdown, by including additional custom conversion patterns. The module also includes an enhanced customized Markdown Editor Widget for markdown editing and preview at runtime. This widget is styled using Bootstrap 3.0. View a complete demo.
Not seeing the updated content on this page! Hard refresh your browser to clean cache for this page (e.g. SHIFT-F5 on Windows Chrome)
The yii2-markdown
extension can be installed automatically or manually using one of these options:
Installation via Composer is the recommended and most easy option to install Krajee Yii2 extensions. You can install yii2-markdown
via composer
package manager. Either run:
$ php composer.phar require kartik-v/yii2-markdown "dev-master"
or add:
"kartik-v/yii2-markdown": "dev-master"
to your application's composer.json
file.
You may also manually install the extension to your project (in case your composer install does not work). Just download the source ZIP or TAR ball and extract the extension asset files and folders into your project. You may need to install dependencies manually and also set the namespaces to the extensions in your Yii2 extensions configurations manually.
You must setup the markdown
module by registering it in the modules section of your
Yii Configuration file. View a complete demo.
'modules' = [ /* your other modules */ 'markdown' => [ 'class' => 'kartik\markdown\Module', ] ];
You can setup additional configuration options for the markdown
module:
'modules' = [ 'markdown' => [ // the module class 'class' => 'kartik\markdown\Module', // the controller action route used for markdown editor preview 'previewAction' => '/markdown/parse/preview', // the controller action route used for downloading the markdown exported file 'downloadAction' => '/markdown/parse/download', // 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, // array the the internalization configuration for this module 'i18n' => [ 'class' => 'yii\i18n\PhpMessageSource', 'basePath' => '@markdown/messages', 'forceTranslation' => true ]; ] ];
use kartik\markdown\Markdown; echo Markdown::convert($content);
// add this in your view use kartik\markdown\MarkdownEditor; // usage with Active Form echo $form->field($model, 'markdown')->widget( MarkdownEditor::classname(), ['height' => 300, 'encodeLabels' => false] ); // usage with model echo MarkdownEditor::widget([ 'model' => $model, 'attribute' => 'markdown', ]); // usage without model echo MarkdownEditor::widget([ 'name' => 'markdown', 'value' => $value, ]);
Comments & Discussion
Note
You can now visit the Krajee Webtips Q & A forum for searching OR asking questions OR helping programmers with answers on these extensions and plugins. For asking a question click here. Select the appropriate question category (i.e. Krajee Plugins) and choose this current page plugin in the question related to field.
The comments and discussion section below are intended for generic discussions or feedback for this plugin. Developers may not be able to search or lookup here specific questions or tips on usage for this plugin.