@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | { |
| 21 | 21 | $this->blockBegin($name, $attrs); |
| 22 | 22 | |
| 23 | - switch($name) { |
|
| 23 | + switch ($name) { |
|
| 24 | 24 | case "LI": |
| 25 | 25 | $this->appendBlockText("* "); |
| 26 | 26 | break; |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | public function endElement($parser, $name) |
| 31 | 31 | { |
| 32 | - switch($name) { |
|
| 32 | + switch ($name) { |
|
| 33 | 33 | case "P": |
| 34 | 34 | $this->appendBlockText("\n\n"); |
| 35 | 35 | break; |
@@ -45,14 +45,14 @@ discard block |
||
| 45 | 45 | case "A": |
| 46 | 46 | $attrs = $this->blockAttributesStack->top(); |
| 47 | 47 | |
| 48 | - if(isset($attrs['HREF'])) { |
|
| 48 | + if (isset($attrs['HREF'])) { |
|
| 49 | 49 | $this->appendBlockText(" ({$attrs['HREF']})"); |
| 50 | 50 | } |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | $blockContent = $this->blockFinished(); |
| 54 | 54 | |
| 55 | - if(count($this->transformedTextStack)) { |
|
| 55 | + if (count($this->transformedTextStack)) { |
|
| 56 | 56 | $this->appendBlockText($blockContent); |
| 57 | 57 | } |
| 58 | 58 | else { |
@@ -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(); |
@@ -26,7 +26,7 @@ |
||
| 26 | 26 | $wrappedHtml = "<root>$html</root>"; |
| 27 | 27 | $returnStatus = xml_parse($xml_parser, $wrappedHtml, true); |
| 28 | 28 | |
| 29 | - if(!$returnStatus) { |
|
| 29 | + if (!$returnStatus) { |
|
| 30 | 30 | return $html; |
| 31 | 31 | } |
| 32 | 32 | |
@@ -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 | |