1
0
mirror of https://github.com/erusev/parsedown.git synced 2023-08-10 21:13:06 +03:00

Remove regex from fenced code block

Also remove unused function
This commit is contained in:
Aidan Woods 2018-04-09 02:30:22 +01:00
parent e74a5bd7ed
commit d2dd736e1b
No known key found for this signature in database
GPG Key ID: 9A6A8EFAA512BBB9

View File

@ -424,33 +424,42 @@ class Parsedown
protected function blockFencedCode($Line)
{
if (preg_match('/^(['.$Line['text'][0].']{3,}+)[ ]*+([^`]++)?+[ ]*+$/', $Line['text'], $matches))
$marker = $Line['text'][0];
$openerLength = strspn($Line['text'], $marker);
if ($openerLength < 3)
{
$Element = array(
'name' => 'code',
'text' => '',
);
if (isset($matches[2]))
{
$class = "language-{$matches[2]}";
$Element['attributes'] = array(
'class' => $class,
);
}
$Block = array(
'char' => $Line['text'][0],
'openerLength' => mb_strlen($matches[1]),
'element' => array(
'name' => 'pre',
'element' => $Element,
),
);
return $Block;
return;
}
$infostring = trim(substr($Line['text'], $openerLength), "\t ");
if (strpos($infostring, '`') !== false)
{
return;
}
$Element = array(
'name' => 'code',
'text' => '',
);
if ($infostring !== '')
{
$Element['attributes'] = array('class' => "language-$infostring");
}
$Block = array(
'char' => $marker,
'openerLength' => $openerLength,
'element' => array(
'name' => 'pre',
'element' => $Element,
),
);
return $Block;
}
protected function blockFencedCodeContinue($Line, $Block)
@ -467,9 +476,8 @@ class Parsedown
unset($Block['interrupted']);
}
if (
preg_match('/^(['.preg_quote($Block['char']).']{3,}+)[ ]*+$/', $Line['text'], $matches)
and mb_strlen($matches[1]) >= $Block['openerLength']
if (($len = strspn($Line['text'], $Block['char'])) >= $Block['openerLength']
and chop(substr($Line['text'], $len), ' ') === ''
) {
$Block['element']['element']['text'] = substr($Block['element']['element']['text'], 1);
@ -483,15 +491,6 @@ class Parsedown
return $Block;
}
protected function blockFencedCodeComplete($Block)
{
$text = $Block['element']['element']['text'];
$Block['element']['element']['text'] = $text;
return $Block;
}
#
# Header