This commit is contained in:
joyqi 2020-11-24 16:06:06 +08:00
parent cee119eb4d
commit 1cc3066569

View File

@ -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;