0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2024-12-31 11:54:03 -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>? // Have we replaced the previous block with a new <ul>/<ol>?
if ( ( prev = node.previousSibling ) && if ( ( prev = node.previousSibling ) && prev.nodeName === type ) {
prev.nodeName === type ) {
prev.appendChild( newLi ); prev.appendChild( newLi );
detach( node );
} }
// Otherwise, replace this block with the <ul>/<ol> // Otherwise, replace this block with the <ul>/<ol>
else { else {
@ -3736,7 +3736,8 @@ var makeList = function ( self, frag, type ) {
]) ])
); );
} }
newLi.appendChild( node ); newLi.appendChild( empty( node ) );
walker.currentNode = newLi;
} else { } else {
node = node.parentNode.parentNode; node = node.parentNode.parentNode;
tag = node.nodeName; tag = node.nodeName;
@ -3762,18 +3763,26 @@ var makeOrderedList = function ( frag ) {
var removeList = function ( frag ) { var removeList = function ( frag ) {
var lists = frag.querySelectorAll( 'UL, OL' ), var lists = frag.querySelectorAll( 'UL, OL' ),
items = frag.querySelectorAll( 'LI' ), items = frag.querySelectorAll( 'LI' ),
root = this._root,
i, l, list, listFrag, item; i, l, list, listFrag, item;
for ( i = 0, l = lists.length; i < l; i += 1 ) { for ( i = 0, l = lists.length; i < l; i += 1 ) {
list = lists[i]; list = lists[i];
listFrag = empty( list ); listFrag = empty( list );
fixContainer( listFrag, this._root ); fixContainer( listFrag, root );
replaceWith( list, listFrag ); replaceWith( list, listFrag );
} }
for ( i = 0, l = items.length; i < l; i += 1 ) { for ( i = 0, l = items.length; i < l; i += 1 ) {
item = items[i]; item = items[i];
if ( isBlock( item ) ) {
replaceWith( item,
this.createDefaultBlock([ empty( item ) ])
);
} else {
fixContainer( item, root );
replaceWith( item, empty( item ) ); replaceWith( item, empty( item ) );
} }
}
return frag; 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>? // Have we replaced the previous block with a new <ul>/<ol>?
if ( ( prev = node.previousSibling ) && if ( ( prev = node.previousSibling ) && prev.nodeName === type ) {
prev.nodeName === type ) {
prev.appendChild( newLi ); prev.appendChild( newLi );
detach( node );
} }
// Otherwise, replace this block with the <ul>/<ol> // Otherwise, replace this block with the <ul>/<ol>
else { else {
@ -1381,7 +1381,8 @@ var makeList = function ( self, frag, type ) {
]) ])
); );
} }
newLi.appendChild( node ); newLi.appendChild( empty( node ) );
walker.currentNode = newLi;
} else { } else {
node = node.parentNode.parentNode; node = node.parentNode.parentNode;
tag = node.nodeName; tag = node.nodeName;
@ -1407,18 +1408,26 @@ var makeOrderedList = function ( frag ) {
var removeList = function ( frag ) { var removeList = function ( frag ) {
var lists = frag.querySelectorAll( 'UL, OL' ), var lists = frag.querySelectorAll( 'UL, OL' ),
items = frag.querySelectorAll( 'LI' ), items = frag.querySelectorAll( 'LI' ),
root = this._root,
i, l, list, listFrag, item; i, l, list, listFrag, item;
for ( i = 0, l = lists.length; i < l; i += 1 ) { for ( i = 0, l = lists.length; i < l; i += 1 ) {
list = lists[i]; list = lists[i];
listFrag = empty( list ); listFrag = empty( list );
fixContainer( listFrag, this._root ); fixContainer( listFrag, root );
replaceWith( list, listFrag ); replaceWith( list, listFrag );
} }
for ( i = 0, l = items.length; i < l; i += 1 ) { for ( i = 0, l = items.length; i < l; i += 1 ) {
item = items[i]; item = items[i];
if ( isBlock( item ) ) {
replaceWith( item,
this.createDefaultBlock([ empty( item ) ])
);
} else {
fixContainer( item, root );
replaceWith( item, empty( item ) ); replaceWith( item, empty( item ) );
} }
}
return frag; return frag;
}; };