X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Flist%2Fplugin.js;h=be747020723e065c34dfb27c4874567f6c33899e;hb=8665a7c6c60586526e32e8941fe2896739b6ebfb;hp=e37a9b1faf2a9009268a8d5deb91872b9b6e15e5;hpb=941b0a9ba4e673e292510d80a5a86806994b8ea6;p=ckeditor.git diff --git a/_source/plugins/list/plugin.js b/_source/plugins/list/plugin.js index e37a9b1..be74702 100644 --- a/_source/plugins/list/plugin.js +++ b/_source/plugins/list/plugin.js @@ -29,7 +29,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license if ( !baseArray ) baseArray = []; - // Iterate over all list items to get their contents and look for inner lists. + // Iterate over all list items to and look for inner lists. for ( var i = 0, count = listNode.getChildCount() ; i < count ; i++ ) { var listItem = listNode.getChild( i ); @@ -37,7 +37,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // It may be a text node or some funny stuff. if ( listItem.$.nodeName.toLowerCase() != 'li' ) continue; - var itemObj = { 'parent' : listNode, indent : baseIndentLevel, contents : [] }; + + var itemObj = { 'parent' : listNode, indent : baseIndentLevel, element : listItem, contents : [] }; if ( !grandparentNode ) { itemObj.grandparent = listNode.getParent(); @@ -51,9 +52,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license CKEDITOR.dom.element.setMarker( database, listItem, 'listarray_index', baseArray.length ); baseArray.push( itemObj ); - for ( var j = 0, itemChildCount = listItem.getChildCount() ; j < itemChildCount ; j++ ) + for ( var j = 0, itemChildCount = listItem.getChildCount(), child; j < itemChildCount ; j++ ) { - var child = listItem.getChild( j ); + child = listItem.getChild( j ); if ( child.type == CKEDITOR.NODE_ELEMENT && listNodeNames[ child.getName() ] ) // Note the recursion here, it pushes inner list items with // +1 indentation in the correct order. @@ -89,7 +90,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license rootNode = listArray[ currentIndex ].parent.clone( false, true ); retval.append( rootNode ); } - currentListItem = rootNode.append( doc.createElement( 'li' ) ); + currentListItem = rootNode.append( item.element.clone( false, true ) ); for ( var i = 0 ; i < item.contents.length ; i++ ) currentListItem.append( item.contents[i].clone( true, true ) ); currentIndex++; @@ -104,9 +105,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { currentListItem; if ( listNodeNames[ item.grandparent.getName() ] ) - currentListItem = doc.createElement( 'li' ); + currentListItem = item.element.clone( false, true ); else { + // Create completely new blocks here, attributes are dropped. if ( paragraphMode != CKEDITOR.ENTER_BR && item.grandparent.getName() != 'td' ) currentListItem = doc.createElement( paragraphName ); else @@ -232,6 +234,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license newList.listNode.replace( groupObj.root ); } + var headerTagRegex = /^h[1-6]$/; + function createList( editor, groupObj, listsCreated ) { var contents = groupObj.contents, @@ -283,8 +287,17 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { var contentBlock = listContents.shift(), listItem = doc.createElement( 'li' ); - contentBlock.moveChildren( listItem ); - contentBlock.remove(); + + // Preserve heading structure when converting to list item. (#5271) + if ( headerTagRegex.test( contentBlock.getName() ) ) + contentBlock.appendTo( listItem ); + else + { + contentBlock.copyAttributes( listItem ); + contentBlock.moveChildren( listItem ); + contentBlock.remove(); + } + listItem.appendTo( listNode ); // Append a bogus BR to force the LI to render at full height @@ -570,7 +583,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license nodeBefore = firstNestedList && firstNestedList.previous, tailNbspmatch; - if( nodeBefore + if ( nodeBefore && ( nodeBefore.name && nodeBefore.name == 'br' || nodeBefore.value && ( tailNbspmatch = nodeBefore.value.match( tailNbspRegex ) ) ) ) { @@ -594,11 +607,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license } var defaultListDataFilterRules = { elements : {} }; - for( var i in dtd.$listItem ) + for ( var i in dtd.$listItem ) defaultListDataFilterRules.elements[ i ] = getExtendNestedListFilter(); var defaultListHtmlFilterRules = { elements : {} }; - for( i in dtd.$listItem ) + for ( i in dtd.$listItem ) defaultListHtmlFilterRules.elements[ i ] = getExtendNestedListFilter( true ); CKEDITOR.plugins.add( 'list', @@ -631,7 +644,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license afterInit : function ( editor ) { var dataProcessor = editor.dataProcessor; - if( dataProcessor ) + if ( dataProcessor ) { dataProcessor.dataFilter.addRules( defaultListDataFilterRules ); dataProcessor.htmlFilter.addRules( defaultListHtmlFilterRules );