You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

97 lines
2.5 KiB

  1. <?php
  2. /**
  3. * The summary XHTML form selects either up to the first two paragraphs
  4. * it find in a page or the first section (whichever comes first)
  5. * It strips out the table of contents if one exists
  6. * Section divs are not used - everything should be nested in a single
  7. * div with CSS class "page"
  8. * Headings have their a name link removed and section editing links
  9. * removed
  10. * It also attempts to capture the first heading in a page for
  11. * use as the title of the page.
  12. *
  13. *
  14. * @author Harry Fuecks <hfuecks@gmail.com>
  15. * @todo Is this currently used anywhere? Should it?
  16. */
  17. class Doku_Renderer_xhtmlsummary extends Doku_Renderer_xhtml
  18. {
  19. // Namespace these variables to
  20. // avoid clashes with parent classes
  21. protected $sum_paragraphs = 0;
  22. protected $sum_capture = true;
  23. protected $sum_inSection = false;
  24. protected $sum_summary = '';
  25. protected $sum_pageTitle = false;
  26. /** @inheritdoc */
  27. public function document_start()
  28. {
  29. $this->doc .= DOKU_LF . '<div>' . DOKU_LF;
  30. }
  31. /** @inheritdoc */
  32. public function document_end()
  33. {
  34. $this->doc = $this->sum_summary;
  35. $this->doc .= DOKU_LF . '</div>' . DOKU_LF;
  36. }
  37. /** @inheritdoc
  38. * @param string $text
  39. * @param int $level
  40. * @param int $pos
  41. * @param false $returnonly
  42. */
  43. public function header($text, $level, $pos, $returnonly = false)
  44. {
  45. if (!$this->sum_pageTitle) {
  46. $this->info['sum_pagetitle'] = $text;
  47. $this->sum_pageTitle = true;
  48. }
  49. $this->doc .= DOKU_LF . '<h' . $level . '>';
  50. $this->doc .= $this->_xmlEntities($text);
  51. $this->doc .= "</h$level>" . DOKU_LF;
  52. }
  53. /** @inheritdoc */
  54. public function section_open($level)
  55. {
  56. if ($this->sum_capture) {
  57. $this->sum_inSection = true;
  58. }
  59. }
  60. /** @inheritdoc */
  61. public function section_close()
  62. {
  63. if ($this->sum_capture && $this->sum_inSection) {
  64. $this->sum_summary .= $this->doc;
  65. $this->sum_capture = false;
  66. }
  67. }
  68. /** @inheritdoc */
  69. public function p_open()
  70. {
  71. if ($this->sum_capture && $this->sum_paragraphs < 2) {
  72. $this->sum_paragraphs++;
  73. }
  74. parent::p_open();
  75. }
  76. /** @inheritdoc */
  77. public function p_close()
  78. {
  79. parent::p_close();
  80. if ($this->sum_capture && $this->sum_paragraphs >= 2) {
  81. $this->sum_summary .= $this->doc;
  82. $this->sum_capture = false;
  83. }
  84. }
  85. }
  86. //Setup VIM: ex: et ts=2 :