mirror of
https://github.com/erusev/parsedown.git
synced 2024-09-20 12:01:29 +02:00
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:
parent
ab9f45b420
commit
fb3db195cb
111
Parsedown.php
111
Parsedown.php
@ -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];
|
||||
$Block = $this->block($Line, $CurrentBlock, $Blocks);
|
||||
|
||||
# ~
|
||||
|
||||
$blockTypes = $this->unmarkedBlockTypes;
|
||||
|
||||
if (isset($this->BlockTypes[$marker]))
|
||||
if (isset($Block))
|
||||
{
|
||||
foreach ($this->BlockTypes[$marker] as $blockType)
|
||||
{
|
||||
$blockTypes []= $blockType;
|
||||
}
|
||||
}
|
||||
$CurrentBlock = $Block;
|
||||
|
||||
#
|
||||
# ~
|
||||
unset($Block);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
$CurrentBlock = $Block;
|
||||
|
||||
continue 2;
|
||||
}
|
||||
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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user