arrange methods

This commit is contained in:
Emanuil Rusev 2014-02-21 02:22:31 +02:00
parent 688b761d32
commit f972f7f15d

View File

@ -15,24 +15,6 @@
class Parsedown class Parsedown
{ {
# Multiton
static function instance($name = 'default')
{
if (isset(self::$instances[$name]))
{
return self::$instances[$name];
}
$instance = new Parsedown();
self::$instances[$name] = $instance;
return $instance;
}
private static $instances = array();
# #
# Setters # Setters
# #
@ -92,85 +74,6 @@ class Parsedown
# #
# Private # Private
private function compile(array $blocks)
{
$markup = '';
foreach ($blocks as $block)
{
$markup .= "\n";
if (isset($block['name']))
{
$markup .= '<'.$block['name'];
if (isset($block['attributes']))
{
foreach ($block['attributes'] as $name => $value)
{
$markup .= ' '.$name.'="'.$value.'"';
}
}
if ($block['content'] === null)
{
$markup .= ' />';
continue;
}
else
{
$markup .= '>';
}
}
switch ($block['content type'])
{
case 'markup':
$markup .= $block['content'];
break;
case 'markdown':
$markup .= $this->parse_span_elements($block['content']);
break;
case 'markdown lines':
$result = $this->find_blocks($block['content'], $block['name']);
if (is_string($result)) # dense li
{
$markup .= $this->parse_span_elements($result);
break;
}
$markup .= $this->compile($result);
break;
case 'blocks':
$markup .= $this->compile($block['content']);
break;
}
if (isset($block['name']))
{
$markup .= '</'.$block['name'].'>';
}
}
$markup .= "\n";
return $markup;
}
private function find_blocks(array $lines, $block_context = null) private function find_blocks(array $lines, $block_context = null)
{ {
$block = null; $block = null;
@ -790,6 +693,85 @@ class Parsedown
return $blocks; return $blocks;
} }
private function compile(array $blocks)
{
$markup = '';
foreach ($blocks as $block)
{
$markup .= "\n";
if (isset($block['name']))
{
$markup .= '<'.$block['name'];
if (isset($block['attributes']))
{
foreach ($block['attributes'] as $name => $value)
{
$markup .= ' '.$name.'="'.$value.'"';
}
}
if ($block['content'] === null)
{
$markup .= ' />';
continue;
}
else
{
$markup .= '>';
}
}
switch ($block['content type'])
{
case 'markup':
$markup .= $block['content'];
break;
case 'markdown':
$markup .= $this->parse_span_elements($block['content']);
break;
case 'markdown lines':
$result = $this->find_blocks($block['content'], $block['name']);
if (is_string($result)) # dense li
{
$markup .= $this->parse_span_elements($result);
break;
}
$markup .= $this->compile($result);
break;
case 'blocks':
$markup .= $this->compile($block['content']);
break;
}
if (isset($block['name']))
{
$markup .= '</'.$block['name'].'>';
}
}
$markup .= "\n";
return $markup;
}
private function parse_span_elements($text, $markers = array(" \n", '![', '&', '*', '<', '[', '\\', '_', '`', 'http', '~~')) private function parse_span_elements($text, $markers = array(" \n", '![', '&', '*', '<', '[', '\\', '_', '`', 'http', '~~'))
{ {
if (isset($text[1]) === false or $markers === array()) if (isset($text[1]) === false or $markers === array())
@ -1140,6 +1122,25 @@ class Parsedown
return $markup; return $markup;
} }
#
# Static
static function instance($name = 'default')
{
if (isset(self::$instances[$name]))
{
return self::$instances[$name];
}
$instance = new Parsedown();
self::$instances[$name] = $instance;
return $instance;
}
private static $instances = array();
# #
# Fields # Fields
# #