mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-12 01:16:19 +00:00
Fix whitespace handling in unwrapList
Update 'referenceNode' before modifying the DOM. Bug: T254308 Change-Id: I76af898e238c1e6d3db96d3e6156e80e55c87820
This commit is contained in:
parent
0d14fcea6a
commit
62c0080850
|
@ -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 );
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -41,6 +41,12 @@
|
|||
"index": 0,
|
||||
"expected": "<p>Foo</p><p>Bar</p>"
|
||||
},
|
||||
{
|
||||
"name": "multiple items with whitespace",
|
||||
"html": "<dl>\n<dd>Foo</dd>\n<dd>Bar</dd>\n</dl>",
|
||||
"index": 0,
|
||||
"expected": "\n<p>Foo</p>\n<p>Bar</p>\n"
|
||||
},
|
||||
{
|
||||
"name": "nested list",
|
||||
"html": "<dl><dd>Foo<dl><dd>Bar</dd></dl></dd></dl>",
|
||||
|
|
|
@ -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
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue