Index: trunk/phase3/maintenance/parserTests.txt |
— | — | @@ -7148,7 +7148,121 @@ |
7149 | 7149 | </p> |
7150 | 7150 | !! end |
7151 | 7151 | |
| 7152 | +!!test |
| 7153 | +<poem> |
| 7154 | +!!input |
| 7155 | +<poem> |
| 7156 | +this |
| 7157 | +is |
| 7158 | +a |
| 7159 | +test |
| 7160 | +</poem> |
| 7161 | +!!result |
| 7162 | +<div class="poem"> |
| 7163 | +<p>this<br /> |
| 7164 | +is<br /> |
| 7165 | +a<br /> |
| 7166 | +test |
| 7167 | +</p> |
| 7168 | +</div> |
7152 | 7169 | |
| 7170 | +!!end |
| 7171 | + |
| 7172 | +!!test |
| 7173 | + <poem> with recursive parsing |
| 7174 | +!!input |
| 7175 | +<poem> |
| 7176 | +this ''is'' a '''test''' |
| 7177 | +</poem> |
| 7178 | +!! result |
| 7179 | +<div class="poem"> |
| 7180 | +<p>this <i>is</i> a <b>test</b> |
| 7181 | +</p> |
| 7182 | +</div> |
| 7183 | + |
| 7184 | +!!end |
| 7185 | + |
| 7186 | + |
| 7187 | +!!test |
| 7188 | + <poem> with leading whitespace |
| 7189 | +!!input |
| 7190 | +<poem> |
| 7191 | + |
| 7192 | + test |
| 7193 | + |
| 7194 | +</poem> |
| 7195 | +!!result |
| 7196 | +<div class="poem"> |
| 7197 | +<p><br /> |
| 7198 | + test<br /> |
| 7199 | +</p> |
| 7200 | +</div> |
| 7201 | + |
| 7202 | +!!end |
| 7203 | + |
| 7204 | +!!test |
| 7205 | +Horizontal rule |
| 7206 | +!!input |
| 7207 | +<poem> |
| 7208 | +some |
| 7209 | +----- |
| 7210 | +text |
| 7211 | +</poem> |
| 7212 | +!!result |
| 7213 | +<div class="poem"> |
| 7214 | +<p>some<br /> |
| 7215 | +</p> |
| 7216 | +<hr /><br /> |
| 7217 | +<p>text |
| 7218 | +</p> |
| 7219 | +</div> |
| 7220 | + |
| 7221 | +!!end |
| 7222 | + |
| 7223 | +!!test |
| 7224 | + nested <poem><nowiki> |
| 7225 | +!!input |
| 7226 | +<poem><nowiki> |
| 7227 | +this |
| 7228 | +is |
| 7229 | +a |
| 7230 | +test |
| 7231 | +</nowiki></poem> |
| 7232 | +!!result |
| 7233 | +<div class="poem"> |
| 7234 | +<p><br /> |
| 7235 | +this<br /> |
| 7236 | +is<br /> |
| 7237 | +a<br /> |
| 7238 | +test<br /> |
| 7239 | + |
| 7240 | +</p> |
| 7241 | +</div> |
| 7242 | + |
| 7243 | +!!end |
| 7244 | + |
| 7245 | +!!test |
| 7246 | + nested <poem><nowiki> with formatting |
| 7247 | +!!input |
| 7248 | +<poem><nowiki> |
| 7249 | +this |
| 7250 | +'''is''' |
| 7251 | +a |
| 7252 | +test |
| 7253 | +</nowiki></poem> |
| 7254 | +!!result |
| 7255 | +<div class="poem"> |
| 7256 | +<p><br /> |
| 7257 | +this<br /> |
| 7258 | +'''is'''<br /> |
| 7259 | +a<br /> |
| 7260 | +test<br /> |
| 7261 | + |
| 7262 | +</p> |
| 7263 | +</div> |
| 7264 | + |
| 7265 | +!! end |
| 7266 | + |
7153 | 7267 | # |
7154 | 7268 | # |
7155 | 7269 | # |
Index: trunk/phase3/includes/parser/Parser.php |
— | — | @@ -4183,34 +4183,42 @@ |
4184 | 4184 | * based on http://www.mediawiki.org/wiki/Extension:Poem |
4185 | 4185 | */ |
4186 | 4186 | |
4187 | | - function renderPoem( $in, $param=array() ) { |
| 4187 | + function renderPoem( $in, $param = array() ) { |
4188 | 4188 | |
4189 | 4189 | /* using newlines in the text will cause the parser to add <p> tags, |
4190 | 4190 | * which may not be desired in some cases |
4191 | 4191 | */ |
4192 | | - $nl = isset( $param['compact'] ) ? '' : "\n"; |
| 4192 | + $nl = array_key_exists( 'compact', $param ) ? '' : "\n"; |
4193 | 4193 | |
4194 | 4194 | $tag = $this->insertStripItem( "<br />", $this->mStripState ); |
4195 | | - $text = preg_replace( |
4196 | | - array( "/^\n/", "/\n$/D", "/\n/", "/^( +)/me" ), |
4197 | | - array( "", "", "$tag\n", "str_replace(' ',' ','\\1')" ), |
4198 | | - $in ); |
| 4195 | + // Only strip the very first and very last \n (which trim cannot do) |
| 4196 | + $text = $in; |
| 4197 | + if( substr( $in, 0, 1 ) == "\n" ) |
| 4198 | + $text = substr( $in, 1 ); |
| 4199 | + if( substr( $text, -1 ) == "\n" ) |
| 4200 | + $text = substr( $text, 0, -1 ); |
| 4201 | + |
| 4202 | + $text = str_replace( "\n", "$tag\n", $text ); |
| 4203 | + $text = preg_replace_callback( |
| 4204 | + "/^( +)/m", |
| 4205 | + create_function( |
| 4206 | + '$matches', |
| 4207 | + 'return str_replace(" ", " ", "$matches[0]");' |
| 4208 | + ), |
| 4209 | + $text ); |
4199 | 4210 | $text = $this->recursiveTagParse( $text ); |
4200 | 4211 | |
4201 | 4212 | // Pass HTML attributes through to the output. |
4202 | 4213 | $attribs = Sanitizer::validateTagAttributes( $param, 'div' ); |
4203 | 4214 | |
4204 | 4215 | // Wrap output in a <div> with "poem" class. |
4205 | | - if( isset( $attribs['class'] ) ) { |
| 4216 | + if( array_key_exists( 'class', $attribs ) ) { |
4206 | 4217 | $attribs['class'] = 'poem ' . $attribs['class']; |
4207 | 4218 | } else { |
4208 | 4219 | $attribs['class'] = 'poem'; |
4209 | 4220 | } |
4210 | 4221 | |
4211 | | - return wfOpenElement( 'div', $attribs ) . |
4212 | | - $nl . |
4213 | | - trim( $text ) . |
4214 | | - "$nl</div>"; |
| 4222 | + return XML::openElement( 'div', $attribs ) . $nl . trim( $text ) . $nl . XML::closeElement( 'div' ); |
4215 | 4223 | } |
4216 | 4224 | |
4217 | 4225 | function getImageParams( $handler ) { |