From f972f7f15ddba8296fe500b9322394a16bffdc3b Mon Sep 17 00:00:00 2001 From: Emanuil Rusev Date: Fri, 21 Feb 2014 02:22:31 +0200 Subject: [PATCH] arrange methods --- Parsedown.php | 195 +++++++++++++++++++++++++------------------------- 1 file changed, 98 insertions(+), 97 deletions(-) diff --git a/Parsedown.php b/Parsedown.php index 52e0b9b..59664e9 100755 --- a/Parsedown.php +++ b/Parsedown.php @@ -15,24 +15,6 @@ 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 # @@ -92,85 +74,6 @@ class Parsedown # # 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 .= ''; - } - } - - $markup .= "\n"; - - return $markup; - } - private function find_blocks(array $lines, $block_context = null) { $block = null; @@ -790,6 +693,85 @@ class Parsedown 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 .= ''; + } + } + + $markup .= "\n"; + + return $markup; + } + private function parse_span_elements($text, $markers = array(" \n", '![', '&', '*', '<', '[', '\\', '_', '`', 'http', '~~')) { if (isset($text[1]) === false or $markers === array()) @@ -1140,6 +1122,25 @@ class Parsedown 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 #