8
0
Pārlūkot izejas kodu

Merge pull request #64 from ckeditor/t/ckeditor5/1727

Other: New lines pasted as a plain text will always create a new paragraph. Closes ckeditor/ckeditor5#1727.

BREAKING CHANGE: From now on, every new line pasted in the editor as a plain text, will create a new paragraph. Read more at ckeditor/ckeditor5#1727.
Piotrek Koszuliński 6 gadi atpakaļ
vecāks
revīzija
bc56f071fd

+ 2 - 3
packages/ckeditor5-clipboard/src/utils/plaintexttohtml.js

@@ -18,9 +18,8 @@ export default function plainTextToHtml( text ) {
 		// Encode <>.
 		.replace( /</g, '&lt;' )
 		.replace( />/g, '&gt;' )
-		// Creates paragraphs for double line breaks and change single line breaks to <br>s.
-		.replace( /\n\n/g, '</p><p>' )
-		.replace( /\n/g, '<br>' )
+		// Creates paragraphs for every line breaks.
+		.replace( /\n/g, '</p><p>' )
 		// Preserve trailing spaces (only the first and last one – the rest is handled below).
 		.replace( /^\s/, '&nbsp;' )
 		.replace( /\s$/, '&nbsp;' )

+ 1 - 1
packages/ckeditor5-clipboard/tests/clipboard.js

@@ -111,7 +111,7 @@ describe( 'Clipboard feature', () => {
 				clipboardPlugin.on( 'inputTransformation', ( evt, data ) => {
 					expect( data.content ).is.instanceOf( ViewDocumentFragment );
 					expect( data.dataTransfer ).to.equal( dataTransferMock );
-					expect( stringifyView( data.content ) ).to.equal( '<p>x</p><p>y  z</p>' );
+					expect( stringifyView( data.content ) ).to.equal( '<p>x</p><p></p><p>y  z</p>' );
 
 					done();
 				} );

+ 6 - 11
packages/ckeditor5-clipboard/tests/utils/plaintexttohtml.js

@@ -10,21 +10,16 @@ describe( 'plainTextToHtml()', () => {
 		expect( plainTextToHtml( 'x y <z>' ) ).to.equal( 'x y &lt;z&gt;' );
 	} );
 
-	it( 'turns double line breaks into paragraphs', () => {
-		expect( plainTextToHtml( 'x\n\ny\n\nz' ) ).to.equal( '<p>x</p><p>y</p><p>z</p>' );
-	} );
-
-	it( 'turns single line breaks into <br>s', () => {
-		expect( plainTextToHtml( 'x\ny\nz' ) ).to.equal( 'x<br>y<br>z' );
+	it( 'turns a single line break into paragraphs', () => {
+		expect( plainTextToHtml( 'x\ny\nz' ) ).to.equal( '<p>x</p><p>y</p><p>z</p>' );
 	} );
 
-	it( 'turns double and single line breaks to a combination of paragraphs and <br>s', () => {
-		expect( plainTextToHtml( 'a\nb\n\nc\nd' ) ).to.equal( '<p>a<br>b</p><p>c<br>d</p>' );
+	it( 'turns double line breaks into paragraphs', () => {
+		expect( plainTextToHtml( 'x\n\ny\n\nz' ) ).to.equal( '<p>x</p><p></p><p>y</p><p></p><p>z</p>' );
 	} );
 
-	it( 'turns 3-5 subsequent new lines to a combination of paragraphs and <br>s', () => {
-		expect( plainTextToHtml( 'a\n\n\nb\n\n\n\nc\n\n\n\n\nd' ) )
-			.to.equal( '<p>a</p><p><br>b</p><p></p><p>c</p><p></p><p><br>d</p>' );
+	it( 'turns combination of different amount of line breaks to paragraphs', () => {
+		expect( plainTextToHtml( 'a\nb\n\nc\n\n\nd' ) ).to.equal( '<p>a</p><p>b</p><p></p><p>c</p><p></p><p></p><p>d</p>' );
 	} );
 
 	it( 'preserves trailing spaces', () => {