Markdown Details Markdown Converter

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.

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 a complete demo.

The output of the conversion is determined based on these parameters at the module configuration level:

  • smartyPants: boolean determining whether to use PHP SmartyPantsTypographer to process Markdown output
  • customConversion: array list of custom conversion patterns provided to find and replace as key-value pairs

In addition, the following variables can be passed to the Markdown::convert() function.

  • $content: string the content to convert.
  • $config: array the configuration of Markdown formats to process. The following formatting parameters are set in config:
    • markdown: array configuration parameters for PHP Markdown Extra
    • smarty: array configuration parameters for PHP SmartyPantsTypographer
    • custom: array configuration parameters for custom processing. This will override the customConversion set at module level. This is set as (key => value) pairs, where each key will be scanned and replaced with value
  • $smartyMode: integer determining the mode of PHP SmartyPantsTypographer. Defaults to SMARTYPANTS_ATTR_LONG_EM_DASH_SHORT_EN.
    • SMARTYPANTS_ATTR_DO_NOTHING = 0: SmartyPantsTypographer does nothing at all
    • SMARTYPANTS_ATTR_EM_DASH = 1: "--" for em-dashes; no en-dash support
    • SMARTYPANTS_ATTR_LONG_EM_DASH_SHORT_EN = 2: "---" for em-dashes; "--" for en-dashes
    • SMARTYPANTS_ATTR_SHORT_EM_DASH_LONG_EN = 3: "--" for em-dashes; "---" for en-dashes

Use 3 dashes `—` for em-dash. Use 2 dashes `–` for an en-dash or ranges (e.g. “It’s all in chapters 12–14”).


Use 3 dashes `---` for em-dash. Use 2 dashes `--` for an en-dash or ranges (e.g. "It's all in chapters 12--14").

use kartik\markdown\Markdown;

$content = '<p>Use 3 dashes `---` for em-dash. ' . 
    'Use 2 dashes `--` for an en-dash or ranges (e.g. "It\'s all in chapters 12--14").</p>';

// with custom post processing
echo Markdown::convert($content, ['custom' => [
    '<p>' => '<p class="text-info">'
]]);

// set smarty mode
echo Markdown::convert($content, [], Markdown::SMARTYPANTS_ATTR_DO_NOTHING);

This will parse markdown format using PHP Markdown Extra only. You can use this function, if you do not want to use SmartyPants or custom conversion features offered by this module.

Heading 3

use kartik\markdown\Markdown;

$content = '### Heading 3 ###';
echo Markdown::process($content);