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:
parent
e74a5bd7ed
commit
d2dd736e1b
@ -424,33 +424,42 @@ class Parsedown
|
|||||||
|
|
||||||
protected function blockFencedCode($Line)
|
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(
|
return;
|
||||||
'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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$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)
|
protected function blockFencedCodeContinue($Line, $Block)
|
||||||
@ -467,9 +476,8 @@ class Parsedown
|
|||||||
unset($Block['interrupted']);
|
unset($Block['interrupted']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (($len = strspn($Line['text'], $Block['char'])) >= $Block['openerLength']
|
||||||
preg_match('/^(['.preg_quote($Block['char']).']{3,}+)[ ]*+$/', $Line['text'], $matches)
|
and chop(substr($Line['text'], $len), ' ') === ''
|
||||||
and mb_strlen($matches[1]) >= $Block['openerLength']
|
|
||||||
) {
|
) {
|
||||||
$Block['element']['element']['text'] = substr($Block['element']['element']['text'], 1);
|
$Block['element']['element']['text'] = substr($Block['element']['element']['text'], 1);
|
||||||
|
|
||||||
@ -483,15 +491,6 @@ class Parsedown
|
|||||||
return $Block;
|
return $Block;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function blockFencedCodeComplete($Block)
|
|
||||||
{
|
|
||||||
$text = $Block['element']['element']['text'];
|
|
||||||
|
|
||||||
$Block['element']['element']['text'] = $text;
|
|
||||||
|
|
||||||
return $Block;
|
|
||||||
}
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Header
|
# Header
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user