Index: trunk/extensions/LabeledSectionTransclusion/lstParserTests.txt |
— | — | @@ -391,3 +391,45 @@ |
392 | 392 | <p>junk |
393 | 393 | </p> |
394 | 394 | !!end |
| 395 | + |
| 396 | +!!article |
| 397 | +fromsection |
| 398 | +!!text |
| 399 | +Before... |
| 400 | +<section begin="A"/>SectionA<section end="A"/> |
| 401 | +<section begin="B"/>SectionB<section end="B"/> |
| 402 | +<section begin="C"/>SectionC<section end="C"/> |
| 403 | +...After |
| 404 | +!!endarticle |
| 405 | +!!test |
| 406 | +LST: inclusion starting at a specified section till the end of article |
| 407 | +!!options |
| 408 | +!!input |
| 409 | +{{#lst:fromsection|B|}} |
| 410 | +!!result |
| 411 | +<p>SectionB |
| 412 | +SectionC |
| 413 | +...After |
| 414 | +</p> |
| 415 | +!!end |
| 416 | + |
| 417 | +!!article |
| 418 | +tosection |
| 419 | +!!text |
| 420 | +Before... |
| 421 | +<section begin="A"/>SectionA<section end="A"/> |
| 422 | +<section begin="B"/>SectionB<section end="B"/> |
| 423 | +<section begin="C"/>SectionC<section end="C"/> |
| 424 | +...After |
| 425 | +!!endarticle |
| 426 | +!!test |
| 427 | +LST: inclusion from beginning of article to a specified section |
| 428 | +!!options |
| 429 | +!!input |
| 430 | +{{#lst:tosection||B}} |
| 431 | +!!result |
| 432 | +<p>Before... |
| 433 | +SectionA |
| 434 | +SectionB |
| 435 | +</p> |
| 436 | +!!end |
Index: trunk/extensions/LabeledSectionTransclusion/lst.php |
— | — | @@ -322,7 +322,7 @@ |
323 | 323 | $endAttr = self::getAttrPattern_( $end, 'end' ); |
324 | 324 | $endRegex = "/^$endAttr$/s"; |
325 | 325 | |
326 | | - return compact( 'dom', 'root', 'newFrame', 'repl', 'beginRegex', 'endRegex' ); |
| 326 | + return compact( 'dom', 'root', 'newFrame', 'repl', 'beginRegex', 'begin', 'endRegex' ); |
327 | 327 | } |
328 | 328 | |
329 | 329 | /** |
— | — | @@ -359,24 +359,28 @@ |
360 | 360 | $text = ''; |
361 | 361 | $node = $root->getFirstChild(); |
362 | 362 | while ( $node ) { |
363 | | - // Find the begin node |
364 | | - $found = false; |
365 | | - for ( ; $node; $node = $node->getNextSibling() ) { |
366 | | - if ( $node->getName() != 'ext' ) { |
367 | | - continue; |
368 | | - } |
369 | | - $parts = $node->splitExt(); |
370 | | - $parts = array_map( array( $newFrame, 'expand' ), $parts ); |
371 | | - if ( self::isSection( $parts['name'] ) ) { |
372 | | - if ( preg_match( $beginRegex, $parts['attr'] ) ) { |
373 | | - $found = true; |
374 | | - break; |
| 363 | + // If name of begin node was specified find it |
| 364 | + // otherwise transclude everything from the beginning of the page |
| 365 | + if ( $begin != '' ) { |
| 366 | + // Find the begin node |
| 367 | + $found = false; |
| 368 | + for ( ; $node; $node = $node->getNextSibling() ) { |
| 369 | + if ( $node->getName() != 'ext' ) { |
| 370 | + continue; |
375 | 371 | } |
| 372 | + $parts = $node->splitExt(); |
| 373 | + $parts = array_map( array( $newFrame, 'expand' ), $parts ); |
| 374 | + if ( self::isSection( $parts['name'] ) ) { |
| 375 | + if ( preg_match( $beginRegex, $parts['attr'] ) ) { |
| 376 | + $found = true; |
| 377 | + break; |
| 378 | + } |
| 379 | + } |
376 | 380 | } |
| 381 | + if ( !$found || !$node ) { |
| 382 | + break; |
| 383 | + } |
377 | 384 | } |
378 | | - if ( !$found || !$node ) { |
379 | | - break; |
380 | | - } |
381 | 385 | |
382 | 386 | // Write the text out while looking for the end node |
383 | 387 | $found = false; |
— | — | @@ -399,7 +403,13 @@ |
400 | 404 | } |
401 | 405 | if ( !$found ) { |
402 | 406 | break; |
| 407 | + } else if ( $begin == '' ) { |
| 408 | + // When end node was found and |
| 409 | + // text is transcluded from the beginning of the page |
| 410 | + // finish the transclusion |
| 411 | + break; |
403 | 412 | } |
| 413 | + |
404 | 414 | $node = $node->getNextSibling(); |
405 | 415 | } |
406 | 416 | return $text; |