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