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