5 * Parses for paragraph blocks.
11 * @author Paul M. Jones <pmjones@php.net>
15 * @version $Id: Paragraph.php,v 1.3 2005/02/23 17:38:29 pmjones Exp $
21 * Parses for paragraph blocks.
23 * This class implements a Text_Wiki rule to find sections of the source
24 * text that are paragraphs. A para is any line not starting with a token
25 * delimiter, followed by two newlines.
31 * @author Paul M. Jones <pmjones@php.net>
35 class Text_Wiki_Parse_Paragraph
extends Text_Wiki_Parse
{
39 * The regular expression used to find source text matching this
48 var $regex = "/^.*?\n\n/m";
52 'blockquote', // are we sure about this one?
66 * Generates a token entry for the matched text. Token options are:
68 * 'start' => The starting point of the paragraph.
70 * 'end' => The ending point of the paragraph.
74 * @param array &$matches The array of matches from parse().
76 * @return A delimited token number to be used as a placeholder in
81 function process(&$matches)
83 $delim = $this->wiki
->delim
;
85 // was anything there?
86 if (trim($matches[0]) == '') {
90 // does the match start with a delimiter?
91 if (substr($matches[0], 0, 1) != $delim) {
94 $start = $this->wiki
->addToken(
95 $this->rule
, array('type' => 'start')
98 $end = $this->wiki
->addToken(
99 $this->rule
, array('type' => 'end')
102 return $start . trim($matches[0]) . $end;
105 // the line starts with a delimiter. read in the delimited
106 // token number, check the token, and see if we should
109 // loop starting at the second character (we already know
110 // the first is a delimiter) until we find another
111 // delimiter; the text between them is a token key number.
113 $len = strlen($matches[0]);
114 for ($i = 1; $i < $len; $i++
) {
115 $char = $matches[0]{$i};
116 if ($char == $delim) {
123 // look at the token and see if it's skippable (if we skip,
124 // it will not be marked as a paragraph)
125 $token_type = strtolower($this->wiki
->tokens
[$key][0]);
126 $skip = $this->getConf('skip', array());
128 if (in_array($token_type, $skip)) {
129 // this type of token should not have paragraphs applied to it.
130 // return the entire matched text.
134 $start = $this->wiki
->addToken(
135 $this->rule
, array('type' => 'start')
138 $end = $this->wiki
->addToken(
139 $this->rule
, array('type' => 'end')
142 return $start . trim($matches[0]) . $end;