From 13edcbfc046fe6aaa7577257f13238099d90fcaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Mon, 12 Aug 2019 12:02:37 +0200 Subject: [PATCH] Remove fixListIndentation() filter. --- src/filters/list.js | 59 ----------- src/normalizers/googledocsnormalizer.js | 1 - tests/data/normalization.js | 7 -- tests/filters/list.js | 130 +----------------------- 4 files changed, 1 insertion(+), 196 deletions(-) diff --git a/src/filters/list.js b/src/filters/list.js index e05f0e1..4c23c73 100644 --- a/src/filters/list.js +++ b/src/filters/list.js @@ -70,65 +70,6 @@ export function unwrapParagraphInListItem( documentFragment, writer ) { } } -/** - * Fix structure of nested lists to follow HTML guidelines and normalize content in predictable way. - * - * 1. Move nested lists to have sure that list items are the only children of lists. - * - * before: after: - * OL OL - * |-> LI |-> LI - * |-> OL |-> OL - * |-> LI |-> LI - * - * 2. Remove additional indentation which cannot be recreated in HTML structure. - * - * before: after: - * OL OL - * |-> LI |-> LI - * |-> OL |-> OL - * |-> OL |-> LI - * | |-> OL |-> LI - * | |-> OL - * | |-> LI - * |-> LI - * - * before: after: - * OL OL - * |-> OL |-> LI - * |-> OL - * |-> OL - * |-> LI - * - * @param {module:engine/view/documentfragment~DocumentFragment} documentFragment - * @param {module:engine/view/upcastwriter~UpcastWriter} writer - */ -export function fixListIndentation( documentFragment, writer ) { - for ( const value of writer.createRangeIn( documentFragment ) ) { - const element = value.item; - - // case 1: The previous sibling of a list is a list item. - if ( element.is( 'li' ) ) { - const next = element.nextSibling; - - if ( next && isList( next ) ) { - writer.remove( next ); - writer.insertChild( element.childCount, next, element ); - } - } - - // case 2: The list is the first child of another list. - if ( isList( element ) ) { - let firstChild = element.getChild( 0 ); - - while ( isList( firstChild ) ) { - writer.unwrapElement( firstChild ); - firstChild = element.getChild( 0 ); - } - } - } -} - // Finds all list-like elements in a given document fragment. // // @param {module:engine/view/documentfragment~DocumentFragment} documentFragment Document fragment diff --git a/src/normalizers/googledocsnormalizer.js b/src/normalizers/googledocsnormalizer.js index b6f659f..955d407 100644 --- a/src/normalizers/googledocsnormalizer.js +++ b/src/normalizers/googledocsnormalizer.js @@ -33,7 +33,6 @@ export default class GoogleDocsNormalizer { const writer = new UpcastWriter(); removeBoldWrapper( data.content, writer ); - fixListIndentation( data.content, writer ); unwrapParagraphInListItem( data.content, writer ); } } diff --git a/tests/data/normalization.js b/tests/data/normalization.js index 420fcd3..fc75593 100644 --- a/tests/data/normalization.js +++ b/tests/data/normalization.js @@ -57,13 +57,6 @@ describe( 'PasteFromOffice - normalization', () => { editorConfig } ); - generateTests( { - input: 'google-docs-list', - type: 'normalization', - browsers, - editorConfig - } ); - generateTests( { input: 'generic-list-in-table', type: 'normalization', diff --git a/tests/filters/list.js b/tests/filters/list.js index 81cfecd..6d41558 100644 --- a/tests/filters/list.js +++ b/tests/filters/list.js @@ -10,8 +10,7 @@ import UpcastWriter from '@ckeditor/ckeditor5-engine/src/view/upcastwriter'; import { transformListItemLikeElementsIntoLists, - unwrapParagraphInListItem, - fixListIndentation + unwrapParagraphInListItem } from '../../src/filters/list'; describe( 'PasteFromOffice - filters', () => { @@ -127,132 +126,5 @@ describe( 'PasteFromOffice - filters', () => { expect( htmlDataProcessor.toData( documentFragment ) ).to.equal( '
  1. foo
  2. bar
    • baz
' ); } ); } ); - - describe( 'fixListIndentation', () => { - it( 'should move nested list to previous list item', () => { - const inputData = ''; - - const documentFragment = htmlDataProcessor.toView( inputData ); - - fixListIndentation( documentFragment, writer ); - - expect( htmlDataProcessor.toData( documentFragment ) ).to.equal( - '' - ); - } ); - } ); - - describe( 'repeatedly nested lists are normalized', () => { - it( 'should unwrap single nested list', () => { - const inputData = ''; - const documentFragment = htmlDataProcessor.toView( inputData ); - - fixListIndentation( documentFragment, writer ); - - expect( htmlDataProcessor.toData( documentFragment ) ).to.equal( - '' - ); - } ); - - it( 'should preserve sibling elements in correct relation', () => { - const inputData = '
    ' + - '
  1. foo
  2. ' + - '
      ' + - '
        ' + - '
          ' + - '
        1. one
        2. ' + - '
        ' + - '
      1. two
      2. ' + - '
      ' + - '
    1. three
    2. ' + - '
        ' + - '
          ' + - '
            ' + - '
          1. four
          2. ' + - '
          ' + - '
        ' + - '
      ' + - '
    ' + - '
  3. correct' + - '
      ' + - '
    1. AAA' + - '
        ' + - '
      1. BBB
      2. ' + - '
      3. CCC
      4. ' + - '
      ' + - '
    2. ' + - '
    ' + - '
  4. ' + - '
'; - - const documentFragment = htmlDataProcessor.toView( inputData ); - - fixListIndentation( documentFragment, writer ); - - expect( htmlDataProcessor.toData( documentFragment ) ).to.equal( - '
    ' + - '
  1. foo' + - '
      ' + - '
    1. one
    2. ' + - '
    3. two
    4. ' + - '
    5. three' + - '
        ' + - '
      1. four
      2. ' + - '
      ' + - '
    6. ' + - '
    ' + - '
  2. ' + - '
  3. correct' + - '
      ' + - '
    1. AAA' + - '
        ' + - '
      1. BBB
      2. ' + - '
      3. CCC
      4. ' + - '
      ' + - '
    2. ' + - '
    ' + - '
  4. ' + - '
' - ); - } ); - - it( 'should normalize lists which are start from nested elements', () => { - const inputData = '
    ' + - '
      ' + - '
        ' + - '
          ' + - '
        1. foo
        2. ' + - '
        ' + - '
      ' + - '
    ' + - '
'; - const documentFragment = htmlDataProcessor.toView( inputData ); - - fixListIndentation( documentFragment, writer ); - - expect( htmlDataProcessor.toData( documentFragment ) ).to.equal( '
  1. foo
' ); - } ); - - it( 'should normalize 2 sibling list independently', () => { - const inputData = '
    ' + - '
  1. foo
  2. ' + - '
' + - ''; - const documentFragment = htmlDataProcessor.toView( inputData ); - - fixListIndentation( documentFragment, writer ); - - expect( htmlDataProcessor.toData( documentFragment ) ).to.equal( '
  1. foo
' ); - } ); - } ); } ); } );