diff --git a/src/utils/plaintexttohtml.js b/src/utils/plaintexttohtml.js index 6f752f9..9c453f2 100644 --- a/src/utils/plaintexttohtml.js +++ b/src/utils/plaintexttohtml.js @@ -18,10 +18,9 @@ export default function plainTextToHtml( text ) { // Encode <>. .replace( //g, '>' ) - // Creates paragraphs for double line breaks and change single line breaks to spaces. - // In the future single line breaks may be converted into
s. + // Creates paragraphs for double line breaks and change single line breaks to
s. .replace( /\n\n/g, '

' ) - .replace( /\n/g, ' ' ) + .replace( /\n/g, '
' ) // Preserve trailing spaces (only the first and last one – the rest is handled below). .replace( /^\s/, ' ' ) .replace( /\s$/, ' ' ) diff --git a/tests/utils/plaintexttohtml.js b/tests/utils/plaintexttohtml.js index be210d5..2ee67bc 100644 --- a/tests/utils/plaintexttohtml.js +++ b/tests/utils/plaintexttohtml.js @@ -14,6 +14,19 @@ describe( 'plainTextToHtml()', () => { expect( plainTextToHtml( 'x\n\ny\n\nz' ) ).to.equal( '

x

y

z

' ); } ); + it( 'turns single line breaks into
s', () => { + expect( plainTextToHtml( 'x\ny\nz' ) ).to.equal( 'x
y
z' ); + } ); + + it( 'turns double and single line breaks to a combination of paragraphs and
s', () => { + expect( plainTextToHtml( 'a\nb\n\nc\nd' ) ).to.equal( '

a
b

c
d

' ); + } ); + + it( 'turns 3-5 subsequent new lines to a combination of paragraphs and
s', () => { + expect( plainTextToHtml( 'a\n\n\nb\n\n\n\nc\n\n\n\n\nd' ) ) + .to.equal( '

a


b

c


d

' ); + } ); + it( 'preserves trailing spaces', () => { expect( plainTextToHtml( ' x ' ) ).to.equal( ' x ' ); } ); @@ -21,8 +34,4 @@ describe( 'plainTextToHtml()', () => { it( 'preserve subsequent spaces', () => { expect( plainTextToHtml( 'x y ' ) ).to.equal( 'x  y  ' ); } ); - - it( 'turns single line breaks to spaces', () => { - expect( plainTextToHtml( 'x\ny\nz' ) ).to.equal( 'x y z' ); - } ); } );