@@ -3,14 +3,16 @@ discard block |
||
| 3 | 3 | namespace PurpleBooth; |
| 4 | 4 | |
| 5 | 5 | |
| 6 | -class Parser { |
|
| 6 | +class Parser |
|
| 7 | +{ |
|
| 7 | 8 | |
| 8 | 9 | private $text = ""; |
| 9 | 10 | private $transformedTextStack; |
| 10 | 11 | private $blockTypeStack; |
| 11 | 12 | private $blockAttributesStack; |
| 12 | 13 | |
| 13 | - public function __construct() { |
|
| 14 | + public function __construct() |
|
| 15 | + { |
|
| 14 | 16 | $this->transformedTextStack = new \SplStack(); |
| 15 | 17 | $this->blockTypeStack = new \SplStack(); |
| 16 | 18 | $this->blockAttributesStack = new \SplStack(); |
@@ -54,8 +56,7 @@ discard block |
||
| 54 | 56 | |
| 55 | 57 | if(count($this->transformedTextStack)) { |
| 56 | 58 | $this->appendBlockText($blockContent); |
| 57 | - } |
|
| 58 | - else { |
|
| 59 | + } else { |
|
| 59 | 60 | $this->text .= $blockContent; |
| 60 | 61 | } |
| 61 | 62 | } |
@@ -65,33 +66,39 @@ discard block |
||
| 65 | 66 | $this->appendBlockText(str_replace("\n", " ", $data)); |
| 66 | 67 | } |
| 67 | 68 | |
| 68 | - public function getText() { |
|
| 69 | + public function getText() |
|
| 70 | + { |
|
| 69 | 71 | $text = trim($this->text); |
| 70 | 72 | $lines = explode("\n", $text); |
| 71 | 73 | |
| 72 | 74 | return implode("\n", array_map("trim", $lines)); |
| 73 | 75 | } |
| 74 | 76 | |
| 75 | - private function appendBlockText($value) { |
|
| 77 | + private function appendBlockText($value) |
|
| 78 | + { |
|
| 76 | 79 | $this->setBlockText($this->getBlockText() . $value); |
| 77 | 80 | } |
| 78 | 81 | |
| 79 | - private function setBlockText($value) { |
|
| 82 | + private function setBlockText($value) |
|
| 83 | + { |
|
| 80 | 84 | $this->transformedTextStack->pop(); |
| 81 | 85 | $this->transformedTextStack->push($value); |
| 82 | 86 | } |
| 83 | 87 | |
| 84 | - private function getBlockText() { |
|
| 88 | + private function getBlockText() |
|
| 89 | + { |
|
| 85 | 90 | return $this->transformedTextStack->top(); |
| 86 | 91 | } |
| 87 | 92 | |
| 88 | - private function blockBegin($name, $attributes) { |
|
| 93 | + private function blockBegin($name, $attributes) |
|
| 94 | + { |
|
| 89 | 95 | $this->transformedTextStack->push(""); |
| 90 | 96 | $this->blockTypeStack->push($name); |
| 91 | 97 | $this->blockAttributesStack->push($attributes); |
| 92 | 98 | } |
| 93 | 99 | |
| 94 | - private function blockFinished() { |
|
| 100 | + private function blockFinished() |
|
| 101 | + { |
|
| 95 | 102 | return $this->transformedTextStack->pop(); |
| 96 | 103 | return $this->blockTypeStack->pop(); |
| 97 | 104 | return $this->blockAttributesStack->pop(); |
@@ -11,7 +11,8 @@ |
||
| 11 | 11 | ); |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | - public function getName() { |
|
| 14 | + public function getName() |
|
| 15 | + { |
|
| 15 | 16 | return "html_stripper"; |
| 16 | 17 | } |
| 17 | 18 | |