Przeglądaj źródła

Fix: List item should not be converted in disallowed by schema context.

Oskar Wróbel 8 lat temu
rodzic
commit
e1aab73d9d

+ 16 - 3
packages/ckeditor5-list/src/converters.js

@@ -369,9 +369,17 @@ export function viewModelConverter( evt, data, conversionApi ) {
 		// `listItem`s created recursively should have bigger indent.
 		conversionStore.indent++;
 
-		writer.insert( listItem, data.modelCursor );
+		// Try to find allowed parent for list item.
+		const splitResult = conversionApi.splitToAllowedParent( listItem, data.modelCursor );
 
-		// Remember position after list item.
+		// When there is no allowed parent it means that list item can not be converted at current modelCursor.
+		if ( !splitResult ) {
+			return;
+		}
+
+		writer.insert( listItem, splitResult.position );
+
+		// Remember position after list item, next list items will be inserted at this position.
 		let nextPosition = ModelPosition.createAfter( listItem );
 
 		// Check all children of the converted `<li>`.
@@ -391,7 +399,12 @@ export function viewModelConverter( evt, data, conversionApi ) {
 		conversionStore.indent--;
 
 		data.modelRange = new ModelRange( data.modelCursor, nextPosition );
-		data.modelCursor = data.modelRange.end;
+
+		if ( splitResult.cursorParent ) {
+			data.modelCursor = ModelPosition.createAt( splitResult.cursorParent );
+		} else {
+			data.modelCursor = data.modelRange.end;
+		}
 	}
 }
 

+ 12 - 0
packages/ckeditor5-list/tests/listengine.js

@@ -3427,6 +3427,18 @@ describe( 'ListEngine', () => {
 				.to.equal( '<ul><li>Foo<span></span><ul><li>Xxx</li><li>Yyy</li></ul></li></ul>' );
 		} );
 
+		it( 'list should be not converted in disallowed context', () => {
+			model.document.createRoot( '$title', 'title' );
+			model.schema.register( '$title', {
+				disallow: '$block',
+				allow: 'inline'
+			} );
+
+			const data = editor.data;
+
+			expect( data.stringify( data.parse( '<ul><li>foo</li></ul>', [ 'title' ] ) ) ).to.equal( '' );
+		} );
+
 		describe( 'remove converter should properly handle ui elements', () => {
 			let uiElement, liFoo, liBar;