Browse Source

Simplified schema rules.

Oskar Wróbel 6 years ago
parent
commit
e0baf90e7c
2 changed files with 9 additions and 27 deletions
  1. 3 20
      packages/ckeditor5-heading/src/title.js
  2. 6 7
      packages/ckeditor5-heading/tests/title.js

+ 3 - 20
packages/ckeditor5-heading/src/title.js

@@ -64,26 +64,9 @@ export default class Title extends Plugin {
 		// </title>
 		//
 		// See: https://github.com/ckeditor/ckeditor5/issues/2005.
-		model.schema.register( 'title', { inheritAllFrom: '$block' } );
-		model.schema.register( 'title-content', {
-			inheritAllFrom: '$block',
-			allowIn: 'title'
-		} );
-
-		model.schema.addChildCheck( ( context, childDefinition ) => {
-			// Allow `title` element only directly inside a root.
-			if ( childDefinition.name === 'title' && !context.endsWith( '$root' ) ) {
-				return false;
-			}
-
-			// Allow only `title-content` inside `title`.
-			if (
-				context.endsWith( 'title' ) && childDefinition.name !== 'title-content' ||
-				childDefinition.name === 'title-content' && !context.endsWith( 'title' )
-			) {
-				return false;
-			}
-		} );
+		model.schema.register( 'title', { isBlock: true, allowIn: '$root' } );
+		model.schema.register( 'title-content', { isBlock: true, allowIn: 'title' } );
+		model.schema.extend( '$text', { allowIn: 'title-content' } );
 
 		// Disallow all attributes in `title-content`.
 		model.schema.addAttributeCheck( context => {

+ 6 - 7
packages/ckeditor5-heading/tests/title.js

@@ -49,19 +49,18 @@ describe( 'Title', () => {
 
 	it( 'should set proper schema rules', () => {
 		expect( model.schema.isRegistered( 'title' ) ).to.equal( true );
+		expect( model.schema.isBlock( 'title' ) ).to.equal( true );
 		expect( model.schema.isRegistered( 'title-content' ) ).to.equal( true );
+		expect( model.schema.isBlock( 'title-content' ) ).to.equal( true );
 
 		expect( model.schema.checkChild( 'title', '$text' ) ).to.equal( false );
-		expect( model.schema.checkChild( 'title', 'paragraph' ) ).to.equal( false );
+		expect( model.schema.checkChild( 'title', '$block' ) ).to.equal( false );
 		expect( model.schema.checkChild( 'title', 'title-content' ) ).to.equal( true );
 		expect( model.schema.checkChild( '$root', 'title-content' ) ).to.equal( false );
-		expect( model.schema.checkChild( 'blockQuote', 'title-content' ) ).to.equal( false );
-		expect( model.schema.checkChild( 'title-content', '$text' ) ).to.equal( true );
-		expect( model.schema.checkChild( 'title-content', 'paragraph' ) ).to.equal( false );
-		expect( model.schema.checkChild( 'title-content', 'blockQuote' ) ).to.equal( false );
 		expect( model.schema.checkChild( '$root', 'title' ) ).to.equal( true );
-		expect( model.schema.checkChild( 'blockQuote', 'title' ) ).to.equal( false );
-		expect( model.schema.checkChild( 'paragraph', 'title' ) ).to.equal( false );
+		expect( model.schema.checkChild( '$block', 'title-content' ) ).to.equal( false );
+		expect( model.schema.checkChild( 'title-content', '$text' ) ).to.equal( true );
+		expect( model.schema.checkChild( 'title-content', '$block' ) ).to.equal( false );
 
 		model.schema.extend( '$text', { allowAttributes: [ 'bold', 'foo' ] } );