1be906b56SAndreas Gohr<?php 2be906b56SAndreas Gohr 3be906b56SAndreas Gohrnamespace dokuwiki\Parsing\Handler; 4be906b56SAndreas Gohr 5533aca44SAndreas Gohrclass Preformatted extends AbstractRewriter 6be906b56SAndreas Gohr{ 7be906b56SAndreas Gohr protected $pos; 8be906b56SAndreas Gohr protected $text = ''; 9be906b56SAndreas Gohr 10be906b56SAndreas Gohr /** @inheritdoc */ 11*8c5fa126SAndreas Gohr protected function getClosingCall(): string 12be906b56SAndreas Gohr { 13*8c5fa126SAndreas Gohr return 'preformatted_end'; 14be906b56SAndreas Gohr } 15be906b56SAndreas Gohr 16be906b56SAndreas Gohr /** @inheritdoc */ 17be906b56SAndreas Gohr public function process() 18be906b56SAndreas Gohr { 19be906b56SAndreas Gohr foreach ($this->calls as $call) { 20be906b56SAndreas Gohr switch ($call[0]) { 21be906b56SAndreas Gohr case 'preformatted_start': 22be906b56SAndreas Gohr $this->pos = $call[2]; 23be906b56SAndreas Gohr break; 24be906b56SAndreas Gohr case 'preformatted_newline': 25be906b56SAndreas Gohr $this->text .= "\n"; 26be906b56SAndreas Gohr break; 27be906b56SAndreas Gohr case 'preformatted_content': 28be906b56SAndreas Gohr $this->text .= $call[1][0]; 29be906b56SAndreas Gohr break; 30be906b56SAndreas Gohr case 'preformatted_end': 31be906b56SAndreas Gohr if (trim($this->text)) { 32bcaec9f4SAndreas Gohr $this->callWriter->writeCall(['preformatted', [$this->text], $this->pos]); 33be906b56SAndreas Gohr } 34be906b56SAndreas Gohr // see FS#1699 & FS#1652, add 'eol' instructions to ensure proper triggering of following p_open 35bcaec9f4SAndreas Gohr $this->callWriter->writeCall(['eol', [], $this->pos]); 36bcaec9f4SAndreas Gohr $this->callWriter->writeCall(['eol', [], $this->pos]); 37be906b56SAndreas Gohr break; 38be906b56SAndreas Gohr } 39be906b56SAndreas Gohr } 40be906b56SAndreas Gohr 41be906b56SAndreas Gohr return $this->callWriter; 42be906b56SAndreas Gohr } 43be906b56SAndreas Gohr} 44