diff --git a/includes/CommentModifier.php b/includes/CommentModifier.php index a05501f9d..9fba59e7b 100644 --- a/includes/CommentModifier.php +++ b/includes/CommentModifier.php @@ -237,25 +237,29 @@ class CommentModifier { // and start a new paragraph after if ( self::isBlockElement( $list->firstChild->firstChild ) ) { if ( $p->firstChild ) { - $container->insertBefore( $p, $referenceNode->nextSibling ); + $insertBefore = $referenceNode->nextSibling; $referenceNode = $p; + $container->insertBefore( $p, $insertBefore ); } - $container->insertBefore( $list->firstChild->firstChild, $referenceNode->nextSibling ); + $insertBefore = $referenceNode->nextSibling; $referenceNode = $list->firstChild->firstChild; + $container->insertBefore( $list->firstChild->firstChild, $insertBefore ); $p = $doc->createElement( 'p' ); } else { $p->appendChild( $list->firstChild->firstChild ); } } if ( $p->firstChild ) { - $container->insertBefore( $p, $referenceNode->nextSibling ); + $insertBefore = $referenceNode->nextSibling; $referenceNode = $p; + $container->insertBefore( $p, $insertBefore ); } $list->removeChild( $list->firstChild ); } else { // Text node / comment node, probably empty - $container->insertBefore( $list->firstChild, $referenceNode->nextSibling ); + $insertBefore = $referenceNode->nextSibling; $referenceNode = $list->firstChild; + $container->insertBefore( $list->firstChild, $insertBefore ); } } $container->removeChild( $list ); diff --git a/modules/modifier.js b/modules/modifier.js index 0ebd61589..3e776a4a8 100644 --- a/modules/modifier.js +++ b/modules/modifier.js @@ -217,7 +217,7 @@ function removeAddedListItem( node ) { * @param {HTMLElement} list List element (dl/ol/ul) */ function unwrapList( list ) { - var p, + var p, insertBefore, doc = list.ownerDocument, container = list.parentNode, referenceNode = list; @@ -236,25 +236,29 @@ function unwrapList( list ) { // and start a new paragraph after if ( ve.isBlockElement( list.firstChild.firstChild ) ) { if ( p.firstChild ) { - container.insertBefore( p, referenceNode.nextSibling ); + insertBefore = referenceNode.nextSibling; referenceNode = p; + container.insertBefore( p, insertBefore ); } - container.insertBefore( list.firstChild.firstChild, referenceNode.nextSibling ); + insertBefore = referenceNode.nextSibling; referenceNode = list.firstChild.firstChild; + container.insertBefore( list.firstChild.firstChild, insertBefore ); p = doc.createElement( 'p' ); } else { p.appendChild( list.firstChild.firstChild ); } } if ( p.firstChild ) { - container.insertBefore( p, referenceNode.nextSibling ); + insertBefore = referenceNode.nextSibling; referenceNode = p; + container.insertBefore( p, insertBefore ); } list.removeChild( list.firstChild ); } else { // Text node / comment node, probably empty - container.insertBefore( list.firstChild, referenceNode.nextSibling ); + insertBefore = referenceNode.nextSibling; referenceNode = list.firstChild; + container.insertBefore( list.firstChild, insertBefore ); } } container.removeChild( list ); diff --git a/tests/cases/unwrap.json b/tests/cases/unwrap.json index d2a88059d..35b9cce16 100644 --- a/tests/cases/unwrap.json +++ b/tests/cases/unwrap.json @@ -41,6 +41,12 @@ "index": 0, "expected": "

Foo

Bar

" }, + { + "name": "multiple items with whitespace", + "html": "
\n
Foo
\n
Bar
\n
", + "index": 0, + "expected": "\n

Foo

\n

Bar

\n" + }, { "name": "nested list", "html": "
Foo
Bar
", diff --git a/tests/qunit/modifier.test.js b/tests/qunit/modifier.test.js index 2f6c3e8e0..7cf44c967 100644 --- a/tests/qunit/modifier.test.js +++ b/tests/qunit/modifier.test.js @@ -124,7 +124,7 @@ QUnit.test( '#unwrapList', function ( assert ) { modifier.unwrapList( container.childNodes[ caseItem.index || 0 ] ); assert.strictEqual( - container.innerHTML.trim(), + container.innerHTML, caseItem.expected, caseItem.name );