From 394b93bbd2a2b8e3ae0b1696eee2e03ce63c497c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A5=81=E5=AE=81?= Date: Mon, 8 Feb 2016 15:59:24 +0800 Subject: [PATCH] fix more split --- var/Markdown.php | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/var/Markdown.php b/var/Markdown.php index 9bfcfc5a..a097d1d1 100644 --- a/var/Markdown.php +++ b/var/Markdown.php @@ -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("//i", "", $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]); + } }