summaryrefslogtreecommitdiff
path: root/inc/parser/xhtmlsummary.php
blob: eeb684e57483584971a39575bc7c84fa9f82efaa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');

require_once DOKU_INC . 'inc/parser/xhtml.php';

/**
* The summary XHTML form selects either up to the first two paragraphs
* it find in a page or the first section (whichever comes first)
* It strips out the table of contents if one exists
* Section divs are not used - everything should be nested in a single
* div with CSS class "page"
* Headings have their a name link removed and section editing links
* removed
* It also attempts to capture the first heading in a page for
* use as the title of the page.
*/
class Doku_Renderer_xhtmlsummary extends Doku_Renderer_xhtml {
    
    // Namespace these variables to
    // avoid clashes with parent classes
    var $sum_paragraphs = 0;
    var $sum_capture = TRUE;
    var $sum_inSection = FALSE;
    var $sum_summary = '';
    var $sum_pageTitle = FALSE;
    
    function document_start() {
        $this->doc .= DOKU_LF.'<div>'.DOKU_LF;
    }
    
    function document_end() {
        $this->doc = $this->sum_summary;
        $this->doc .= DOKU_LF.'</div>'.DOKU_LF;
    }
    
    function toc_open() {
        $this->sum_summary .= $this->doc;
    }
    
    function toc_close() {
        $this->doc = '';
    }
    
    function header($text, $level, $pos) {
        if ( !$this->sum_pageTitle ) {
            $this->info['sum_pagetitle'] = $text;
            $this->sum_pageTitle = TRUE;
        }
        $this->doc .= DOKU_LF.'<h'.$level.'>';
        $this->doc .= $this->_xmlEntities($text);
        $this->doc .= "</h$level>".DOKU_LF;
    }
    
    function section_open($level) {
        if ( $this->sum_capture ) {
            $this->sum_inSection = TRUE;
        }
    }
    
    function section_close() {
        if ( $this->sum_capture && $this->sum_inSection ) {
            $this->sum_summary .= $this->doc;
            $this->sum_capture = FALSE;
        }
    }
    
    function p_open() {
        if ( $this->sum_capture && $this->sum_paragraphs < 2 ) {
            $this->sum_paragraphs++;
        }
        parent :: p_open();
    }
    
    function p_close() {
        parent :: p_close();
        if ( $this->sum_capture && $this->sum_paragraphs >= 2 ) {
            $this->sum_summary .= $this->doc;
            $this->sum_capture = FALSE;
        }
    }
    
}


//Setup VIM: ex: et ts=2 enc=utf-8 :