author | Dan |
Wed, 13 May 2009 09:41:24 -0400 | |
changeset 968 | 105a24b4de8f |
parent 32 | 4d87aad3c4c0 |
permissions | -rw-r--r-- |
1 | 1 |
<?php |
2 |
||
3 |
/** |
|
4 |
* |
|
5 |
* Parses for paragraph blocks. |
|
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: Paragraph.php,v 1.3 2005/02/23 17:38:29 pmjones Exp $ |
|
16 |
* |
|
17 |
*/ |
|
18 |
||
19 |
/** |
|
20 |
* |
|
21 |
* Parses for paragraph blocks. |
|
22 |
* |
|
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. |
|
26 |
* |
|
27 |
* @category Text |
|
28 |
* |
|
29 |
* @package Text_Wiki |
|
30 |
* |
|
31 |
* @author Paul M. Jones <pmjones@php.net> |
|
32 |
* |
|
33 |
*/ |
|
34 |
||
35 |
class Text_Wiki_Parse_Paragraph extends Text_Wiki_Parse { |
|
36 |
||
37 |
/** |
|
38 |
* |
|
39 |
* The regular expression used to find source text matching this |
|
40 |
* rule. |
|
41 |
* |
|
42 |
* @access public |
|
43 |
* |
|
44 |
* @var string |
|
45 |
* |
|
46 |
*/ |
|
47 |
||
48 |
var $regex = "/^.*?\n\n/m"; |
|
49 |
||
50 |
var $conf = array( |
|
51 |
'skip' => array( |
|
52 |
'blockquote', // are we sure about this one? |
|
53 |
'code', |
|
54 |
'heading', |
|
55 |
'horiz', |
|
56 |
'deflist', |
|
57 |
'table', |
|
58 |
'list', |
|
32
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
59 |
'toc', |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
60 |
'pre' |
1 | 61 |
) |
62 |
); |
|
63 |
||
64 |
||
65 |
/** |
|
66 |
* |
|
67 |
* Generates a token entry for the matched text. Token options are: |
|
68 |
* |
|
69 |
* 'start' => The starting point of the paragraph. |
|
70 |
* |
|
71 |
* 'end' => The ending point of the paragraph. |
|
72 |
* |
|
73 |
* @access public |
|
74 |
* |
|
75 |
* @param array &$matches The array of matches from parse(). |
|
76 |
* |
|
77 |
* @return A delimited token number to be used as a placeholder in |
|
78 |
* the source text. |
|
79 |
* |
|
80 |
*/ |
|
81 |
||
82 |
function process(&$matches) |
|
83 |
{ |
|
84 |
$delim = $this->wiki->delim; |
|
85 |
||
86 |
// was anything there? |
|
87 |
if (trim($matches[0]) == '') { |
|
88 |
return ''; |
|
89 |
} |
|
90 |
||
91 |
// does the match start with a delimiter? |
|
92 |
if (substr($matches[0], 0, 1) != $delim) { |
|
93 |
// no. |
|
94 |
||
95 |
$start = $this->wiki->addToken( |
|
96 |
$this->rule, array('type' => 'start') |
|
97 |
); |
|
98 |
||
99 |
$end = $this->wiki->addToken( |
|
100 |
$this->rule, array('type' => 'end') |
|
101 |
); |
|
102 |
||
103 |
return $start . trim($matches[0]) . $end; |
|
104 |
} |
|
105 |
||
106 |
// the line starts with a delimiter. read in the delimited |
|
107 |
// token number, check the token, and see if we should |
|
108 |
// skip it. |
|
109 |
||
110 |
// loop starting at the second character (we already know |
|
111 |
// the first is a delimiter) until we find another |
|
112 |
// delimiter; the text between them is a token key number. |
|
113 |
$key = ''; |
|
114 |
$len = strlen($matches[0]); |
|
115 |
for ($i = 1; $i < $len; $i++) { |
|
116 |
$char = $matches[0]{$i}; |
|
117 |
if ($char == $delim) { |
|
118 |
break; |
|
119 |
} else { |
|
120 |
$key .= $char; |
|
121 |
} |
|
122 |
} |
|
123 |
||
124 |
// look at the token and see if it's skippable (if we skip, |
|
125 |
// it will not be marked as a paragraph) |
|
126 |
$token_type = strtolower($this->wiki->tokens[$key][0]); |
|
127 |
$skip = $this->getConf('skip', array()); |
|
128 |
||
129 |
if (in_array($token_type, $skip)) { |
|
130 |
// this type of token should not have paragraphs applied to it. |
|
131 |
// return the entire matched text. |
|
132 |
return $matches[0]; |
|
133 |
} else { |
|
134 |
||
135 |
$start = $this->wiki->addToken( |
|
136 |
$this->rule, array('type' => 'start') |
|
137 |
); |
|
138 |
||
139 |
$end = $this->wiki->addToken( |
|
140 |
$this->rule, array('type' => 'end') |
|
141 |
); |
|
142 |
||
143 |
return $start . trim($matches[0]) . $end; |
|
144 |
} |
|
145 |
} |
|
32
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
146 |
|
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
147 |
/** |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
148 |
* |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
149 |
* Abstrct method to parse source text for matches. |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
150 |
* |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
151 |
* Applies the rule's regular expression to the source text, passes |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
152 |
* every match to the process() method, and replaces the matched text |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
153 |
* with the results of the processing. |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
154 |
* |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
155 |
* @access public |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
156 |
* |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
157 |
* @see Text_Wiki_Parse::process() |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
158 |
* |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
159 |
*/ |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
160 |
|
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
161 |
function parse() |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
162 |
{ |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
163 |
$source =& $this->wiki->source; |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
164 |
$source = wikiformat_process_block($source); |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
165 |
|
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
166 |
$source = preg_replace('/<litewiki>(.*?)<\/litewiki>([\s]+?|$)/is', '<litewiki>\\1\\2</litewiki>', $source); |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
167 |
|
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
168 |
// die('<pre>' . htmlspecialchars($source) . '</pre>'); |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
169 |
|
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
170 |
$this->wiki->source = preg_replace_callback( |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
171 |
$this->regex, |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
172 |
array(&$this, 'process'), |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
173 |
$this->wiki->source |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
174 |
); |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
175 |
|
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
176 |
$source = preg_replace('/<litewiki>(.*?)<\/litewiki>/is', '\\1', $source); |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
177 |
} |
1 | 178 |
} |
179 |
?> |