Yii 2 Markdown

Latest Stable Version Latest Unstable Version Total Downloads Monthly Downloads Daily Downloads
Thankful to Krajee!
to get more out of us.

NOTE: This extension depends on the kartik-v/yii2-krajee-base extension which in turn depends on the yiisoft/yii2-bootstrap extension. Check the composer.json for this extension's requirements and dependencies that may be updated by composer.

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.

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

This class implements markdown conversion using PHP Markdown Extra and PHP Smarty Pants Typographer for processing Markdown conversion to HTML. It also supports configurable custom conversion processing of patterns for styling your own flavour of Markdown to some extent. View examples and details or view a complete demo.

use kartik\markdown\Markdown;
echo Markdown::convert($content);

This is an advanced markdown input widget to edit and preview Markdown content with configurable options. It is styled using Bootstrap 3.0. The key features available with this widget are:

  1. Configurable toolbar and buttons for formatting content
  2. Live preview of Markdown formatted text as HTML
  3. Maximize editor for full screen editing
  4. Implements PHP Markdown Extra and PHP SmartyPantsTypographer functionality as provided by the MarkdownConverter.
  5. Uses Bootstrap 3.0 styling wherever possible
  6. Allows saving/exporting of the text-editor contents as Text or HTML
  7. Configurable header, footer, and input options.
  8. Supports localization and customization of messages and content.
View examples and details or view a complete demo.

// add this in your view
use kartik\markdown\MarkdownEditor;

// usage with Active Form 
echo $form->field($model, 'markdown')->widget(
	['height' => 300, 'encodeLabels' => false]

// usage with model
echo MarkdownEditor::widget([
    'model' => $model, 
    'attribute' => 'markdown',

// usage without model
echo MarkdownEditor::widget([
    'name' => 'markdown', 
    'value' => $value,