Preformatted.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace dokuwiki\Parsing\Handler;
  3. class Preformatted extends AbstractRewriter
  4. {
  5. protected $pos;
  6. protected $text ='';
  7. /** @inheritdoc */
  8. public function finalise()
  9. {
  10. $last_call = end($this->calls);
  11. $this->writeCall(array('preformatted_end',array(), $last_call[2]));
  12. $this->process();
  13. $this->callWriter->finalise();
  14. unset($this->callWriter);
  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(array('preformatted', array($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(array('eol', array(), $this->pos));
  36. $this->callWriter->writeCall(array('eol', array(), $this->pos));
  37. break;
  38. }
  39. }
  40. return $this->callWriter;
  41. }
  42. }