diff --git a/src/converters.js b/src/converters.js index 463c8fe..4ca2824 100644 --- a/src/converters.js +++ b/src/converters.js @@ -365,22 +365,19 @@ export function modelViewMergeAfter( evt, data, conversionApi ) { export function viewModelConverter( evt, data, conversionApi ) { if ( conversionApi.consumable.consume( data.viewItem, { name: true } ) ) { const writer = conversionApi.writer; - const conversionStore = this.conversionApi.store; // 1. Create `listItem` model element. const listItem = writer.createElement( 'listItem' ); // 2. Handle `listItem` model element attributes. - conversionStore.indent = conversionStore.indent || 0; - writer.setAttribute( 'listIndent', conversionStore.indent, listItem ); + const indent = getIndent( data.viewItem ); + + writer.setAttribute( 'listIndent', indent, listItem ); // Set 'bulleted' as default. If this item is pasted into a context, const type = data.viewItem.parent && data.viewItem.parent.name == 'ol' ? 'numbered' : 'bulleted'; writer.setAttribute( 'listType', type, listItem ); - // `listItem`s created recursively should have bigger indent. - conversionStore.indent++; - // Try to find allowed parent for list item. const splitResult = conversionApi.splitToAllowedParent( listItem, data.modelCursor ); @@ -394,8 +391,6 @@ export function viewModelConverter( evt, data, conversionApi ) { const nextPosition = viewToModelListItemChildrenConverter( listItem, data.viewItem.getChildren(), conversionApi ); - conversionStore.indent--; - // Result range starts before the first item and ends after the last. data.modelRange = writer.createRange( data.modelCursor, nextPosition ); @@ -426,7 +421,9 @@ export function cleanList( evt, data, conversionApi ) { const children = Array.from( data.viewItem.getChildren() ); for ( const child of children ) { - if ( !child.is( 'li' ) ) { + const isWrongElement = !( child.is( 'li' ) || isList( child ) ); + + if ( isWrongElement ) { child._remove(); } } @@ -453,7 +450,7 @@ export function cleanListItem( evt, data, conversionApi ) { let firstNode = true; for ( const child of children ) { - if ( foundList && !child.is( 'ul' ) && !child.is( 'ol' ) ) { + if ( foundList && !isList( child ) ) { child._remove(); } @@ -464,10 +461,10 @@ export function cleanListItem( evt, data, conversionApi ) { } // If this is the last text node before