Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
248 jpm 1
<?php
2
// $Id: Deflist.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 as a
8
* definition list.  In short, if a line starts with ':' then it is a
9
* definition list item; another ':' on the same lines indicates the end
10
* of the definition term and the beginning of the definition narrative.
11
* The list items must be on sequential lines (no blank lines between
12
* them) -- a blank line indicates the beginning of a new list.
13
*
14
* @author Paul M. Jones <pmjones@ciaweb.net>
15
*
16
* @package Text_Wiki
17
*
18
*/
19
 
20
class Text_Wiki_Parse_Deflist extends Text_Wiki_Parse {
21
 
22
 
23
    /**
24
    *
25
    * The regular expression used to parse the source text and find
26
    * matches conforming to this rule.  Used by the parse() method.
27
    *
28
    * @access public
29
    *
30
    * @var string
31
    *
32
    * @see parse()
33
    *
34
    */
35
 
36
    var $regex = '/\n((: ).*\n)(?!(: |\n))/Us';
37
 
38
 
39
    /**
40
    *
41
    * Generates a replacement for the matched text.  Token options are:
42
    *
43
    * 'type' =>
44
    *     'list_start'    : the start of a definition list
45
    *     'list_end'      : the end of a definition list
46
    *     'term_start'    : the start of a definition term
47
    *     'term_end'      : the end of a definition term
48
    *     'narr_start'    : the start of definition narrative
49
    *     'narr_end'      : the end of definition narrative
50
    *     'unknown'       : unknown type of definition portion
51
    *
52
    * @access public
53
    *
54
    * @param array &$matches The array of matches from parse().
55
    *
56
    * @return A series of text and delimited tokens marking the different
57
    * list text and list elements.
58
    *
59
    */
60
 
61
    function process(&$matches)
62
    {
63
        // the replacement text we will return to parse()
64
        $return = '';
65
 
66
        // the list of post-processing matches
67
        $list = array();
68
 
69
        // start the deflist
70
        $options = array('type' => 'list_start');
71
        $return .= $this->wiki->addToken($this->rule, $options);
72
 
73
        // $matches[1] is the text matched as a list set by parse();
74
        // create an array called $list that contains a new set of
75
        // matches for the various definition-list elements.
76
        preg_match_all(
77
            '/^(: )(.*)?( : )(.*)?$/Ums',
78
            $matches[1],
79
            $list,
80
            PREG_SET_ORDER
81
        );
82
 
83
        // add each term and narrative
84
        foreach ($list as $key => $val) {
85
            $return .= (
86
                $this->wiki->addToken($this->rule, array('type' => 'term_start')) .
87
                trim($val[2]) .
88
                $this->wiki->addToken($this->rule, array('type' => 'term_end')) .
89
                $this->wiki->addToken($this->rule, array('type' => 'narr_start')) .
90
                trim($val[4]) .
91
                $this->wiki->addToken($this->rule, array('type' => 'narr_end'))
92
            );
93
        }
94
 
95
 
96
        // end the deflist
97
        $options = array('type' => 'list_end');
98
        $return .= $this->wiki->addToken($this->rule, $options);
99
 
100
        // done!
101
        return "\n" . $return . "\n\n";
102
    }
103
}
104
?>