PHPackages                             opotemkin/yii2-markdown - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. opotemkin/yii2-markdown

ActiveYii2-extension[Parsing &amp; Serialization](/categories/parsing)

opotemkin/yii2-markdown
=======================

Advanced Markdown editing and conversion utilities for Yii Framework 2.0

v1.6.0(8y ago)06491BSD-3-ClausePHP

Since Oct 5Pushed 8y ago1 watchersCompare

[ Source](https://github.com/opotemkin/yii2-markdown)[ Packagist](https://packagist.org/packages/opotemkin/yii2-markdown)[ Docs](https://github.com/kartik-v/yii2-markdown)[ RSS](/packages/opotemkin-yii2-markdown/feed)WikiDiscussions master Synced yesterday

READMEChangelog (3)Dependencies (3)Versions (9)Used By (0)

yii2-markdown (fork kartik-v/yii2-markdown)
===========================================

[](#yii2-markdown-fork-kartik-vyii2-markdown)

[![Latest Stable Version](https://camo.githubusercontent.com/af49a0b7156c61110aa8db0780916d67fba5dfe400de0977f093d7d684ceea98/68747470733a2f2f706f7365722e707567782e6f72672f6f706f74656d6b696e2f796969322d6d61726b646f776e2f762f737461626c65)](https://packagist.org/packages/opotemkin/yii2-markdown)[![License](https://camo.githubusercontent.com/4f81fce14fead2c6544e0e4570f5a3340d651f3288cd8977a09c8e7b01b4a39b/68747470733a2f2f706f7365722e707567782e6f72672f6b617274696b2d762f796969322d6d61726b646f776e2f6c6963656e7365)](https://packagist.org/packages/kartik-v/yii2-markdown)[![Total Downloads](https://camo.githubusercontent.com/8d6d6b13357331e8b3bfadbb4737e939b6a0a67ac142ece162df807547f30341/68747470733a2f2f706f7365722e707567782e6f72672f6b617274696b2d762f796969322d6d61726b646f776e2f646f776e6c6f616473)](https://packagist.org/packages/kartik-v/yii2-markdown)[![Monthly Downloads](https://camo.githubusercontent.com/1f5b42e9f91f93bd2a533e4d21f7a62e105ce3ecf8162caf8729c44819d31844/68747470733a2f2f706f7365722e707567782e6f72672f6b617274696b2d762f796969322d6d61726b646f776e2f642f6d6f6e74686c79)](https://packagist.org/packages/kartik-v/yii2-markdown)[![Daily Downloads](https://camo.githubusercontent.com/47d35806b5162594de15bf6f2536d4e6f06a856fbab9bc7e6c7fcb0a2feb926d/68747470733a2f2f706f7365722e707567782e6f72672f6b617274696b2d762f796969322d6d61726b646f776e2f642f6461696c79)](https://packagist.org/packages/kartik-v/yii2-markdown)

This module provides Markdown Editing and Conversion utilities for Yii Framework 2.0. It implements markdown conversion using PHP Markdown Extra and PHP Smarty Pants. 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](http://demos.krajee.com/markdown-demo).

### Markdown

[](#markdown)

[`VIEW DEMO`](http://demos.krajee.com/markdown-details/markdown-converter)
This is a markdown converter class that uses [PHP Markdown Extra](http://michelf.ca/projects/php-markdown/extra/) and [PHP SmartyPantsTypographer](http://michelf.ca/projects/php-smartypants/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](http://demos.krajee.com/markdown-details/markdown-converter) or view a [complete demo](http://demos.krajee.com/markdown-demo).

### MarkdownEditor

[](#markdowneditor)

[`VIEW DEMO`](http://demos.krajee.com/markdown-details/markdown-editor)
This is an advanced markdown input widget with configurable options. It is styled using Bootstrap 3.0. 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 Markdown.
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](http://demos.krajee.com/markdown-details/markdown-editor) or view a [complete demo](http://demos.krajee.com/markdown-demo).

### Demo

[](#demo)

You can see a [demonstration here](http://demos.krajee.com/markdown) on usage of these functions with documentation and examples.

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

> Note: Check the [composer.json](https://github.com/kartik-v/yii2-markdown/blob/master/composer.json) for this extension's requirements and dependencies. Read this [web tip /wiki](http://webtips.krajee.com/setting-composer-minimum-stability-application/) on setting the `minimum-stability` settings for your application's composer.json.

Either run

```
$ php composer.phar require opotemkin/yii2-markdown "dev-master"

```

or add

```
"opotemkin/yii2-markdown": "dev-master"

```

to the `require` section of your `composer.json` file.

Usage
-----

[](#usage)

### Setup Module

[](#setup-module)

Add `markdown` to your modules section of your Yii configuration file

```
'modules' = [
	/* 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 list of custom conversion patterns for post processing
		'customConversion' => [
			'' => ''
		],

		// whether to use PHP SmartyPantsTypographer to process Markdown output
		'smartyPants' => true
	]
	/* other modules */
];
```

### Markdown

[](#markdown-1)

```
use kartik\markdown\Markdown;

// default call
echo Markdown::convert($content);

// with custom post processing
echo Markdown::convert($content, ['custom' => [
	'' => '',
	'' => '',
	'' => Html::beginTag('p', $options),
]]);
```

### MarkdownEditor

[](#markdowneditor-1)

```
// 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,
]);
```

### Smarty Templates

[](#smarty-templates)

Smarty templates can be enabled globally by setting the module params

```
'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 */
];
```

Then define smarty in the editor

```
echo MarkdownEditor::widget([
    'model' => $model,
    'attribute' => 'markdown',
    'smarty' => true,
]);
```

Note that it may be unwise to enable Smarty templates globally. You can set the module property smarty to a callable function and provide RBAC features.

```
'modules' = [
	'markdown' => [
		'class' => 'kartik\markdown\Module',
		'smarty' => function($module) {
			if (\Yii::$app->user->can('smarty')) {
			    if(\Yii::$app->user->can('smartyYiiApp'))
			        $module->smartyYiiApp=true;
			    else
			        $module->smartyYiiApp=false;
			    if(\Yii::$app->user->can('smartyYiiParams'))
			        $module->smartyYiiParams=true;
			    else
			        $module->smartyYiiParams=false;
			    return true;
			}
			return false;
		}
	],
        /* other modules */
];
```

It may be a better option to leave smarty turned off in the config files and turn it on in the view with the widget settings.

```
echo MarkdownEditor::widget([
    'model' => $model,
    'attribute' => 'markdown',
    'smarty' => true,
    'previewAction' => Url::to(['my/preview']),
]);
```

Then create an action in your controller and implement RBAC there. That way Smarty templates is off by default and you can turn it on and control access to it in the Controller.

```
class MyController extends Controller
{
    public function actionPreview()
    {
        $module = Yii::$app->getModule('markdown');
        if (\Yii::$app->user->can('smarty')) {
            $module->smarty = true;
            $module->smartyYiiApp = \Yii::$app->user->can('smartyYiiApp') ? true : false;
            $module->smartyYiiParams = Yii::$app->user->can('smartyYiiParams') ? true : false;
        }
        if (isset($_POST['source'])) {
            $output = (strlen($_POST['source']) > 0) ? Markdown::convert($_POST['source'], ['custom' => $module->customConversion]) : $_POST['nullMsg'];
        }
        echo Json::encode(HtmlPurifier::process($output));
    }
}
```

After saving the value to the database you can render it in your views with Markdown::convert(). For example if you save the Markdown field in the content column of the Post table you can use something like the following.

```
$content = Post::find(['page_id'=>'myPage'])->one()->content;
echo HtmlPurifier::process(Markdown::convert($content, ['custom' => $module->customConversion]))
```

License
-------

[](#license)

**yii2-markdown** is released under the BSD 3-Clause License. See the bundled `LICENSE.md` for details.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 84% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~180 days

Recently: every ~291 days

Total

8

Last Release

2973d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e3ed6ff4923acf27121d2f268af686606f8f620934402d73dd8fe5568b8da602?d=identicon)[opotemkin](/maintainers/opotemkin)

---

Top Contributors

[![kartik-v](https://avatars.githubusercontent.com/u/3592619?v=4)](https://github.com/kartik-v "kartik-v (121 commits)")[![derekisbusy](https://avatars.githubusercontent.com/u/5118781?v=4)](https://github.com/derekisbusy "derekisbusy (12 commits)")[![Edofre](https://avatars.githubusercontent.com/u/710429?v=4)](https://github.com/Edofre "Edofre (2 commits)")[![drenty](https://avatars.githubusercontent.com/u/1330021?v=4)](https://github.com/drenty "drenty (2 commits)")[![janoszab](https://avatars.githubusercontent.com/u/3897821?v=4)](https://github.com/janoszab "janoszab (1 commits)")[![lestat1968](https://avatars.githubusercontent.com/u/7681695?v=4)](https://github.com/lestat1968 "lestat1968 (1 commits)")[![andrew72ru](https://avatars.githubusercontent.com/u/567649?v=4)](https://github.com/andrew72ru "andrew72ru (1 commits)")[![RichWeber](https://avatars.githubusercontent.com/u/1702252?v=4)](https://github.com/RichWeber "RichWeber (1 commits)")[![chris68](https://avatars.githubusercontent.com/u/1455561?v=4)](https://github.com/chris68 "chris68 (1 commits)")[![Faryshta](https://avatars.githubusercontent.com/u/2029247?v=4)](https://github.com/Faryshta "Faryshta (1 commits)")[![GeNTooFReaK](https://avatars.githubusercontent.com/u/40491599?v=4)](https://github.com/GeNTooFReaK "GeNTooFReaK (1 commits)")

---

Tags

convertermarkdownjqueryyii2extensionyiieditorbootstrapforminput

### Embed Badge

![Health badge](/badges/opotemkin-yii2-markdown/health.svg)

```
[![Health](https://phpackages.com/badges/opotemkin-yii2-markdown/health.svg)](https://phpackages.com/packages/opotemkin-yii2-markdown)
```

###  Alternatives

[kartik-v/yii2-markdown

Advanced Markdown editing and conversion utilities for Yii Framework 2.0

88265.8k6](/packages/kartik-v-yii2-markdown)[kartik-v/yii2-password

Useful password strength validation utilities for Yii Framework 2.0

791.2M17](/packages/kartik-v-yii2-password)[kartik-v/yii2-widget-rating

A Yii2 widget for the simple yet powerful bootstrap-star-rating plugin with fractional rating support (sub repo split from yii2-widgets)

444.1M8](/packages/kartik-v-yii2-widget-rating)[kartik-v/yii2-widget-switchinput

A Yii2 wrapper widget for the Bootstrap Switch plugin to use checkboxes &amp; radios as toggle switchinputes (sub repo split from yii2-widgets)

384.4M13](/packages/kartik-v-yii2-widget-switchinput)[kartik-v/yii2-widget-fileinput

An enhanced FileInput widget for Bootstrap 3.x, 4.x &amp; 5.x with file preview, multiple selection, and more features (sub repo split from yii2-widgets)

2286.8M95](/packages/kartik-v-yii2-widget-fileinput)[kartik-v/yii2-widget-touchspin

A Yii2 wrapper widget for the Bootstrap Switch plugin to use checkboxes &amp; radios as toggle touchspines (sub repo split from yii2-widgets)

184.1M6](/packages/kartik-v-yii2-widget-touchspin)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
