Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
164 jpm 1
<?php
2
// $Id: Heading.php,v 1.1 2004-11-23 17:24:57 jpm Exp $
3
 
4
 
5
/**
6
*
7
* This class implements a Text_Wiki_Parse to find source text marked to
8
* be a heading element, as defined by text on a line by itself prefixed
9
* with a number of plus signs (+). The heading text itself is left in
10
* the source, but is prefixed and suffixed with delimited tokens marking
11
* the start and end of the heading.
12
*
13
* @author Paul M. Jones <pmjones@ciaweb.net>
14
*
15
* @package Text_Wiki
16
*
17
*/
18
 
19
class Text_Wiki_Parse_Heading extends Text_Wiki_Parse {
20
 
21
 
22
    /**
23
    *
24
    * The regular expression used to parse the source text and find
25
    * matches conforming to this rule.  Used by the parse() method.
26
    *
27
    * @access public
28
    *
29
    * @var string
30
    *
31
    * @see parse()
32
    *
33
    */
34
 
35
    var $regex = '/^(={1,6})(.*?)(={1,6})/m';
36
 
37
    var $conf = array(
38
        'id_prefix' => 'toc'
39
    );
40
 
41
    /**
42
    *
43
    * Generates a replacement for the matched text.  Token options are:
44
    *
45
    * 'type' => ['start'|'end'] The starting or ending point of the
46
    * heading text.  The text itself is left in the source.
47
    *
48
    * @access public
49
    *
50
    * @param array &$matches The array of matches from parse().
51
    *
52
    * @return string A pair of delimited tokens to be used as a
53
    * placeholder in the source text surrounding the heading text.
54
    *
55
    */
56
 
57
    function process(&$matches)
58
    {
59
        // Tableau permettant l'inversion du nombre de = par rapport au niveau du titre
60
        $titre_niveau = array(6=>1, 5=>2, 4=>3, 3=>4, 2=>5, 1=>6);
61
        // keep a running count for header IDs.  we use this later
62
        // when constructing TOC entries, etc.
63
        static $id;
64
        if (! isset($id)) {
65
            $id = 0;
66
        }
67
 
68
        $prefix = htmlspecialchars($this->getConf('id_prefix'));
69
 
70
        $start = $this->wiki->addToken(
71
            $this->rule,
72
            array(
73
                'type' => 'start',
74
                'level' => $titre_niveau[strlen($matches[1])],
75
                'text' => $matches[2],
76
                'id' => $prefix . $id ++
77
            )
78
        );
79
 
80
        $end = $this->wiki->addToken(
81
            $this->rule,
82
            array(
83
                'type' => 'end',
84
                'level' =>$titre_niveau[strlen($matches[1])]
85
            )
86
        );
87
 
88
        return $start . $matches[2] . $end . "\n";
89
    }
90
}
91
?>