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