| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287 |
- /**
- * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
- /* globals document */
- import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
- import Clipboard from '@ckeditor/ckeditor5-clipboard/src/clipboard';
- import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
- import Heading from '@ckeditor/ckeditor5-heading/src/heading';
- import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
- import Italic from '@ckeditor/ckeditor5-basic-styles/src/italic';
- import Underline from '@ckeditor/ckeditor5-basic-styles/src/underline';
- import Link from '@ckeditor/ckeditor5-link/src/link';
- import List from '@ckeditor/ckeditor5-list/src/list';
- import PasteFromOffice from '../../../src/pastefromoffice';
- import { setData, stringify } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
- import { pasteHtml } from '../../_utils/utils';
- import simple from '../../_data/list/simple/input.word2016.html';
- import styled from '../../_data/list/styled/input.word2016.html';
- import multiple from '../../_data/list/multiple/input.word2016.html';
- import multipleCombined from '../../_data/list/multiple-combined/input.word2016.html';
- import manyOneItem from '../../_data/list/many-one-item/input.word2016.html';
- import heading1 from '../../_data/list/heading1/input.word2016.html';
- import heading3Styled from '../../_data/list/heading3-styled/input.word2016.html';
- import heading7 from '../../_data/list/heading7/input.word2016.html';
- describe( 'List – integration', () => {
- let element, editor, insertedModel;
- before( () => {
- element = document.createElement( 'div' );
- document.body.appendChild( element );
- return ClassicTestEditor
- .create( element, { plugins: [ Clipboard, Paragraph, Heading, Bold, Italic, Underline, Link, List, PasteFromOffice ] } )
- .then( editorInstance => {
- editor = editorInstance;
- const model = editor.model;
- const insertContent = model.insertContent;
- sinon.stub( editor.model, 'insertContent' ).callsFake( ( content, selection ) => {
- // Save model string representation now as it may change after `insertContent()` function call
- // so accessing it later may not work as it may have empty/changed structure.
- insertedModel = stringify( content );
- insertContent.call( model, content, selection );
- } );
- } );
- } );
- beforeEach( () => {
- setData( editor.model, '<paragraph>[]</paragraph>' );
- } );
- afterEach( () => {
- insertedModel = null;
- } );
- after( () => {
- sinon.restore();
- editor.destroy();
- element.remove();
- } );
- // Pastes (after cleaning up garbage markup):
- //
- // <p><span>1.</span<span>Item1</span></p>
- // <p><span>2.</span>><span>Item 2</span></p>
- //
- // which should result in the same output as pasting:
- //
- // <ol><li>Item1</li><li>Item2</li></ol>
- it( 'pastes simple list', () => {
- const expectedModel = '<listItem listIndent="0" listType="numbered">Item1</listItem>' +
- '<listItem listIndent="0" listType="numbered">Item 2</listItem>';
- expectContent( simple, expectedModel );
- } );
- // Pastes (after cleaning up garbage markup):
- //
- // <p>List:</p>
- // <p><span>·</span><span>B<b>old</b></span></p>
- // <p><span>·</span><span><a href="https://cksource.com">Lin</a>k</span></p>
- // <p><span>·</span><span><i>M<b>ul<u>tip</u></b><u>le</u></span></i></p>
- //
- // which should result in the same output as pasting:
- //
- // <p>List:</p>
- // <ul>
- // <li>B<b>old</b></li>
- // <li><a href="https://cksource.com">Lin</a>k</li>
- // <li><i>M<b>ul<u>tip</u></b><u>le</u></i></li>
- // </ul>
- it( 'pastes list with styled items prepended by a paragraph', () => {
- const expectedModel = '<paragraph>List:</paragraph>' +
- '<listItem listIndent="0" listType="bulleted">B<$text bold="true">old</$text></listItem>' +
- '<listItem listIndent="0" listType="bulleted"><$text linkHref="https://cksource.com">Lin</$text>k</listItem>' +
- '<listItem listIndent="0" listType="bulleted"><$text italic="true">M</$text><$text bold="true" italic="true">ul</$text>' +
- '<$text bold="true" italic="true" underline="true">tip</$text>' +
- '<$text italic="true" underline="true">le</$text></listItem>';
- expectContent( styled, expectedModel );
- } );
- // Pastes (after cleaning up garbage markup):
- //
- // <p><span>1.</span><span>Item1</span></p>
- // <p><span>2.</span><span>Item 2</span></p>
- // <p>Some text</p>
- // <p><span>·</span><span>Bullet 1</span></p>
- //
- // which should result in the same output as pasting:
- //
- // <ol>
- // <li>Item1</li>
- // <li>Item 2</li>
- // </ol>
- // <p>Some text</p>
- // <ul>
- // <li>Bullet 1</li>
- // </ul>
- it( 'pastes multiple lists separated by the paragraph', () => {
- const expectedModel = '<listItem listIndent="0" listType="numbered">Item1</listItem>' +
- '<listItem listIndent="0" listType="numbered">Item 2</listItem>' +
- '<paragraph>Some text</paragraph>' +
- '<listItem listIndent="0" listType="bulleted">Bullet 1</listItem>';
- expectContent( multiple, expectedModel );
- } );
- // Pastes (after cleaning up garbage markup):
- //
- // <p><span>1.</span><span>Item1</span></p>
- // <p><span>2.</span><span>Item 2</span></p>
- // <p><span>1.</span><span>Item 1</span></p>
- // <p><span>2.</span><span>Item2</span></p>
- //
- // which should result in the same output as pasting:
- //
- // <ol>
- // <li>Item1</li>
- // <li>Item 2</li>
- // </ol>
- // <ol>
- // <li>Item 1</li>
- // <li>Item2</li>
- // </ol>
- //
- // It will create one list, see https://github.com/ckeditor/ckeditor5-list/issues/99.
- it( 'pastes multiple lists one right after another', () => {
- const expectedModel = '<listItem listIndent="0" listType="numbered">Item1</listItem>' +
- '<listItem listIndent="0" listType="numbered">Item 2</listItem>' +
- '<listItem listIndent="0" listType="numbered">Item 1</listItem>' +
- '<listItem listIndent="0" listType="numbered">Item2</listItem>';
- expectContent( multipleCombined, expectedModel );
- } );
- // Pastes (after cleaning up garbage markup):
- //
- // <p><span>1.</span><span>A</span></p>
- // <p><span>1)</span><span>B</span></p>
- // <p><span>I.</span><span>C</span></p>
- // <p><span>A.</span><span>D</span></p>
- // <p><span>a)</span><span>E</span></p>
- // <p><span>a.</span><span>F</span></p>
- // <p><span>i.</span><span>G</span></p>
- // <p></p>
- // <p><span>·</span><span>H</span></p>
- // <p><span>o</span><span>I</span></p>
- // <p></p>
- // <p><span>§</span><span>J</span></p>
- // <p><span><img... /></span><span>k</span></p>
- // <p></p>
- // <p><span>1.</span><span>h1</span></p>
- //
- // which should result in the same output as pasting:
- //
- // <ol><li>A</li></ol>
- // <ol><li>B</li></ol>
- // <ol><li>C</li></ol>
- // <ol><li>D</li></ol>
- // <ol><li>E</li></ol>
- // <ol><li>F</li></ol>
- // <ol><li>G</li></ol>
- // <p></p>
- // <ul><li>H</li></ul>
- // <ul><li>I</li></ul>
- // <p></p>
- // <ul><li>J</li></ul>
- // <ul><li>k</li></ul>
- // <p></p>
- // <ol><li>h1</li></ol>
- //
- // It will create one list, for all lists not separated by any element - see https://github.com/ckeditor/ckeditor5-list/issues/99.
- it( 'pastes many one item lists', () => {
- const expectedModel = '<listItem listIndent="0" listType="numbered">A</listItem>' +
- '<listItem listIndent="0" listType="numbered">B</listItem>' +
- '<listItem listIndent="0" listType="numbered">C</listItem>' +
- '<listItem listIndent="0" listType="numbered">D</listItem>' +
- '<listItem listIndent="0" listType="numbered">E</listItem>' +
- '<listItem listIndent="0" listType="numbered">F</listItem>' +
- '<listItem listIndent="0" listType="numbered">G</listItem>' +
- '<paragraph></paragraph>' +
- '<listItem listIndent="0" listType="bulleted">H</listItem>' +
- '<listItem listIndent="0" listType="bulleted">I</listItem>' +
- '<paragraph></paragraph>' +
- '<listItem listIndent="0" listType="bulleted">J</listItem>' +
- '<listItem listIndent="0" listType="bulleted">k</listItem>' +
- '<paragraph></paragraph>' +
- '<listItem listIndent="0" listType="numbered">h1</listItem>';
- expectContent( manyOneItem, expectedModel );
- } );
- // Pastes (after cleaning up garbage markup):
- //
- // <h1><span>1.</span><span>H1 1</span></h1>
- // <h1><span>2.</span><span>H1 2</span></h1>
- //
- // which should result in the same output as pasting:
- //
- // <ol>
- // <li>H1 1</li>
- // <li>H1 2</li>
- // </ol>
- //
- // Since headings cannot be used inside lists, they should be transformed to a regular text.
- it( 'pastes list created from headings (h1)', () => {
- const expectedModel = '<listItem listIndent="0" listType="numbered">H1 1</listItem>' +
- '<listItem listIndent="0" listType="numbered">H1 2</listItem>';
- expectContent( heading1, expectedModel );
- } );
- // Pastes (after cleaning up garbage markup):
- //
- // <h3><span>·</span><span>H<b>2 1</b></span></h3>
- // <h3><span>·</span><span><i><u>H</u></i><u>2</u> 2</span></h3>
- //
- // which should result in the same output as pasting:
- //
- // <ul>
- // <li>H<b>2 1</b></li>
- // <li><i><u>H</u></i><u>2</u> 2</li>
- // </ul>
- //
- // Since headings cannot be used inside lists, they should be transformed to a regular text.
- it( 'pastes list created from styled headings (h3)', () => {
- const expectedModel = '<listItem listIndent="0" listType="bulleted">H<$text bold="true">2 1</$text></listItem>' +
- '<listItem listIndent="0" listType="bulleted"><$text italic="true" underline="true">H</$text>' +
- '<$text underline="true">2</$text> 2</listItem>';
- expectContent( heading3Styled, expectedModel );
- } );
- // Pastes (after cleaning up garbage markup):
- //
- // <p><span>1.</span><span>H 7</span></p>
- //
- // which should result in the same output as pasting:
- //
- // <ol>
- // <li>H 7</li>
- // </ol>
- //
- // In Word `Heading 7` is represented as `<p class="MsoHeading7"...>`.
- it( 'pastes list created from styled headings (h3)', () => {
- const expectedModel = '<listItem listIndent="0" listType="numbered">H 7</listItem>';
- expectContent( heading7, expectedModel );
- } );
- function expectContent( input, expectedModel ) {
- pasteHtml( editor, input );
- expect( insertedModel ).to.equal( expectedModel );
- }
- } );
|