Krajee

Markdown Converter

Thankful to Krajee! BUY A COFFEEor to get more out of us.
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.

Tip

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 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); 

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.

 
visitors to Krajee Yii2 Demos since 22-May-2017