mirror of
https://github.com/typemill/typemill.git
synced 2025-08-06 14:16:46 +02:00
Version 1.1.1 Theme and Plugin Optimizations
This commit is contained in:
@@ -25,9 +25,17 @@ class ParsedownExtension extends \ParsedownExtra
|
||||
# split text into lines
|
||||
$lines = explode("\n", $text);
|
||||
|
||||
# iterate through lines to identify blocks
|
||||
$markup = $this->lines($lines);
|
||||
|
||||
# iterate through lines to identify blocks and return array of content
|
||||
$blocks = $this->getContentArray($lines);
|
||||
|
||||
return $blocks;
|
||||
}
|
||||
|
||||
function markup($blocks)
|
||||
{
|
||||
# iterate through array of content and get markup
|
||||
$markup = $this->getMarkup($blocks);
|
||||
|
||||
# trim line breaks
|
||||
$markup = trim($markup, "\n");
|
||||
|
||||
@@ -146,4 +154,176 @@ class ParsedownExtension extends \ParsedownExtra
|
||||
|
||||
return $markup;
|
||||
}
|
||||
|
||||
|
||||
#
|
||||
# Blocks
|
||||
#
|
||||
|
||||
protected function getContentArray(array $lines)
|
||||
{
|
||||
$CurrentBlock = null;
|
||||
|
||||
foreach ($lines as $line)
|
||||
{
|
||||
if (chop($line) === '')
|
||||
{
|
||||
if (isset($CurrentBlock))
|
||||
{
|
||||
$CurrentBlock['interrupted'] = true;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strpos($line, "\t") !== false)
|
||||
{
|
||||
$parts = explode("\t", $line);
|
||||
|
||||
$line = $parts[0];
|
||||
|
||||
unset($parts[0]);
|
||||
|
||||
foreach ($parts as $part)
|
||||
{
|
||||
$shortage = 4 - mb_strlen($line, 'utf-8') % 4;
|
||||
|
||||
$line .= str_repeat(' ', $shortage);
|
||||
$line .= $part;
|
||||
}
|
||||
}
|
||||
|
||||
$indent = 0;
|
||||
|
||||
while (isset($line[$indent]) and $line[$indent] === ' ')
|
||||
{
|
||||
$indent ++;
|
||||
}
|
||||
|
||||
$text = $indent > 0 ? substr($line, $indent) : $line;
|
||||
|
||||
# ~
|
||||
|
||||
$Line = array('body' => $line, 'indent' => $indent, 'text' => $text);
|
||||
|
||||
# ~
|
||||
|
||||
if (isset($CurrentBlock['continuable']))
|
||||
{
|
||||
$Block = $this->{'block'.$CurrentBlock['type'].'Continue'}($Line, $CurrentBlock);
|
||||
|
||||
if (isset($Block))
|
||||
{
|
||||
$CurrentBlock = $Block;
|
||||
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($this->isBlockCompletable($CurrentBlock['type']))
|
||||
{
|
||||
$CurrentBlock = $this->{'block'.$CurrentBlock['type'].'Complete'}($CurrentBlock);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# ~
|
||||
|
||||
$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);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
# ~
|
||||
|
||||
if (isset($CurrentBlock) and ! isset($CurrentBlock['type']) and ! isset($CurrentBlock['interrupted']))
|
||||
{
|
||||
$CurrentBlock['element']['text'] .= "\n".$text;
|
||||
}
|
||||
else
|
||||
{
|
||||
$Blocks []= $CurrentBlock;
|
||||
|
||||
$CurrentBlock = $this->paragraph($Line);
|
||||
|
||||
$CurrentBlock['identified'] = true;
|
||||
}
|
||||
}
|
||||
|
||||
# ~
|
||||
|
||||
if (isset($CurrentBlock['continuable']) and $this->isBlockCompletable($CurrentBlock['type']))
|
||||
{
|
||||
$CurrentBlock = $this->{'block'.$CurrentBlock['type'].'Complete'}($CurrentBlock);
|
||||
}
|
||||
|
||||
# ~
|
||||
|
||||
$Blocks []= $CurrentBlock;
|
||||
|
||||
unset($Blocks[0]);
|
||||
|
||||
# ~
|
||||
return $Blocks;
|
||||
}
|
||||
|
||||
public function getMarkup($Blocks)
|
||||
{
|
||||
$markup = '';
|
||||
|
||||
foreach ($Blocks as $Block)
|
||||
{
|
||||
if (isset($Block['hidden']))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$markup .= "\n";
|
||||
$markup .= isset($Block['markup']) ? $Block['markup'] : $this->element($Block['element']);
|
||||
}
|
||||
|
||||
$markup .= "\n";
|
||||
|
||||
# ~
|
||||
|
||||
return $markup;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user