XW-1429 | remove whitespace after original marker and put a single space after new marker position

This commit is contained in:
Igor Rogatty 2016-05-09 15:14:02 +02:00
parent bc7f3efb35
commit 3ef5a8e72b
2 changed files with 6 additions and 17 deletions

View file

@ -136,19 +136,9 @@ class PortableInfoboxParserTagController extends WikiaController {
// Skip if the first marker is already at the top
if ( strpos( $text, $firstMarker ) !== 0 ) {
$firstMarkerWithFollowingWhitespace = '';
$text = preg_replace_callback(
'/(' . $firstMarker . ')\s*/',
function ( $matches ) use ( &$firstMarkerWithFollowingWhitespace ) {
$firstMarkerWithFollowingWhitespace = $matches[0];
return '';
},
$text,
1
);
$text = $firstMarkerWithFollowingWhitespace . $text;
// Remove first marker and the following whitespace
$text = preg_replace( '/' . $firstMarker . '\s*/', '', $text, 1 );
$text = $firstMarker . ' ' . $text;
}
}
}

View file

@ -276,8 +276,8 @@ class PortableInfoboxParserTagControllerTest extends WikiaBaseTest {
'infobox-1' => '1'
],
'text' => 'nospaceinfobox-1',
'expected' => 'infobox-1nospace',
'message' => 'no space between elements'
'expected' => 'infobox-1 nospace',
'message' => 'no space between input elements'
],
[
'markers' => [
@ -290,8 +290,7 @@ class PortableInfoboxParserTagControllerTest extends WikiaBaseTest {
more text
infobox-2
and some more',
'expected' => 'infobox-1
some text
'expected' => 'infobox-1 some text
some more
more text
infobox-2