From 1cc30665697805ab49f8aac901bb898b78284e80 Mon Sep 17 00:00:00 2001 From: joyqi Date: Tue, 24 Nov 2020 16:06:06 +0800 Subject: [PATCH] fix #1030 --- var/HyperDown.php | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/var/HyperDown.php b/var/HyperDown.php index 1bb8ed8b..1ad3aee9 100644 --- a/var/HyperDown.php +++ b/var/HyperDown.php @@ -265,7 +265,7 @@ class HyperDown $result = $this->call('after' . ucfirst($method), $result, $value); $html .= $result; - } + } return $html; } @@ -378,17 +378,27 @@ class HyperDown public function parseInline($text, $whiteList = '', $clearHolders = true, $enableAutoLink = true) { $self = $this; - $text = $this->call('beforeParseInline', $text); + $text = $this->call('beforeParseInline', $text); + + // 处理``之外的\字符 + preg_match_all('/`.+?`/', $text, $matches); + $delimiters = $matches[0]; + $lineTextArray = preg_split('/`.+?`/', $text); + $lineTextArray = array_map(function ($str) { + return preg_replace_callback("/\\\+/", function ($matches) { + $str = $matches[0]; + if (mb_strlen($str) % 2 > 0) { + return $str . '\\'; + } else { + return $str; + } + }, $str); + }, $lineTextArray); + $text = ''; + do { + $text .= array_shift($lineTextArray) . array_shift($delimiters); + } while ($lineTextArray); - $text = preg_replace_callback("/\\\+/",function($matches) { - $str = $matches[0]; - if(mb_strlen($str) % 2>0) { - return $str . '\\'; - } else { - return $str; - } - },$text); - // code $text = preg_replace_callback( "/(^|[^\\\])(`+)(.+?)\\2/", @@ -532,7 +542,7 @@ class HyperDown return $self->makeHolder($result); }, $text - ); + ); // strong and em and some fuck $text = $this->parseInlineCallback($text); @@ -656,7 +666,7 @@ class HyperDown $this->_blocks = array(); $this->_current = 'normal'; $this->_pos = -1; - + $state = array( 'special' => implode("|", array_keys($this->_specialWhiteList)), 'empty' => 0, @@ -1414,7 +1424,7 @@ class HyperDown if (preg_match("/^(\s*)/", $line, $matches)) { $space = strlen($matches[1]); - + if ($space > 0) { $secondMinSpace = min($space, $secondMinSpace); $secondFound = true;