8
0
Oskar Wróbel 6 лет назад
Родитель
Сommit
1537137f25
2 измененных файлов с 10 добавлено и 6 удалено
  1. 7 0
      packages/ckeditor5-heading/src/title.js
  2. 3 6
      packages/ckeditor5-heading/tests/title.js

+ 7 - 0
packages/ckeditor5-heading/src/title.js

@@ -65,6 +65,13 @@ export default class Title extends Plugin {
 			}
 			}
 		} );
 		} );
 
 
+		// Disallow all attributes in title.
+		model.schema.addAttributeCheck( context => {
+			if ( context.endsWith( 'title $text' ) ) {
+				return false;
+			}
+		} );
+
 		editor.conversion.elementToElement( { model: 'title', view: 'h1' } );
 		editor.conversion.elementToElement( { model: 'title', view: 'h1' } );
 
 
 		// Create and take care about proper position of a title element.
 		// Create and take care about proper position of a title element.

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

@@ -55,6 +55,8 @@ describe( 'Title', () => {
 		expect( model.schema.checkChild( [ '$root' ], 'title' ) ).to.equal( true );
 		expect( model.schema.checkChild( [ '$root' ], 'title' ) ).to.equal( true );
 		expect( model.schema.checkChild( [ '$root', 'blockQuote' ], 'title' ) ).to.equal( false );
 		expect( model.schema.checkChild( [ '$root', 'blockQuote' ], 'title' ) ).to.equal( false );
 		expect( model.schema.checkChild( [ '$root', 'paragraph' ], 'title' ) ).to.equal( false );
 		expect( model.schema.checkChild( [ '$root', 'paragraph' ], 'title' ) ).to.equal( false );
+		expect( model.schema.checkAttribute( [ 'title', '$text' ], 'bold' ) ).to.equal( false );
+		expect( model.schema.checkAttribute( [ 'title', '$text' ], 'foo' ) ).to.equal( false );
 	} );
 	} );
 
 
 	it( 'should convert title to h1', () => {
 	it( 'should convert title to h1', () => {
@@ -130,13 +132,8 @@ describe( 'Title', () => {
 			expect( getData( model ) ).to.equal( '<title>[]</title><blockQuote><paragraph>Foo</paragraph></blockQuote>' );
 			expect( getData( model ) ).to.equal( '<title>[]</title><blockQuote><paragraph>Foo</paragraph></blockQuote>' );
 		} );
 		} );
 
 
-		it( 'should clear element from disallowed attributes when changing to title element', () => {
+		it( 'should clear element from attributes when changing to title element', () => {
 			model.schema.extend( '$text', { allowAttributes: 'bold' } );
 			model.schema.extend( '$text', { allowAttributes: 'bold' } );
-			model.schema.addAttributeCheck( ( context, attributeName ) => {
-				if ( context.endsWith( 'title $text' ) && attributeName === 'bold' ) {
-					return false;
-				}
-			} );
 
 
 			setData( model,
 			setData( model,
 				'<paragraph>F<$text bold="true">o</$text>o</paragraph><paragraph>B<$text bold="true">a</$text>r</paragraph>'
 				'<paragraph>F<$text bold="true">o</$text>o</paragraph><paragraph>B<$text bold="true">a</$text>r</paragraph>'