tables.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. import { testDataProcessor } from '../_utils/utils';
  6. describe( 'GFMDataProcessor', () => {
  7. describe( 'tables', () => {
  8. it( 'should process tables', () => {
  9. testDataProcessor(
  10. '| Heading 1 | Heading 2\n' +
  11. '| --- | ---\n' +
  12. '| Cell 1 | Cell 2\n' +
  13. '| Cell 3 | Cell 4\n',
  14. '<table>' +
  15. '<thead>' +
  16. '<tr>' +
  17. '<th>Heading 1</th>' +
  18. '<th>Heading 2</th>' +
  19. '</tr>' +
  20. '</thead>' +
  21. '<tbody>' +
  22. '<tr>' +
  23. '<td>Cell 1</td>' +
  24. '<td>Cell 2</td>' +
  25. '</tr>' +
  26. '<tr>' +
  27. '<td>Cell 3</td>' +
  28. '<td>Cell 4</td>' +
  29. '</tr>' +
  30. '</tbody>' +
  31. '</table>',
  32. // After converting back it will be normalized.
  33. '| Heading 1 | Heading 2 |\n' +
  34. '| --- | --- |\n' +
  35. '| Cell 1 | Cell 2 |\n' +
  36. '| Cell 3 | Cell 4 |'
  37. );
  38. } );
  39. it( 'should process tables with aligned columns', () => {
  40. testDataProcessor(
  41. '| Header 1 | Header 2 | Header 3 | Header 4 |\n' +
  42. '| :------: | -------: | :------- | -------- |\n' +
  43. '| Cell 1 | Cell 2 | Cell 3 | Cell 4 |\n' +
  44. '| Cell 5 | Cell 6 | Cell 7 | Cell 8 |',
  45. '<table>' +
  46. '<thead>' +
  47. '<tr>' +
  48. '<th align="center">Header 1</th>' +
  49. '<th align="right">Header 2</th>' +
  50. '<th align="left">Header 3</th>' +
  51. '<th>Header 4</th>' +
  52. '</tr>' +
  53. '</thead>' +
  54. '<tbody>' +
  55. '<tr>' +
  56. '<td align="center">Cell 1</td>' +
  57. '<td align="right">Cell 2</td>' +
  58. '<td align="left">Cell 3</td>' +
  59. '<td>Cell 4</td>' +
  60. '</tr>' +
  61. '<tr>' +
  62. '<td align="center">Cell 5</td>' +
  63. '<td align="right">Cell 6</td>' +
  64. '<td align="left">Cell 7</td>' +
  65. '<td>Cell 8</td>' +
  66. '</tr>' +
  67. '</tbody>' +
  68. '</table>',
  69. // After converting back it will be normalized.
  70. '| Header 1 | Header 2 | Header 3 | Header 4 |\n' +
  71. '| :-: | --: | :-- | --- |\n' +
  72. '| Cell 1 | Cell 2 | Cell 3 | Cell 4 |\n' +
  73. '| Cell 5 | Cell 6 | Cell 7 | Cell 8 |'
  74. );
  75. } );
  76. it( 'should process not table without borders', () => {
  77. testDataProcessor(
  78. 'Header 1 | Header 2\n' +
  79. '-------- | --------\n' +
  80. 'Cell 1 | Cell 2\n' +
  81. 'Cell 3 | Cell 4',
  82. '<table>' +
  83. '<thead>' +
  84. '<tr>' +
  85. '<th>Header 1</th>' +
  86. '<th>Header 2</th>' +
  87. '</tr>' +
  88. '</thead>' +
  89. '<tbody>' +
  90. '<tr>' +
  91. '<td>Cell 1</td>' +
  92. '<td>Cell 2</td>' +
  93. '</tr>' +
  94. '<tr>' +
  95. '<td>Cell 3</td>' +
  96. '<td>Cell 4</td>' +
  97. '</tr>' +
  98. '</tbody>' +
  99. '</table>',
  100. // After converting back it will be normalized.
  101. '| Header 1 | Header 2 |\n' +
  102. '| --- | --- |\n' +
  103. '| Cell 1 | Cell 2 |\n' +
  104. '| Cell 3 | Cell 4 |'
  105. );
  106. } );
  107. it( 'should process formatting inside cells', () => {
  108. testDataProcessor(
  109. 'Header 1|Header 2|Header 3|Header 4\n' +
  110. ':-------|:------:|-------:|--------\n' +
  111. '*Cell 1* |**Cell 2** |~Cell 3~ |Cell 4',
  112. '<table>' +
  113. '<thead>' +
  114. '<tr>' +
  115. '<th align="left">Header 1</th>' +
  116. '<th align="center">Header 2</th>' +
  117. '<th align="right">Header 3</th>' +
  118. '<th>Header 4</th>' +
  119. '</tr>' +
  120. '</thead>' +
  121. '<tbody>' +
  122. '<tr>' +
  123. '<td align="left">' +
  124. '<em>Cell 1</em>' +
  125. '</td>' +
  126. '<td align="center">' +
  127. '<strong>Cell 2</strong>' +
  128. '</td>' +
  129. '<td align="right">' +
  130. '<del>Cell 3</del>' +
  131. '</td>' +
  132. '<td>' +
  133. 'Cell 4' +
  134. '</td>' +
  135. '</tr>' +
  136. '</tbody>' +
  137. '</table>',
  138. // After converting back it will be normalized.
  139. '| Header 1 | Header 2 | Header 3 | Header 4 |\n' +
  140. '| :-- | :-: | --: | --- |\n' +
  141. '| _Cell 1_ | **Cell 2** | ~Cell 3~ | Cell 4 |'
  142. );
  143. } );
  144. } );
  145. } );