mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-15 02:55:04 +00:00
Don't leave unclosed <li> behind
This fixes a FIXME I left in the code. Previously, I just stripped the closing </li> to make sure the nested <ol> is *inside* of the <li>. This relies on (Remex) Tidy to clean the incomplete HTML up. This patch remembers the stripped </li> and adds it back. This also makes sure the nested <ol> is closed, even if it was the last element in the data structure. Notice how this does not influence any test. I find this a bit confusing. It looks like (Remex) Tidy is executed, even if the tests are not marked as "html/php+tidy". Bug: T237241 Change-Id: Idb804df46dc24406d6bba40414675b6ff4812d48
This commit is contained in:
parent
f24f77d4c4
commit
3cf1e99cc2
|
@ -67,20 +67,21 @@ class FootnoteBodyFormatter {
|
|||
$indented = false;
|
||||
foreach ( $groupRefs as $key => $value ) {
|
||||
// FIXME: This assumes extended references appear immediately after their parent in the
|
||||
// array. Reorder the refs according to their stored numbering.
|
||||
// data structure. Reorder the refs according to their stored numbering.
|
||||
if ( !$indented && isset( $value['extends'] ) ) {
|
||||
// Hack: The nested <ol> needs to go inside of the <li>.
|
||||
$parserInput = preg_replace( '/<\/li>\s*$/', '', $parserInput );
|
||||
// The nested <ol> must be inside the parent's <li>
|
||||
if ( preg_match( '#</li>\s*$#D', $parserInput, $matches, PREG_OFFSET_CAPTURE ) ) {
|
||||
$parserInput = substr( $parserInput, 0, $matches[0][1] );
|
||||
}
|
||||
$parserInput .= Html::openElement( 'ol', [ 'class' => 'mw-extended-references' ] );
|
||||
$indented = true;
|
||||
$indented = $matches[0][0] ?? true;
|
||||
} elseif ( $indented && !isset( $value['extends'] ) ) {
|
||||
// FIXME: This is't closed if there is no unindented element at the end
|
||||
$parserInput .= Html::closeElement( 'ol' );
|
||||
$parserInput .= $this->closeIndention( $indented );
|
||||
$indented = false;
|
||||
}
|
||||
$parserInput .= $this->referencesFormatEntry(
|
||||
$key, $value, $isSectionPreview ) . "\n";
|
||||
$parserInput .= $this->referencesFormatEntry( $key, $value, $isSectionPreview ) . "\n";
|
||||
}
|
||||
$parserInput .= $this->closeIndention( $indented );
|
||||
$parserInput = Html::rawElement( 'ol', [ 'class' => [ 'references' ] ], $parserInput );
|
||||
// Live hack: parse() adds two newlines on WM, can't reproduce it locally -ævar
|
||||
$ret = rtrim( $this->parser->recursiveTagParse( $parserInput ), "\n" );
|
||||
|
@ -98,6 +99,19 @@ class FootnoteBodyFormatter {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|bool $closingLi
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function closeIndention( $closingLi ) : string {
|
||||
if ( !$closingLi ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return Html::closeElement( 'ol' ) . ( is_string( $closingLi ) ? $closingLi : '' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a single entry for the referencesFormat() function
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue