mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-13 18:37:07 +00:00
Merge "Improve unwrapFragment() for multi-paragraph comments"
This commit is contained in:
commit
7281eec5b2
|
@ -346,7 +346,13 @@ class CommentModifier {
|
||||||
while (
|
while (
|
||||||
static::allOfType( $fragment->childNodes, 'dl' ) ||
|
static::allOfType( $fragment->childNodes, 'dl' ) ||
|
||||||
static::allOfType( $fragment->childNodes, 'ul' ) ||
|
static::allOfType( $fragment->childNodes, 'ul' ) ||
|
||||||
static::allOfType( $fragment->childNodes, 'ol' )
|
static::allOfType( $fragment->childNodes, 'ol' ) ||
|
||||||
|
(
|
||||||
|
// Or if the comment starts with a bullet followed by indents
|
||||||
|
count( $fragment->childNodes ) > 1 &&
|
||||||
|
static::allOfType( [ $fragment->childNodes[0] ], 'ul' ) &&
|
||||||
|
static::allOfType( array_slice( iterator_to_array( $fragment->childNodes ), 1 ), 'dl' )
|
||||||
|
)
|
||||||
) {
|
) {
|
||||||
// Do not iterate over childNodes while we're modifying it
|
// Do not iterate over childNodes while we're modifying it
|
||||||
$childNodeList = iterator_to_array( $fragment->childNodes );
|
$childNodeList = iterator_to_array( $fragment->childNodes );
|
||||||
|
|
|
@ -124,6 +124,23 @@ class CommentModifierTest extends IntegrationTestCase {
|
||||||
return static::getJson( '../cases/unwrap.json' );
|
return static::getJson( '../cases/unwrap.json' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider provideUnwrapFragment
|
||||||
|
*/
|
||||||
|
public function testUnwrapFragment( string $html, string $expected ): void {
|
||||||
|
$doc = static::createDocument( '' );
|
||||||
|
$container = DOMUtils::parseHTMLToFragment( $doc, $html );
|
||||||
|
CommentModifier::unwrapFragment( $container );
|
||||||
|
static::assertEquals( $expected, DOMUtils::getFragmentInnerHTML( $container ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function provideUnwrapFragment() {
|
||||||
|
yield [
|
||||||
|
"<ul><li>aaa</li></ul>\n<dl><dd>bbb</dd></dl>",
|
||||||
|
"<p>aaa</p>\n<p>bbb</p>",
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider provideAppendSignature
|
* @dataProvider provideAppendSignature
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue