Markdown.php 1.17 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
<?php
/**
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @link http://www.yiiframework.com/
 * @license http://www.yiiframework.com/license/
 */

namespace yii\helpers\base;

use Michelf\MarkdownExtra;

/**
 * Markdown provides an ability to transform markdown into HTML.
 *
 * Basic usage is the following:
 *
 * ```php
18
 * $myHtml = Markdown::process($myText);
19 20 21 22 23
 * ```
 *
 * If you want to configure the parser:
 *
 * ```php
24
 * $myHtml = Markdown::process($myText, array(
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
 *     'fn_id_prefix' => 'footnote_',
 * ));
 * ```
 *
 * For more details please refer to [PHP Markdown library documentation](http://michelf.ca/projects/php-markdown/).
 * @author Alexander Makarov <sam@rmcreative.ru>
 * @since 2.0
 */
class Markdown
{
	/**
	 * @var MarkdownExtra
	 */
	protected static $markdown;

Alexander Makarov committed
40 41 42 43 44 45 46
	/**
	 * Converts markdown into HTML
	 *
	 * @param string $content
	 * @param array $config
	 * @return string
	 */
47 48
	public static function process($content, $config = array())
	{
resurtm committed
49
		if (static::$markdown === null) {
50 51 52 53 54 55 56 57
			static::$markdown = new MarkdownExtra();
		}
		foreach ($config as $name => $value) {
			static::$markdown->{$name} = $value;
		}
		return static::$markdown->transform($content);
	}
}