0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2024-12-22 07:13:08 -05:00

Replace block node when creating list

So you get:

<li>Text</li>

instead of

<li><p>Text</p></li>
This commit is contained in:
Neil Jenkins 2016-09-27 06:06:42 +04:00
parent 6a9582c7e7
commit 0fa4a9b587
3 changed files with 30 additions and 12 deletions

View file

@ -3723,9 +3723,9 @@ var makeList = function ( self, frag, type ) {
}
// Have we replaced the previous block with a new <ul>/<ol>?
if ( ( prev = node.previousSibling ) &&
prev.nodeName === type ) {
if ( ( prev = node.previousSibling ) && prev.nodeName === type ) {
prev.appendChild( newLi );
detach( node );
}
// Otherwise, replace this block with the <ul>/<ol>
else {
@ -3736,7 +3736,8 @@ var makeList = function ( self, frag, type ) {
])
);
}
newLi.appendChild( node );
newLi.appendChild( empty( node ) );
walker.currentNode = newLi;
} else {
node = node.parentNode.parentNode;
tag = node.nodeName;
@ -3762,17 +3763,25 @@ var makeOrderedList = function ( frag ) {
var removeList = function ( frag ) {
var lists = frag.querySelectorAll( 'UL, OL' ),
items = frag.querySelectorAll( 'LI' ),
root = this._root,
i, l, list, listFrag, item;
for ( i = 0, l = lists.length; i < l; i += 1 ) {
list = lists[i];
listFrag = empty( list );
fixContainer( listFrag, this._root );
fixContainer( listFrag, root );
replaceWith( list, listFrag );
}
for ( i = 0, l = items.length; i < l; i += 1 ) {
item = items[i];
replaceWith( item, empty( item ) );
if ( isBlock( item ) ) {
replaceWith( item,
this.createDefaultBlock([ empty( item ) ])
);
} else {
fixContainer( item, root );
replaceWith( item, empty( item ) );
}
}
return frag;
};

File diff suppressed because one or more lines are too long

View file

@ -1368,9 +1368,9 @@ var makeList = function ( self, frag, type ) {
}
// Have we replaced the previous block with a new <ul>/<ol>?
if ( ( prev = node.previousSibling ) &&
prev.nodeName === type ) {
if ( ( prev = node.previousSibling ) && prev.nodeName === type ) {
prev.appendChild( newLi );
detach( node );
}
// Otherwise, replace this block with the <ul>/<ol>
else {
@ -1381,7 +1381,8 @@ var makeList = function ( self, frag, type ) {
])
);
}
newLi.appendChild( node );
newLi.appendChild( empty( node ) );
walker.currentNode = newLi;
} else {
node = node.parentNode.parentNode;
tag = node.nodeName;
@ -1407,17 +1408,25 @@ var makeOrderedList = function ( frag ) {
var removeList = function ( frag ) {
var lists = frag.querySelectorAll( 'UL, OL' ),
items = frag.querySelectorAll( 'LI' ),
root = this._root,
i, l, list, listFrag, item;
for ( i = 0, l = lists.length; i < l; i += 1 ) {
list = lists[i];
listFrag = empty( list );
fixContainer( listFrag, this._root );
fixContainer( listFrag, root );
replaceWith( list, listFrag );
}
for ( i = 0, l = items.length; i < l; i += 1 ) {
item = items[i];
replaceWith( item, empty( item ) );
if ( isBlock( item ) ) {
replaceWith( item,
this.createDefaultBlock([ empty( item ) ])
);
} else {
fixContainer( item, root );
replaceWith( item, empty( item ) );
}
}
return frag;
};