131 // second pass, separate items and tokens |
131 // second pass, separate items and tokens |
132 unset($items_pre); |
132 unset($items_pre); |
133 foreach ( $items as $item ) |
133 foreach ( $items as $item ) |
134 { |
134 { |
135 // get the depth |
135 // get the depth |
136 $itemtoken = preg_replace('/[^#:\*].*$/', '', $item); |
136 $itemtoken = preg_replace('/^([#:\*]+).*$/s', '$1', $item); |
137 // get the text |
137 // get the text |
138 $itemtext = trim(substr($item, strlen($itemtoken))); |
138 $itemtext = trim(substr($item, strlen($itemtoken))); |
139 $piece['items'][] = array( |
139 $piece['items'][] = array( |
140 // depth starts at 1 |
140 // depth starts at 1 |
141 'depth' => strlen($itemtoken), |
141 'depth' => strlen($itemtoken), |
142 'text' => $itemtext |
142 'text' => $itemtext |
143 ); |
143 ); |
144 } |
144 } |
145 |
|
146 $pieces[] = $piece; |
145 $pieces[] = $piece; |
147 } |
146 } |
148 |
147 |
149 $text = Carpenter::tokenize($text, $lists[0]); |
148 $text = Carpenter::tokenize($text, $lists[0]); |
150 |
149 |
|
150 return $pieces; |
|
151 } |
|
152 |
|
153 public function blockquote(&$text) |
|
154 { |
|
155 if ( !preg_match_all('/^(?:(>+) *.+(?:\r?\n|$))+/m', $text, $quotes) ) |
|
156 return array(); |
|
157 |
|
158 $pieces = array(); |
|
159 foreach ( $quotes[0] as $quote ) |
|
160 $pieces[] = "\t" . trim(preg_replace('/^>+ */m', "\t", $quote)); |
|
161 |
|
162 $text = Carpenter::tokenize($text, $quotes[0]); |
151 return $pieces; |
163 return $pieces; |
152 } |
164 } |
153 |
165 |
154 public function paragraph(&$text) |
166 public function paragraph(&$text) |
155 { |
167 { |
156 // The trick with paragraphs is to not turn things into them when a block level element already wraps the block of text. |
168 // The trick with paragraphs is to not turn things into them when a block level element already wraps the block of text. |
157 // First we need a list of block level elements (http://htmlhelp.com/reference/html40/block.html + some Enano extensions) |
169 // First we need a list of block level elements (http://htmlhelp.com/reference/html40/block.html + some Enano extensions) |
158 $blocklevel = 'address|blockquote|center|code|div|dl|fieldset|form|h1|h2|h3|h4|h5|h6|hr|li|ol|p|pre|table|ul|tr|td|th|tbody|thead|tfoot'; |
170 $blocklevel = 'address|blockquote|center|code|div|dl|fieldset|form|h1|h2|h3|h4|h5|h6|hr|li|ol|p|pre|table|ul|tr|td|th|tbody|thead|tfoot'; |
159 |
171 |
160 // Wrap all block level tags |
172 // Wrap all block level tags |
|
173 RenderMan::tag_strip('_paragraph_bypass', $text, $_nw); |
161 $text = preg_replace("/<($blocklevel)(?: .+?>|>)(?:(?R)|.*?)<\/\\1>/s", '<_paragraph_bypass>$0</_paragraph_bypass>', $text); |
174 $text = preg_replace("/<($blocklevel)(?: .+?>|>)(?:(?R)|.*?)<\/\\1>/s", '<_paragraph_bypass>$0</_paragraph_bypass>', $text); |
|
175 RenderMan::tag_unstrip('_paragraph_bypass', $text, $_nw, true); |
162 |
176 |
163 // This is potentially a hack. It allows the parser to stick in <_paragraph_bypass> tags |
177 // This is potentially a hack. It allows the parser to stick in <_paragraph_bypass> tags |
164 // to prevent the paragraph parser from interfering with pretty HTML generated elsewhere. |
178 // to prevent the paragraph parser from interfering with pretty HTML generated elsewhere. |
165 RenderMan::tag_strip('_paragraph_bypass', $text, $_nw); |
179 RenderMan::tag_strip('_paragraph_bypass', $text, $_nw); |
166 |
180 |