Subversion Repositories Applications.papyrus

Rev

Rev 1688 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
248 jpm 1
<?php
2
// $Id: Heading.php,v 1.1 2005-01-20 19:43:20 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}) (.*)/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
        // keep a running count for header IDs.  we use this later
60
        // when constructing TOC entries, etc.
61
        static $id;
62
        if (! isset($id)) {
63
            $id = 0;
64
        }
65
 
66
        $prefix = htmlspecialchars($this->getConf('id_prefix'));
67
 
68
        $start = $this->wiki->addToken(
69
            $this->rule,
70
            array(
71
                'type' => 'start',
72
                'level' => strlen($matches[1]),
73
                'text' => $matches[2],
74
                'id' => $prefix . $id ++
75
            )
76
        );
77
 
78
        $end = $this->wiki->addToken(
79
            $this->rule,
80
            array(
81
                'type' => 'end',
82
                'level' => strlen($matches[1])
83
            )
84
        );
85
 
86
        return $start . $matches[2] . $end . "\n";
87
    }
88
}
89
?>