/** * @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 { testDataProcessor } from '../_utils/utils'; import MarkdownDataProcessor from '../../src/gfmdataprocessor'; import HtmlDataProcessor from '@ckeditor/ckeditor5-engine/src/dataprocessor/htmldataprocessor'; import ViewDocument from '@ckeditor/ckeditor5-engine/src/view/document'; import { StylesProcessor } from '@ckeditor/ckeditor5-engine/src/view/stylesmap'; describe( 'GFMDataProcessor', () => { describe( 'lists', () => { it( 'should process tight asterisks', () => { testDataProcessor( '* item 1\n' + '* item 2\n' + '* item 3', // GitHub renders it as (notice spaces before list items) // '', // List will be normalized to 3-space representation. '* item 1\n' + '* item 2\n' + '* item 3' ); } ); it( 'should process loose asterisks', () => { testDataProcessor( '* item 1\n' + '\n' + '* item 2\n' + '\n' + '* item 3', // Loose lists are rendered with with paragraph inside. '', // List will be normalized to 3-space representation. '* item 1\n' + '\n' + '* item 2\n' + '\n' + '* item 3' ); } ); it( 'should process tight pluses', () => { testDataProcessor( '+ item 1\n' + '+ item 2\n' + '+ item 3', '', // List will be normalized to asterisks, 3-space representation. '* item 1\n' + '* item 2\n' + '* item 3' ); } ); it( 'should process loose pluses', () => { testDataProcessor( '+ item 1\n' + '\n' + '+ item 2\n' + '\n' + '+ item 3', '', // List will be normalized to asterisks, 3-space representation. '* item 1\n' + '\n' + '* item 2\n' + '\n' + '* item 3' ); } ); it( 'should process tight minuses', () => { testDataProcessor( '- item 1\n' + '- item 2\n' + '- item 3', '', // List will be normalized to asterisks, 3-space representation. '* item 1\n' + '* item 2\n' + '* item 3' ); } ); it( 'should process loose minuses', () => { testDataProcessor( '- item 1\n' + '\n' + '- item 2\n' + '\n' + '- item 3', '', // List will be normalized to asterisks, 3-space representation. '* item 1\n' + '\n' + '* item 2\n' + '\n' + '* item 3' ); } ); it( 'should process ordered list with tabs', () => { testDataProcessor( '1. item 1\n' + '2. item 2\n' + '3. item 3', '
    ' + '
  1. item 1
  2. ' + '
  3. item 2
  4. ' + '
  5. item 3
  6. ' + '
', // List will be normalized to 2-space representation. '1. item 1\n' + '2. item 2\n' + '3. item 3' ); } ); it( 'should process ordered list with spaces', () => { testDataProcessor( '1. item 1\n' + '2. item 2\n' + '3. item 3', '
    ' + '
  1. item 1
  2. ' + '
  3. item 2
  4. ' + '
  5. item 3
  6. ' + '
', // List will be normalized to 2-space representation. '1. item 1\n' + '2. item 2\n' + '3. item 3' ); } ); it( 'should process loose ordered list with tabs', () => { testDataProcessor( '1. item 1\n' + '\n' + '2. item 2\n' + '\n' + '3. item 3', '
    ' + '
  1. ' + '

    item 1

    ' + '
  2. ' + '
  3. ' + '

    item 2

    ' + '
  4. ' + '
  5. ' + '

    item 3

    ' + '
  6. ' + '
', // List will be normalized to 2-space representation. '1. item 1\n' + '\n' + '2. item 2\n' + '\n' + '3. item 3' ); } ); it( 'should process loose ordered list with spaces', () => { testDataProcessor( '1. item 1\n' + '\n' + '2. item 2\n' + '\n' + '3. item 3', '
    ' + '
  1. ' + '

    item 1

    ' + '
  2. ' + '
  3. ' + '

    item 2

    ' + '
  4. ' + '
  5. ' + '

    item 3

    ' + '
  6. ' + '
', // List will be normalized to 2-space representation. '1. item 1\n' + '\n' + '2. item 2\n' + '\n' + '3. item 3' ); } ); it( 'should process nested and mixed lists', () => { testDataProcessor( '1. First\n' + '2. Second:\n' + ' * Fee\n' + ' * Fie\n' + ' * Foe\n' + '3. Third', '
    ' + '
  1. First
  2. ' + '
  3. Second:' + '' + '
  4. ' + '
  5. Third
  6. ' + '
', // All lists will be normalized after converting back. '1. First\n' + '2. Second:\n' + ' * Fee\n' + ' * Fie\n' + ' * Foe\n' + '3. Third' ); } ); it( 'should process nested and mixed loose lists', () => { testDataProcessor( '1. First\n' + '\n' + '2. Second:\n' + ' * Fee\n' + ' * Fie\n' + ' * Foe\n' + '\n' + '3. Third', '
    ' + '
  1. ' + '

    First

    ' + '
  2. ' + '
  3. ' + '

    Second:

    ' + '' + '
  4. ' + '
  5. ' + '

    Third

    ' + '
  6. ' + '
', // All lists will be normalized after converting back. '1. First\n' + '\n' + '2. Second:\n' + '\n' + ' * Fee\n' + ' * Fie\n' + ' * Foe\n' + '3. Third' ); } ); it( 'should create same bullet from different list indicators', () => { testDataProcessor( '* test\n' + '+ test\n' + '- test', '', // After converting back list items will be unified. '* test\n' + '* test\n' + '* test' ); } ); } ); describe( 'todo lists', () => { it( 'should process todo lists', () => { testDataProcessor( '* [ ] Item 1\n' + '* [x] Item 2', '' ); } ); it( 'should process the HTML produced by the todo list feature', () => { const viewDocument = new ViewDocument( new StylesProcessor() ); const htmlDataProcessor = new HtmlDataProcessor( viewDocument ); const mdDataProcessor = new MarkdownDataProcessor( viewDocument ); const viewFragment = htmlDataProcessor.toView( '' ); expect( mdDataProcessor.toData( viewFragment ) ).to.equal( '* [ ] Item 1\n' + '* [x] Item 2' ); } ); } ); } );