fix more split

This commit is contained in:
祁宁 2016-02-08 15:59:24 +08:00
parent 2903f6a191
commit 394b93bbd2

View File

@ -9,7 +9,12 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit;
* @license GNU General Public License 2.0
*/
class Markdown
{
{
/**
* @var HyperDown
*/
public static $parser;
/**
* convert
*
@ -18,14 +23,13 @@ class Markdown
*/
public static function convert($text)
{
static $parser;
if (empty($parser)) {
$parser = new HyperDown();
$parser->hook('afterParseCode', array('Markdown', 'transerCodeClass'));
if (empty(self::$parser)) {
self::$parser = new HyperDown();
self::$parser->hook('afterParseCode', array('Markdown', 'transerCodeClass'));
self::$parser->hook('beforeParseInline', array('Markdown', 'transerComment'));
}
return $parser->makeHtml($text);
return self::$parser->makeHtml($text);
}
/**
@ -38,5 +42,23 @@ class Markdown
{
return preg_replace("/<code class=\"([_a-z0-9-]+)\">/i", "<code class=\"lang-\\1\">", $html);
}
/**
* @param $html
* @return mixed
*/
public static function transerComment($html)
{
return preg_replace_callback("/<!\-\-(.+?)\-\->/s", array('Markdown', 'transerCommentCallback'), $html);
}
/**
* @param $matches
* @return string
*/
public static function transerCommentCallback($matches)
{
return self::$parser->makeHolder($matches[0]);
}
}