瀏覽代碼

Added missing headings to the list title-like elements. Changed the list to a static class property.

Oskar Wróbel 6 年之前
父節點
當前提交
87293a44d9
共有 2 個文件被更改,包括 18 次插入18 次删除
  1. 10 4
      packages/ckeditor5-heading/src/title.js
  2. 8 14
      packages/ckeditor5-heading/tests/title.js

+ 10 - 4
packages/ckeditor5-heading/src/title.js

@@ -18,9 +18,6 @@ import {
 	enablePlaceholder
 } from '@ckeditor/ckeditor5-engine/src/view/placeholder';
 
-// List of model elements that are allowed to be renamed to title element.
-const allowedToBeTitle = new Set( [ 'heading1', 'heading2', 'heading3', 'paragraph' ] );
-
 /**
  * The Title plugin.
  *
@@ -242,7 +239,7 @@ export default class Title extends Plugin {
 				const title = this._getTitleElement();
 
 				// Change first element to the title if it can be a title.
-				if ( allowedToBeTitle.has( rootChild.name ) ) {
+				if ( Title.titleLikeElements.has( rootChild.name ) ) {
 					const position = model.createPositionBefore( rootChild );
 					const title = writer.createElement( 'title' );
 
@@ -422,6 +419,15 @@ export default class Title extends Plugin {
 	}
 }
 
+/**
+ * A list of element names which should be treated by the Title plugin as
+ * title-like. This means that element on the list will be changed to the title
+ * element when will be the first element in the root.
+ *
+ * @member {Set.<String>} module:heading/title~Title.titleLikeElements
+ */
+Title.titleLikeElements = new Set( [ 'paragraph', 'heading1', 'heading2', 'heading3', 'heading4', 'heading5', 'heading6' ] );
+
 function mapModelPositionToView( editingView ) {
 	return ( evt, data ) => {
 		if ( !data.modelPosition.parent.is( 'title' ) ) {

+ 8 - 14
packages/ckeditor5-heading/tests/title.js

@@ -124,28 +124,22 @@ describe( 'Title', () => {
 			);
 		} );
 
-		it( 'should change heading2 element to title when is set as a first root child', () => {
+		it( 'should change paragraph element to title when is set as a first root child', () => {
 			setData( model,
-				'<heading2>Foo</heading2>' +
-				'<heading2>Bar</heading2>'
+				'<paragraph>Foo</paragraph>' +
+				'<paragraph>Bar</paragraph>'
 			);
 
 			expect( getData( model ) ).to.equal(
 				'<title><title-content>[]Foo</title-content></title>' +
-				'<heading2>Bar</heading2>'
+				'<paragraph>Bar</paragraph>'
 			);
 		} );
 
-		it( 'should change heading3 element to title when is set as a first root child', () => {
-			setData( model,
-				'<heading3>Foo</heading3>' +
-				'<heading3>Bar</heading3>'
-			);
-
-			expect( getData( model ) ).to.equal(
-				'<title><title-content>[]Foo</title-content></title>' +
-				'<heading3>Bar</heading3>'
-			);
+		it( 'should have list of title-like elements', () => {
+			expect( Array.from( Title.titleLikeElements ) ).to.have.members( [
+				'paragraph', 'heading1', 'heading2', 'heading3', 'heading4', 'heading5', 'heading6'
+			] );
 		} );
 
 		it( 'should change paragraph element to title when is set as a first root child', () => {