| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334 |
- /**
- * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
- */
- import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
- import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
- import ShiftEnter from '@ckeditor/ckeditor5-enter/src/shiftenter';
- import { getData } from '../../../src/dev-utils/model';
- // NOTE:
- // dev utils' setData() loses white spaces so don't use it for tests here!!!
- // https://github.com/ckeditor/ckeditor5-engine/issues/1428
- describe( 'DomConverter – whitespace handling – integration', () => {
- let editor;
- // See https://github.com/ckeditor/ckeditor5-engine/issues/822.
- describe( 'normalizing whitespaces around block boundaries (#822)', () => {
- beforeEach( () => {
- return VirtualTestEditor
- .create( { plugins: [ Paragraph ] } )
- .then( newEditor => {
- editor = newEditor;
- editor.model.schema.extend( '$text', { allowAttributes: [ 'bold' ] } );
- editor.conversion.attributeToElement( { model: 'bold', view: 'b' } );
- } );
- } );
- afterEach( () => {
- return editor.destroy();
- } );
- it( 'new line at the end of the content is ignored', () => {
- editor.setData( '<p>foo</p>\n' );
- expect( getData( editor.model, { withoutSelection: true } ) )
- .to.equal( '<paragraph>foo</paragraph>' );
- expect( editor.getData() ).to.equal( '<p>foo</p>' );
- } );
- it( 'whitespaces at the end of the content are ignored', () => {
- editor.setData( '<p>foo</p>\n\r\n \t' );
- expect( getData( editor.model, { withoutSelection: true } ) )
- .to.equal( '<paragraph>foo</paragraph>' );
- expect( editor.getData() ).to.equal( '<p>foo</p>' );
- } );
- it( 'nbsp at the end of the content is not ignored', () => {
- editor.setData( '<p>foo </p>' );
- expect( getData( editor.model, { withoutSelection: true } ) )
- .to.equal( '<paragraph>foo </paragraph>' );
- expect( editor.getData() ).to.equal( '<p>foo </p>' );
- } );
- it( 'new line at the beginning of the content is ignored', () => {
- editor.setData( '\n<p>foo</p>' );
- expect( getData( editor.model, { withoutSelection: true } ) )
- .to.equal( '<paragraph>foo</paragraph>' );
- expect( editor.getData() ).to.equal( '<p>foo</p>' );
- } );
- it( 'whitespaces at the beginning of the content are ignored', () => {
- editor.setData( '\n\n \t<p>foo</p>' );
- expect( getData( editor.model, { withoutSelection: true } ) )
- .to.equal( '<paragraph>foo</paragraph>' );
- expect( editor.getData() ).to.equal( '<p>foo</p>' );
- } );
- it( 'nbsp at the beginning of the content is not ignored', () => {
- editor.setData( '<p> foo</p>' );
- expect( getData( editor.model, { withoutSelection: true } ) )
- .to.equal( '<paragraph> foo</paragraph>' );
- expect( editor.getData() ).to.equal( '<p> foo</p>' );
- } );
- it( 'new line between blocks is ignored', () => {
- editor.setData( '<p>foo</p>\n<p>bar</p>' );
- expect( getData( editor.model, { withoutSelection: true } ) )
- .to.equal( '<paragraph>foo</paragraph><paragraph>bar</paragraph>' );
- expect( editor.getData() ).to.equal( '<p>foo</p><p>bar</p>' );
- } );
- it( 'whitespaces between blocks are ignored', () => {
- editor.setData( '<p>foo</p>\n\n \t<p>bar</p>' );
- expect( getData( editor.model, { withoutSelection: true } ) )
- .to.equal( '<paragraph>foo</paragraph><paragraph>bar</paragraph>' );
- expect( editor.getData() ).to.equal( '<p>foo</p><p>bar</p>' );
- } );
- // Controversial result. See https://github.com/ckeditor/ckeditor5-engine/issues/987.
- it( 'nbsp between blocks is not ignored (between paragraphs)', () => {
- editor.setData( '<p>foo</p> <p>bar</p>' );
- expect( getData( editor.model, { withoutSelection: true } ) )
- .to.equal( '<paragraph>foo</paragraph><paragraph> </paragraph><paragraph>bar</paragraph>' );
- expect( editor.getData() ).to.equal( '<p>foo</p><p> </p><p>bar</p>' );
- } );
- it( 'nbsp between blocks is not ignored (different blocks)', () => {
- editor.model.schema.register( 'block', { inheritAllFrom: '$block' } );
- editor.conversion.elementToElement( { model: 'block', view: 'block' } );
- editor.setData( '<block>foo</block> <p>bar</p>' );
- expect( getData( editor.model, { withoutSelection: true } ) )
- .to.equal(
- '<block>foo</block>' +
- '<paragraph> </paragraph>' +
- '<paragraph>bar</paragraph>'
- );
- expect( editor.getData() )
- .to.equal(
- '<block>foo</block>' +
- '<p> </p>' +
- '<p>bar</p>'
- );
- } );
- it( 'new lines inside blocks are ignored', () => {
- editor.setData( '<p>\nfoo\n</p>' );
- expect( getData( editor.model, { withoutSelection: true } ) )
- .to.equal( '<paragraph>foo</paragraph>' );
- expect( editor.getData() ).to.equal( '<p>foo</p>' );
- } );
- it( 'whitespaces inside blocks are ignored', () => {
- editor.setData( '<p>\n\n \tfoo\n\n \t</p>' );
- expect( getData( editor.model, { withoutSelection: true } ) )
- .to.equal( '<paragraph>foo</paragraph>' );
- expect( editor.getData() ).to.equal( '<p>foo</p>' );
- } );
- it( 'nbsp inside blocks are not ignored', () => {
- editor.setData( '<p> foo </p>' );
- expect( getData( editor.model, { withoutSelection: true } ) )
- .to.equal( '<paragraph> foo </paragraph>' );
- expect( editor.getData() ).to.equal( '<p> foo </p>' );
- } );
- it( 'single nbsp inside blocks are ignored', () => {
- editor.setData( '<p> </p>' );
- expect( getData( editor.model, { withoutSelection: true } ) )
- .to.equal( '<paragraph></paragraph>' );
- expect( editor.getData() ).to.equal( '' ); // trimmed
- } );
- it( 'all whitespaces together are ignored', () => {
- editor.setData( '\n<p>foo\n\r\n \t</p>\n<p> bar</p>' );
- expect( getData( editor.model, { withoutSelection: true } ) )
- .to.equal( '<paragraph>foo</paragraph><paragraph>bar</paragraph>' );
- expect( editor.getData() ).to.equal( '<p>foo</p><p>bar</p>' );
- } );
- it( 'nbsp between inline elements is not ignored', () => {
- editor.setData( '<p><b>foo</b> <b>bar</b></p>' );
- expect( getData( editor.model, { withoutSelection: true } ) )
- .to.equal( '<paragraph><$text bold="true">foo</$text>\u00A0<$text bold="true">bar</$text></paragraph>' );
- expect( editor.getData() ).to.equal( '<p><b>foo</b> <b>bar</b></p>' );
- } );
- it( 'nbsp before inline element is not ignored', () => {
- editor.setData( '<p> <b>bar</b></p>' );
- expect( getData( editor.model, { withoutSelection: true } ) )
- .to.equal( '<paragraph> <$text bold="true">bar</$text></paragraph>' );
- expect( editor.getData() ).to.equal( '<p> <b>bar</b></p>' );
- } );
- it( 'nbsp after inline element is not ignored', () => {
- editor.setData( '<p><b>bar</b> </p>' );
- expect( getData( editor.model, { withoutSelection: true } ) )
- .to.equal( '<paragraph><$text bold="true">bar</$text> </paragraph>' );
- expect( editor.getData() ).to.equal( '<p><b>bar</b> </p>' );
- } );
- } );
- // https://github.com/ckeditor/ckeditor5/issues/1024
- describe( 'whitespaces around <br>s', () => {
- beforeEach( () => {
- return VirtualTestEditor
- .create( { plugins: [ Paragraph, ShiftEnter ] } )
- .then( newEditor => {
- editor = newEditor;
- } );
- } );
- afterEach( () => {
- return editor.destroy();
- } );
- it( 'single spaces around <br> #1', () => {
- editor.setData( '<p>foo <br> bar</p>' );
- expect( getData( editor.model, { withoutSelection: true } ) )
- .to.equal( '<paragraph>foo\u00A0<softBreak></softBreak> bar</paragraph>' );
- expect( editor.getData() ).to.equal( '<p>foo <br> bar</p>' );
- } );
- it( 'single spaces around <br> #2', () => {
- editor.setData( '<p>foo <br> bar</p>' );
- expect( getData( editor.model, { withoutSelection: true } ) )
- .to.equal( '<paragraph>foo\u00A0<softBreak></softBreak>bar</paragraph>' );
- expect( editor.getData() ).to.equal( '<p>foo <br>bar</p>' );
- } );
- it( 'two spaces before a <br>', () => {
- editor.setData( '<p>foo <br>bar</p>' );
- expect( getData( editor.model, { withoutSelection: true } ) )
- .to.equal( '<paragraph>foo <softBreak></softBreak>bar</paragraph>' );
- expect( editor.getData() ).to.equal( '<p>foo <br>bar</p>' );
- } );
- it( 'two nbsps before a <br>', () => {
- editor.setData( '<p>foo <br>bar</p>' );
- expect( getData( editor.model, { withoutSelection: true } ) )
- .to.equal( '<paragraph>foo\u00a0 <softBreak></softBreak>bar</paragraph>' );
- expect( editor.getData() ).to.equal( '<p>foo <br>bar</p>' );
- } );
- it( 'single space after a <br>', () => {
- editor.setData( '<p>foo<br> bar</p>' );
- expect( getData( editor.model, { withoutSelection: true } ) )
- .to.equal( '<paragraph>foo<softBreak></softBreak> bar</paragraph>' );
- expect( editor.getData() ).to.equal( '<p>foo<br> bar</p>' );
- } );
- it( 'single space after a <br> (normalization)', () => {
- editor.setData( '<p>foo<br> bar</p>' );
- expect( getData( editor.model, { withoutSelection: true } ) )
- .to.equal( '<paragraph>foo<softBreak></softBreak>bar</paragraph>' );
- expect( editor.getData() ).to.equal( '<p>foo<br>bar</p>' );
- } );
- it( 'two spaces after a <br>', () => {
- editor.setData( '<p>foo<br> bar</p>' );
- expect( getData( editor.model, { withoutSelection: true } ) )
- .to.equal( '<paragraph>foo<softBreak></softBreak> bar</paragraph>' );
- expect( editor.getData() ).to.equal( '<p>foo<br> bar</p>' );
- } );
- it( 'two spaces after a <br> (normalization)', () => {
- editor.setData( '<p>foo<br> bar</p>' );
- expect( getData( editor.model, { withoutSelection: true } ) )
- .to.equal( '<paragraph>foo<softBreak></softBreak> bar</paragraph>' );
- expect( editor.getData() ).to.equal( '<p>foo<br> bar</p>' );
- } );
- it( 'two spaces after a <br> (normalization to a model nbsp)', () => {
- editor.setData( '<p>foo<br> bar</p>' );
- expect( getData( editor.model, { withoutSelection: true } ) )
- .to.equal( '<paragraph>foo<softBreak></softBreak> \u00a0bar</paragraph>' );
- expect( editor.getData() ).to.equal( '<p>foo<br> bar</p>' );
- } );
- // https://github.com/ckeditor/ckeditor5-engine/issues/1429
- // it( 'space between <br>s', () => {
- // editor.setData( '<p>foo<br> <br>bar</p>' );
- // expect( getData( editor.model, { withoutSelection: true } ) )
- // .to.equal( '<paragraph>foo<softBreak></softBreak> <softBreak></softBreak>bar</paragraph>' );
- // expect( editor.getData() ).to.equal( '<p>foo<br> <br>bar</p>' );
- // } );
- it( 'space between <br>s (normalization)', () => {
- editor.setData( '<p>foo<br> <br>bar</p>' );
- expect( getData( editor.model, { withoutSelection: true } ) )
- .to.equal( '<paragraph>foo<softBreak></softBreak><softBreak></softBreak>bar</paragraph>' );
- expect( editor.getData() ).to.equal( '<p>foo<br><br>bar</p>' );
- } );
- it( 'two spaces between <br>s', () => {
- editor.setData( '<p>foo<br> <br>bar</p>' );
- expect( getData( editor.model, { withoutSelection: true } ) )
- .to.equal( '<paragraph>foo<softBreak></softBreak> <softBreak></softBreak>bar</paragraph>' );
- expect( editor.getData() ).to.equal( '<p>foo<br> <br>bar</p>' );
- } );
- } );
- } );
|