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