Browse Source

Add mention attribute to the schema.

Maciej Gołaszewski 6 years ago
parent
commit
a2c4fece14

+ 10 - 0
packages/ckeditor5-mention/src/mentionediting.js

@@ -21,4 +21,14 @@ export default class MentionEditing extends Plugin {
 	static get pluginName() {
 	static get pluginName() {
 		return 'MentionEditing';
 		return 'MentionEditing';
 	}
 	}
+
+	/**
+	 * @inheritDoc
+	 */
+	init() {
+		const editor = this.editor;
+
+		// Allow fontSize attribute on text nodes.
+		editor.model.schema.extend( '$text', { allowAttributes: 'mention' } );
+	}
 }
 }

+ 14 - 0
packages/ckeditor5-mention/tests/mentionediting.js

@@ -21,6 +21,20 @@ describe( 'MentionEditing', () => {
 					expect( newEditor.plugins.get( MentionEditing ) ).to.be.instanceOf( MentionEditing );
 					expect( newEditor.plugins.get( MentionEditing ) ).to.be.instanceOf( MentionEditing );
 				} );
 				} );
 		} );
 		} );
+
+		it( 'should set proper schema rules', () => {
+			return createTestEditor()
+				.then( newEditor => {
+					const model = newEditor.model;
+
+					expect( model.schema.checkAttribute( [ '$root', '$text' ], 'mention' ) ).to.be.true;
+
+					expect( model.schema.checkAttribute( [ '$block', '$text' ], 'mention' ) ).to.be.true;
+					expect( model.schema.checkAttribute( [ '$clipboardHolder', '$text' ], 'mention' ) ).to.be.true;
+
+					expect( model.schema.checkAttribute( [ '$block' ], 'mention' ) ).to.be.false;
+				} );
+		} );
 	} );
 	} );
 
 
 	function createTestEditor( mentionConfig ) {
 	function createTestEditor( mentionConfig ) {