move block identifying code into own method; use this to check whether a new block exists on the current line at a lesser indentation: if so, interupt current block

This commit is contained in:
Aidan Woods 2017-01-23 16:05:12 +00:00
parent ab9f45b420
commit fb3db195cb
No known key found for this signature in database
GPG Key ID: 9A6A8EFAA512BBB9

View File

@ -163,6 +163,15 @@ class Parsedown
# ~
$NewBlock = $this->block($Line, $CurrentBlock);
if (isset($CurrentBlock['indent']) and isset($NewBlock) and $NewBlock['indent'] < $CurrentBlock['indent'])
{
$CurrentBlock['interrupted'] = true;
}
# ~
if (isset($CurrentBlock['continuable']))
{
$Block = $this->{'block'.$CurrentBlock['type'].'Continue'}($Line, $CurrentBlock);
@ -189,47 +198,15 @@ class Parsedown
# ~
$marker = $text[0];
# ~
$blockTypes = $this->unmarkedBlockTypes;
if (isset($this->BlockTypes[$marker]))
{
foreach ($this->BlockTypes[$marker] as $blockType)
{
$blockTypes []= $blockType;
}
}
#
# ~
foreach ($blockTypes as $blockType)
{
$Block = $this->{'block'.$blockType}($Line, $CurrentBlock);
$Block = $this->block($Line, $CurrentBlock, $Blocks);
if (isset($Block))
{
$Block['type'] = $blockType;
if ( ! isset($Block['identified']))
{
$Blocks []= $CurrentBlock;
$Block['identified'] = true;
}
if ($this->isBlockContinuable($blockType))
{
$Block['continuable'] = true;
}
$CurrentBlock = $Block;
continue 2;
}
unset($Block);
continue;
}
# ~
@ -293,6 +270,66 @@ class Parsedown
return method_exists($this, 'block'.$Type.'Complete');
}
protected function block($Line, $CurrentBlock = null, &$Blocks = null)
{
if ( ! isset($Blocks))
{
$Blocks = array();
}
# ~
$marker = $Line['text'][0];
# ~
$blockTypes = $this->unmarkedBlockTypes;
if (isset($this->BlockTypes[$marker]))
{
foreach ($this->BlockTypes[$marker] as $blockType)
{
$blockTypes []= $blockType;
}
}
#
# ~
$Block = null;
foreach ($blockTypes as $blockType)
{
$Block = $this->{'block'.$blockType}($Line, $CurrentBlock);
if (isset($Block))
{
$Block['type'] = $blockType;
if ( ! isset($Block['identified']))
{
$Blocks []= $CurrentBlock;
$Block['identified'] = true;
}
if ($this->isBlockContinuable($blockType))
{
$Block['continuable'] = true;
}
if ( ! isset($Block['indent']))
{
$Block['indent'] = $Line['indent'];
}
continue;
}
}
return $Block;
}
#
# Code