/*\r
-Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.\r
+Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.\r
For licensing, see LICENSE.html or http://ckeditor.com/license\r
*/\r
\r
if ( !baseArray )\r
baseArray = [];\r
\r
- // Iterate over all list items to get their contents and look for inner lists.\r
+ // Iterate over all list items to and look for inner lists.\r
for ( var i = 0, count = listNode.getChildCount() ; i < count ; i++ )\r
{\r
var listItem = listNode.getChild( i );\r
// It may be a text node or some funny stuff.\r
if ( listItem.$.nodeName.toLowerCase() != 'li' )\r
continue;\r
- var itemObj = { 'parent' : listNode, indent : baseIndentLevel, contents : [] };\r
+\r
+ var itemObj = { 'parent' : listNode, indent : baseIndentLevel, element : listItem, contents : [] };\r
if ( !grandparentNode )\r
{\r
itemObj.grandparent = listNode.getParent();\r
CKEDITOR.dom.element.setMarker( database, listItem, 'listarray_index', baseArray.length );\r
baseArray.push( itemObj );\r
\r
- for ( var j = 0, itemChildCount = listItem.getChildCount() ; j < itemChildCount ; j++ )\r
+ for ( var j = 0, itemChildCount = listItem.getChildCount(), child; j < itemChildCount ; j++ )\r
{\r
- var child = listItem.getChild( j );\r
+ child = listItem.getChild( j );\r
if ( child.type == CKEDITOR.NODE_ELEMENT && listNodeNames[ child.getName() ] )\r
// Note the recursion here, it pushes inner list items with\r
// +1 indentation in the correct order.\r
rootNode = listArray[ currentIndex ].parent.clone( false, true );\r
retval.append( rootNode );\r
}\r
- currentListItem = rootNode.append( doc.createElement( 'li' ) );\r
+ currentListItem = rootNode.append( item.element.clone( false, true ) );\r
for ( var i = 0 ; i < item.contents.length ; i++ )\r
currentListItem.append( item.contents[i].clone( true, true ) );\r
currentIndex++;\r
{\r
currentListItem;\r
if ( listNodeNames[ item.grandparent.getName() ] )\r
- currentListItem = doc.createElement( 'li' );\r
+ currentListItem = item.element.clone( false, true );\r
else\r
{\r
+ // Create completely new blocks here, attributes are dropped.\r
if ( paragraphMode != CKEDITOR.ENTER_BR && item.grandparent.getName() != 'td' )\r
currentListItem = doc.createElement( paragraphName );\r
else\r
newList.listNode.replace( groupObj.root );\r
}\r
\r
+ var headerTagRegex = /^h[1-6]$/;\r
+\r
function createList( editor, groupObj, listsCreated )\r
{\r
var contents = groupObj.contents,\r
{\r
var contentBlock = listContents.shift(),\r
listItem = doc.createElement( 'li' );\r
- contentBlock.moveChildren( listItem );\r
- contentBlock.remove();\r
+\r
+ // Preserve heading structure when converting to list item. (#5271)\r
+ if ( headerTagRegex.test( contentBlock.getName() ) )\r
+ contentBlock.appendTo( listItem );\r
+ else\r
+ {\r
+ contentBlock.copyAttributes( listItem );\r
+ contentBlock.moveChildren( listItem );\r
+ contentBlock.remove();\r
+ }\r
+\r
listItem.appendTo( listNode );\r
\r
// Append a bogus BR to force the LI to render at full height\r
compensateBrs( true );\r
compensateBrs();\r
\r
- var rootParent = groupObj.root.getParent();\r
docFragment.replace( groupObj.root );\r
}\r
\r
while ( ( block = iterator.getNextParagraph() ) )\r
{\r
var path = new CKEDITOR.dom.elementPath( block ),\r
+ pathElements = path.elements,\r
+ pathElementsCount = pathElements.length,\r
listNode = null,\r
processedFlag = false,\r
blockLimit = path.blockLimit,\r
element;\r
\r
// First, try to group by a list ancestor.\r
- for ( var i = 0 ; i < path.elements.length &&\r
- ( element = path.elements[ i ] ) && !element.equals( blockLimit ); i++ )\r
+ for ( var i = pathElementsCount - 1; i >= 0 && ( element = pathElements[ i ] ); i-- )\r
{\r
- if ( listNodeNames[ element.getName() ] )\r
+ if ( listNodeNames[ element.getName() ]\r
+ && blockLimit.contains( element ) ) // Don't leak outside block limit (#3940).\r
{\r
// If we've encountered a list inside a block limit\r
// The last group object of the block limit element should\r
}\r
};\r
\r
+ var dtd = CKEDITOR.dtd;\r
+ var tailNbspRegex = /[\t\r\n ]*(?: |\xa0)$/;\r
+\r
+ function indexOfFirstChildElement( element, tagNameList )\r
+ {\r
+ var child,\r
+ children = element.children,\r
+ length = children.length;\r
+\r
+ for ( var i = 0 ; i < length ; i++ )\r
+ {\r
+ child = children[ i ];\r
+ if ( child.name && ( child.name in tagNameList ) )\r
+ return i;\r
+ }\r
+\r
+ return length;\r
+ }\r
+\r
+ function getExtendNestedListFilter( isHtmlFilter )\r
+ {\r
+ // An element filter function that corrects nested list start in an empty\r
+ // list item for better displaying/outputting. (#3165)\r
+ return function( listItem )\r
+ {\r
+ var children = listItem.children,\r
+ firstNestedListIndex = indexOfFirstChildElement( listItem, dtd.$list ),\r
+ firstNestedList = children[ firstNestedListIndex ],\r
+ nodeBefore = firstNestedList && firstNestedList.previous,\r
+ tailNbspmatch;\r
+\r
+ if ( nodeBefore\r
+ && ( nodeBefore.name && nodeBefore.name == 'br'\r
+ || nodeBefore.value && ( tailNbspmatch = nodeBefore.value.match( tailNbspRegex ) ) ) )\r
+ {\r
+ var fillerNode = nodeBefore;\r
+\r
+ // Always use 'nbsp' as filler node if we found a nested list appear\r
+ // in front of a list item.\r
+ if ( !( tailNbspmatch && tailNbspmatch.index ) && fillerNode == children[ 0 ] )\r
+ children[ 0 ] = ( isHtmlFilter || CKEDITOR.env.ie ) ?\r
+ new CKEDITOR.htmlParser.text( '\xa0' ) :\r
+ new CKEDITOR.htmlParser.element( 'br', {} );\r
+\r
+ // Otherwise the filler is not needed anymore.\r
+ else if ( fillerNode.name == 'br' )\r
+ children.splice( firstNestedListIndex - 1, 1 );\r
+ else\r
+ fillerNode.value = fillerNode.value.replace( tailNbspRegex, '' );\r
+ }\r
+\r
+ };\r
+ }\r
+\r
+ var defaultListDataFilterRules = { elements : {} };\r
+ for ( var i in dtd.$listItem )\r
+ defaultListDataFilterRules.elements[ i ] = getExtendNestedListFilter();\r
+\r
+ var defaultListHtmlFilterRules = { elements : {} };\r
+ for ( i in dtd.$listItem )\r
+ defaultListHtmlFilterRules.elements[ i ] = getExtendNestedListFilter( true );\r
+\r
CKEDITOR.plugins.add( 'list',\r
{\r
init : function( editor )\r
editor.on( 'selectionChange', CKEDITOR.tools.bind( onSelectionChange, bulletedListCommand ) );\r
},\r
\r
+ afterInit : function ( editor )\r
+ {\r
+ var dataProcessor = editor.dataProcessor;\r
+ if ( dataProcessor )\r
+ {\r
+ dataProcessor.dataFilter.addRules( defaultListDataFilterRules );\r
+ dataProcessor.htmlFilter.addRules( defaultListHtmlFilterRules );\r
+ }\r
+ },\r
+\r
requires : [ 'domiterator' ]\r
} );\r
})();\r