浏览代码

Added v -> m converter for h2 and h3 elements.

Oskar Wróbel 6 年之前
父节点
当前提交
2574c2a16f
共有 2 个文件被更改,包括 21 次插入1 次删除
  1. 2 0
      packages/ckeditor5-heading/src/title.js
  2. 19 1
      packages/ckeditor5-heading/tests/title.js

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

@@ -91,6 +91,8 @@ export default class Title extends Plugin {
 		// Custom converter is used for data v -> m conversion to avoid calling post-fixer when setting data.
 		// See https://github.com/ckeditor/ckeditor5/issues/2036.
 		editor.data.upcastDispatcher.on( 'element:h1', dataViewModelH1Insertion, { priority: 'high' } );
+		editor.data.upcastDispatcher.on( 'element:h2', dataViewModelH1Insertion, { priority: 'high' } );
+		editor.data.upcastDispatcher.on( 'element:h3', dataViewModelH1Insertion, { priority: 'high' } );
 
 		// Take care about correct `title` element structure.
 		model.document.registerPostFixer( writer => this._fixTitleContent( writer ) );

+ 19 - 1
packages/ckeditor5-heading/tests/title.js

@@ -86,7 +86,7 @@ describe( 'Title', () => {
 		);
 	} );
 
-	it( 'should avoid calling post-fixers to parse view to correct model', () => {
+	it( 'should avoid calling post-fixers to parse view to correct model (h1)', () => {
 		const modelFrag = editor.data.parse( '<h1>Foo</h1><p>Bar</p>' );
 
 		expect( stringify( modelFrag ) ).to.equal(
@@ -95,6 +95,24 @@ describe( 'Title', () => {
 		);
 	} );
 
+	it( 'should avoid calling post-fixers to parse view to correct model (h2)', () => {
+		const modelFrag = editor.data.parse( '<h2>Foo</h2><p>Bar</p>' );
+
+		expect( stringify( modelFrag ) ).to.equal(
+			'<title><title-content>Foo</title-content></title>' +
+			'<paragraph>Bar</paragraph>'
+		);
+	} );
+
+	it( 'should avoid calling post-fixers to parse view to correct model (h3)', () => {
+		const modelFrag = editor.data.parse( '<h3>Foo</h3><p>Bar</p>' );
+
+		expect( stringify( modelFrag ) ).to.equal(
+			'<title><title-content>Foo</title-content></title>' +
+			'<paragraph>Bar</paragraph>'
+		);
+	} );
+
 	it( 'should allow to override custom v->m title converter', () => {
 		const spy = sinon.spy();