plaintexttohtml.js 988 B

12345678910111213141516171819202122232425262728
  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 single line breaks into paragraphs', () => {
  11. expect( plainTextToHtml( 'x\ny\nz' ) ).to.equal( '<p>x</p><p>y</p><p>z</p>' );
  12. } );
  13. it( 'turns combination of different amount of line breaks to paragraphs', () => {
  14. 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>' );
  15. } );
  16. it( 'preserves trailing spaces', () => {
  17. expect( plainTextToHtml( ' x ' ) ).to.equal( '&nbsp;x&nbsp;' );
  18. } );
  19. it( 'preserve subsequent spaces', () => {
  20. expect( plainTextToHtml( 'x y ' ) ).to.equal( 'x &nbsp;y &nbsp;' );
  21. } );
  22. } );