8
0

plaintexttohtml.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. import plainTextToHtml from '../../src/utils/plaintexttohtml';
  6. describe( 'plainTextToHtml()', () => {
  7. it( 'encodes < and >', () => {
  8. expect( plainTextToHtml( 'x y <z>' ) ).to.equal( 'x y &lt;z&gt;' );
  9. } );
  10. it( 'turns double line breaks into paragraphs', () => {
  11. expect( plainTextToHtml( 'x\n\ny\n\nz' ) ).to.equal( '<p>x</p><p>y</p><p>z</p>' );
  12. } );
  13. it( 'turns single line breaks into <br>s', () => {
  14. expect( plainTextToHtml( 'x\ny\nz' ) ).to.equal( 'x<br>y<br>z' );
  15. } );
  16. it( 'turns double and single line breaks to a combination of paragraphs and <br>s', () => {
  17. expect( plainTextToHtml( 'a\nb\n\nc\nd' ) ).to.equal( '<p>a<br>b</p><p>c<br>d</p>' );
  18. } );
  19. it( 'turns 3-5 subsequent new lines to a combination of paragraphs and <br>s', () => {
  20. expect( plainTextToHtml( 'a\n\n\nb\n\n\n\nc\n\n\n\n\nd' ) )
  21. .to.equal( '<p>a</p><p><br>b</p><p></p><p>c</p><p></p><p><br>d</p>' );
  22. } );
  23. it( 'preserves trailing spaces', () => {
  24. expect( plainTextToHtml( ' x ' ) ).to.equal( '&nbsp;x&nbsp;' );
  25. } );
  26. it( 'preserve subsequent spaces', () => {
  27. expect( plainTextToHtml( 'x y ' ) ).to.equal( 'x &nbsp;y &nbsp;' );
  28. } );
  29. } );