5 * Parse for block-quoted text.
11 * @author Paul M. Jones <pmjones@php.net>
15 * @version $Id: Blockquote.php,v 1.3 2005/02/23 17:38:29 pmjones Exp $
21 * Parse for block-quoted text.
23 * Find source text marked as a blockquote, identified by any number of
24 * greater-than signs '>' at the start of the line, followed by a space,
25 * and then the quote text; each '>' indicates an additional level of
32 * @author Paul M. Jones <pmjones@php.net>
36 class Text_Wiki_Parse_Blockquote
extends Text_Wiki_Parse
{
41 * Regex for parsing the source text.
51 var $regex = '/\n((\>).*\n)(?!(\>))/Us';
56 * Generates a replacement for the matched text.
61 * 'start' : the start of a blockquote
62 * 'end' : the end of a blockquote
64 * 'level' => the indent level (0 for the first level, 1 for the
69 * @param array &$matches The array of matches from parse().
71 * @return A series of text and delimited tokens marking the different
72 * list text and list elements.
76 function process(&$matches)
78 // the replacement text we will return to parse()
81 // the list of post-processing matches
84 // $matches[1] is the text matched as a list set by parse();
85 // create an array called $list that contains a new set of
86 // matches for the various list-item elements.
94 // a stack of starts and ends; we keep this so that we know what
95 // indent level we're at.
98 // loop through each list-item element.
99 foreach ($list as $key => $val) {
101 // $val[0] is the full matched list-item line
102 // $val[1] is the number of initial '>' chars (indent level)
103 // $val[2] is the quote text
105 // we number levels starting at 1, not zero
106 $level = strlen($val[1]);
108 // get the text of the line
111 // add a level to the list?
112 while ($level > count($stack)) {
114 // the current indent level is greater than the number
115 // of stack elements, so we must be starting a new
116 // level. push the new level onto the stack with a
117 // dummy value (boolean true)...
118 array_push($stack, true
);
122 // ...and add a start token to the return.
123 $return .= $this->wiki
->addToken(
127 'level' => $level - 1
135 while (count($stack) > $level) {
137 // as long as the stack count is greater than the
138 // current indent level, we need to end list types.
139 // continue adding end-list tokens until the stack count
140 // and the indent level are the same.
145 $return .= $this->wiki
->addToken(
149 'level' => count($stack)
156 // add the line text.
160 // the last line may have been indented. go through the stack
161 // and create end-tokens until the stack is empty.
164 while (count($stack) > 0) {
166 $return .= $this->wiki
->addToken(
170 'level' => count($stack)
175 // we're done! send back the replacement text.
176 return "\n$return\n\n";