lists.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import MarkdownDataProcessor from '/ckeditor5/markdown-gfm/gfmdataprocessor.js';
  6. import { stringify } from '/tests/engine/_utils/view.js';
  7. describe( 'GFMDataProcessor', () => {
  8. let dataProcessor;
  9. beforeEach( () => {
  10. dataProcessor = new MarkdownDataProcessor();
  11. } );
  12. describe( 'lists', () => {
  13. describe( 'toView', () => {
  14. it( 'should process tight asterisks', () => {
  15. const viewFragment = dataProcessor.toView( '* item 1\n* item 2\n* item 3' );
  16. expect( stringify( viewFragment ) ).to.equal( '<ul><li>item 1</li><li>item 2</li><li>item 3</li></ul>' );
  17. } );
  18. it( 'should process loose asterisks', () => {
  19. const viewFragment = dataProcessor.toView( '* item 1\n\n* item 2\n\n* item 3' );
  20. expect( stringify( viewFragment ) ).to.equal( '<ul><li><p>item 1</p></li><li><p>item 2</p></li><li><p>item 3</p></li></ul>' );
  21. } );
  22. it( 'should process tight pluses', () => {
  23. const viewFragment = dataProcessor.toView( '+ item 1\n+ item 2\n+ item 3' );
  24. expect( stringify( viewFragment ) ).to.equal( '<ul><li>item 1</li><li>item 2</li><li>item 3</li></ul>' );
  25. } );
  26. it( 'should process loose pluses', () => {
  27. const viewFragment = dataProcessor.toView( '+ item 1\n\n+ item 2\n\n+ item 3' );
  28. expect( stringify( viewFragment ) ).to.equal( '<ul><li><p>item 1</p></li><li><p>item 2</p></li><li><p>item 3</p></li></ul>' );
  29. } );
  30. it( 'should process tight minuses', () => {
  31. const viewFragment = dataProcessor.toView( '- item 1\n- item 2\n- item 3' );
  32. expect( stringify( viewFragment ) ).to.equal( '<ul><li>item 1</li><li>item 2</li><li>item 3</li></ul>' );
  33. } );
  34. it( 'should process loose minuses', () => {
  35. const viewFragment = dataProcessor.toView( '- item 1\n\n- item 2\n\n- item 3' );
  36. expect( stringify( viewFragment ) ).to.equal( '<ul><li><p>item 1</p></li><li><p>item 2</p></li><li><p>item 3</p></li></ul>' );
  37. } );
  38. it( 'should process ordered list with tabs', () => {
  39. const viewFragment = dataProcessor.toView( '1. item 1\n2. item 2\n3. item 3' );
  40. expect( stringify( viewFragment ) ).to.equal( '<ol><li>item 1</li><li>item 2</li><li>item 3</li></ol>' );
  41. } );
  42. it( 'should process ordered list with spaces', () => {
  43. const viewFragment = dataProcessor.toView( '1. item 1\n2. item 2\n3. item 3' );
  44. expect( stringify( viewFragment ) ).to.equal( '<ol><li>item 1</li><li>item 2</li><li>item 3</li></ol>' );
  45. } );
  46. it( 'should process loose ordered list with tabs', () => {
  47. const viewFragment = dataProcessor.toView( '1. item 1\n\n2. item 2\n\n3. item 3' );
  48. expect( stringify( viewFragment ) ).to.equal( '<ol><li><p>item 1</p></li><li><p>item 2</p></li><li><p>item 3</p></li></ol>' );
  49. } );
  50. it( 'should process loose ordered list with spaces', () => {
  51. const viewFragment = dataProcessor.toView( '1. item 1\n\n2. item 2\n\n3. item 3' );
  52. expect( stringify( viewFragment ) ).to.equal( '<ol><li><p>item 1</p></li><li><p>item 2</p></li><li><p>item 3</p></li></ol>' );
  53. } );
  54. it( 'should process ordered list with multiple paragraphs in them', () => {
  55. const viewFragment = dataProcessor.toView(
  56. '1. Item 1, graf one.\n\n' +
  57. ' Item 2. graf two. The quick brown fox jumped over the lazy dogs\n' +
  58. ' back.\n \n' +
  59. '2. Item 2.\n\n' +
  60. '3. Item 3.' );
  61. expect( stringify( viewFragment ) ).to.equal(
  62. '<ol>' +
  63. '<li>' +
  64. '<p>Item 1, graf one.</p>' +
  65. '<p>Item 2. graf two. The quick brown fox jumped over the lazy dogs<br></br>back.</p>' +
  66. '</li>' +
  67. '<li>' +
  68. '<p>Item 2.</p>' +
  69. '</li>' +
  70. '<li>' +
  71. '<p>Item 3.</p>' +
  72. '</li>' +
  73. '</ol>'
  74. );
  75. } );
  76. it( 'should process nested lists', () => {
  77. const viewFragment = dataProcessor.toView( '* Tab\n * Tab\n * Tab' );
  78. expect( stringify( viewFragment ) ).to.equal( '<ul><li>Tab<ul><li>Tab<ul><li>Tab</li></ul></li></ul></li></ul>' );
  79. } );
  80. it( 'should process nested and mixed lists', () => {
  81. const viewFragment = dataProcessor.toView( '1. First\n2. Second:\n * Fee\n * Fie\n * Foe\n3. Third' );
  82. expect( stringify( viewFragment ) ).to.equal(
  83. '<ol>' +
  84. '<li>First</li>' +
  85. '<li>Second:' +
  86. '<ul>' +
  87. '<li>Fee</li>' +
  88. '<li>Fie</li>' +
  89. '<li>Foe</li>' +
  90. '</ul>' +
  91. '</li>' +
  92. '<li>Third</li>' +
  93. '</ol>'
  94. );
  95. } );
  96. it( 'should process nested and mixed loose lists', () => {
  97. const viewFragment = dataProcessor.toView( '1. First\n\n2. Second:\n * Fee\n * Fie\n * Foe\n\n3. Third' );
  98. expect( stringify( viewFragment ) ).to.equal(
  99. '<ol>' +
  100. '<li>' +
  101. '<p>First</p>' +
  102. '</li>' +
  103. '<li>' +
  104. '<p>Second:</p>' +
  105. '<ul>' +
  106. '<li>Fee</li>' +
  107. '<li>Fie</li>' +
  108. '<li>Foe</li>' +
  109. '</ul>' +
  110. '</li>' +
  111. '<li>' +
  112. '<p>Third</p>' +
  113. '</li>' +
  114. '</ol>'
  115. );
  116. } );
  117. it( 'should create same bullet from different list indicators', () => {
  118. const viewFragment = dataProcessor.toView( '* test\n+ test\n- test' );
  119. expect( stringify( viewFragment ) ).to.equal( '<ul><li>test</li><li>test</li><li>test</li></ul>' );
  120. } );
  121. } );
  122. } );
  123. } );