diff --git a/src/Cite.php b/src/Cite.php index f5e41613b..5a89d6263 100644 --- a/src/Cite.php +++ b/src/Cite.php @@ -513,9 +513,9 @@ class Cite { $s = ''; foreach ( $this->referenceStack->getGroups() as $group ) { if ( $group === self::DEFAULT_GROUP || $isSectionPreview ) { - $s .= "\n" . $this->formatReferences( $parser, $group ); + $s .= $this->formatReferences( $parser, $group ); } else { - $s .= "\n
" . $this->errorReporter->halfParsed( + $s .= '
' . $this->errorReporter->halfParsed( $parser, 'cite_error_group_refs_without_references', Sanitizer::safeEncodeAttribute( $group ) @@ -532,13 +532,13 @@ class Cite { ) . $s; } // provide a preview of references in its own section - $s = "\n" . Html::rawElement( + $s = Html::rawElement( 'div', [ 'class' => 'mw-ext-cite-cite_section_preview_references' ], $s ); } - return $s; + return $s !== '' ? "\n" . $s : ''; } /** diff --git a/tests/phpunit/CiteIntegrationTest.php b/tests/phpunit/CiteIntegrationTest.php index aadfdcdf7..a6bb08e9d 100644 --- a/tests/phpunit/CiteIntegrationTest.php +++ b/tests/phpunit/CiteIntegrationTest.php @@ -68,14 +68,14 @@ class CiteIntegrationTest extends \MediaWikiIntegrationTestCase { 'Default group' => [ [ '' => [ [ 'name' => 'a' ] ] ], false, - "\n" . '' + "\n" ], 'Default group in preview' => [ [ '' => [ [ 'name' => 'a' ] ] ], true, "\n" . '
' . '

' . - '(cite_section_preview_references)

' . "\n" . '
' + '(cite_section_preview_references)' ], 'Named group' => [ [ 'foo' => [ [ 'name' => 'a' ] ] ], @@ -87,7 +87,7 @@ class CiteIntegrationTest extends \MediaWikiIntegrationTestCase { true, "\n" . '
' . '

' . - '(cite_section_preview_references)

' . "\n" . '
' + '(cite_section_preview_references)' ] ]; }