Browse Source

Brought back a handler for a strange case when data.output can be an array.

Piotrek Koszuliński 9 years ago
parent
commit
47c946a55c

+ 10 - 2
packages/ckeditor5-paragraph/src/paragraph.js

@@ -19,6 +19,8 @@ import modelWriter from '../engine/model/writer.js';
 import buildModelConverter from '../engine/conversion/buildmodelconverter.js';
 import buildViewConverter from '../engine/conversion/buildviewconverter.js';
 
+import isArray from '../utils/lib/lodash/isArray.js';
+
 /**
  * The paragraph feature for the editor.
  * Introduces the `<paragraph>` element in the model which renders as a `<p>` element in the DOM and data.
@@ -97,7 +99,7 @@ export default class Paragraph extends Plugin {
  *
  * @member {Set.<String>} module:paragraph/paragraph~Paragraph.paragraphLikeElements
  */
-Paragraph.paragraphLikeElements = new Set( [ 'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'td', 'li', 'div' ] );
+Paragraph.paragraphLikeElements = new Set( [ 'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'td', 'li', 'div', 'dt', 'dd' ] );
 
 const paragraphsToMerge = new WeakSet();
 
@@ -172,7 +174,13 @@ function autoparagraphParagraphLikeElements( doc, evt, data, consumable, convers
 
 // Merges subsequent paragraphs if they should be merged (see shouldMerge).
 function mergeSubsequentParagraphs( evt, data ) {
-	let node = data.output.getChild( 0 );
+	let node;
+
+	if ( isArray( data.output ) ) {
+		node = data.output[ 0 ];
+	} else {
+		node = data.output.getChild( 0 );
+	}
 
 	while ( node && node.nextSibling ) {
 		const nextSibling = node.nextSibling;

+ 14 - 0
packages/ckeditor5-paragraph/tests/paragraph.js

@@ -165,6 +165,20 @@ describe( 'Paragraph feature', () => {
 				expect( modelFragment.getChild( 0 ).childCount ).to.equal( 1 );
 				expect( modelFragment.getChild( 0 ).getChild( 0 ) ).to.be.instanceOf( ModelText );
 			} );
+
+			it( 'does not break converting inline elements', () => {
+				doc.schema.allow( { name: '$inline', attributes: [ 'bold' ] } );
+				buildViewConverter().for( editor.data.viewToModel )
+					.fromElement( 'b' )
+					.toAttribute( 'bold', true );
+
+				const modelFragment = editor.data.parse( 'foo<b>bar</b>bom' );
+
+				// The result of this test is wrong due to https://github.com/ckeditor/ckeditor5-paragraph/issues/10.
+				// It's meant to catch the odd situation in mergeSubsequentParagraphs when data.output may be an array
+				// for a while
+				expect( stringifyModel( modelFragment ) ).to.equal( '<paragraph>foobarbom</paragraph>' );
+			} );
 		} );
 
 		describe( 'generic block converter (paragraph-like element handling)', () => {