Merge "Improve unwrapFragment() for multi-paragraph comments"

This commit is contained in:
jenkins-bot 2024-06-22 09:48:56 +00:00 committed by Gerrit Code Review
commit 7281eec5b2
2 changed files with 24 additions and 1 deletions

View file

@ -346,7 +346,13 @@ class CommentModifier {
while (
static::allOfType( $fragment->childNodes, 'dl' ) ||
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
$childNodeList = iterator_to_array( $fragment->childNodes );

View file

@ -124,6 +124,23 @@ class CommentModifierTest extends IntegrationTestCase {
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
*/