xref: /dokuwiki/inc/parser/xhtmlsummary.php (revision 3dc2d50c5fda9c4bf708ff4c26e266ba239af62c)
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 */
17class Doku_Renderer_xhtmlsummary extends Doku_Renderer_xhtml {
18
19    // Namespace these variables to
20    // avoid clashes with parent classes
21    var $sum_paragraphs = 0;
22    var $sum_capture = true;
23    var $sum_inSection = false;
24    var $sum_summary = '';
25    var $sum_pageTitle = false;
26
27    function document_start() {
28        $this->doc .= DOKU_LF.'<div>'.DOKU_LF;
29    }
30
31    function document_end() {
32        $this->doc = $this->sum_summary;
33        $this->doc .= DOKU_LF.'</div>'.DOKU_LF;
34    }
35
36    // FIXME not supported anymore
37    function toc_open() {
38        $this->sum_summary .= $this->doc;
39    }
40
41    // FIXME not supported anymore
42    function toc_close() {
43        $this->doc = '';
44    }
45
46    function header($text, $level, $pos) {
47        if ( !$this->sum_pageTitle ) {
48            $this->info['sum_pagetitle'] = $text;
49            $this->sum_pageTitle = true;
50        }
51        $this->doc .= DOKU_LF.'<h'.$level.'>';
52        $this->doc .= $this->_xmlEntities($text);
53        $this->doc .= "</h$level>".DOKU_LF;
54    }
55
56    function section_open($level) {
57        if ( $this->sum_capture ) {
58            $this->sum_inSection = true;
59        }
60    }
61
62    function section_close() {
63        if ( $this->sum_capture && $this->sum_inSection ) {
64            $this->sum_summary .= $this->doc;
65            $this->sum_capture = false;
66        }
67    }
68
69    function p_open() {
70        if ( $this->sum_capture && $this->sum_paragraphs < 2 ) {
71            $this->sum_paragraphs++;
72        }
73        parent :: p_open();
74    }
75
76    function p_close() {
77        parent :: p_close();
78        if ( $this->sum_capture && $this->sum_paragraphs >= 2 ) {
79            $this->sum_summary .= $this->doc;
80            $this->sum_capture = false;
81        }
82    }
83
84}
85
86
87//Setup VIM: ex: et ts=2 :
88