Markdown.php 1.23 KB
Newer Older
1 2
<?php
/**
Carsten Brandt committed
3 4 5
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
6 7 8 9
 */

namespace yii\apidoc\helpers;

10 11
use Parsedown;
use yii\base\Component;
12

Carsten Brandt committed
13
/**
14
 * A Markdown helper with support for class reference links.
Carsten Brandt committed
15 16 17 18
 *
 * @author Carsten Brandt <mail@cebe.cc>
 * @since 2.0
 */
19
class Markdown extends Component
20
{
21
	private $_parseDown;
22

23
	protected function getParseDown()
24
	{
25 26
		if ($this->_parseDown === null) {
			$this->_parseDown = new ParseDown();
27
		}
28 29
		return $this->_parseDown;
	}
30

31 32 33 34
	public function parse($markdown)
	{
		return $this->getParseDown()->parse($markdown);
	}
35

36 37 38 39
	public function parseLine($markdown)
	{
		return $this->getParseDown()->parseLine($markdown);
	}
40

41 42 43 44
	public function registerBlockHander($blockName, $callback)
	{
		$this->getParseDown()->register_block_handler($blockName, $callback);
	}
45

46 47 48 49 50 51 52 53 54 55 56 57 58
	public function unregisterBlockHander($blockName)
	{
		$this->getParseDown()->remove_block_handler($blockName);
	}

	public function registerInlineMarkerHandler($marker, $callback)
	{
		$this->getParseDown()->add_span_marker($marker, $callback);
	}

	public function unregisterInlineMarkerHandler($marker)
	{
		$this->getParseDown()->remove_span_marker($marker);
59
	}
Qiang Xue committed
60
}