lists.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import { testDataProcessor as test } from 'ckeditor5-markdown-gfm/tests/_utils/utils';
  6. describe( 'GFMDataProcessor', () => {
  7. describe( 'lists', () => {
  8. it( 'should process tight asterisks', () => {
  9. test(
  10. '* item 1\n' +
  11. '* item 2\n' +
  12. '* item 3',
  13. // GitHub renders it as (notice spaces before list items)
  14. // <ul>
  15. // <li> item 1</li>
  16. // <li> item 2</li>
  17. // <li> item 3</li>
  18. // </ul>
  19. '<ul><li>item 1</li><li>item 2</li><li>item 3</li></ul>',
  20. // List will be normalized to 3-space representation.
  21. '* item 1\n' +
  22. '* item 2\n' +
  23. '* item 3'
  24. );
  25. } );
  26. it( 'should process loose asterisks', () => {
  27. test(
  28. '* item 1\n' +
  29. '\n' +
  30. '* item 2\n' +
  31. '\n' +
  32. '* item 3',
  33. // Loose lists are rendered with with paragraph inside.
  34. '<ul>' +
  35. '<li>' +
  36. '<p>item 1</p>' +
  37. '</li>' +
  38. '<li>' +
  39. '<p>item 2</p>' +
  40. '</li>' +
  41. '<li>' +
  42. '<p>item 3</p>' +
  43. '</li>' +
  44. '</ul>',
  45. // List will be normalized to 3-space representation.
  46. '* item 1\n' +
  47. '\n' +
  48. '* item 2\n' +
  49. '\n' +
  50. '* item 3'
  51. );
  52. } );
  53. it( 'should process tight pluses', () => {
  54. test(
  55. '+ item 1\n' +
  56. '+ item 2\n' +
  57. '+ item 3',
  58. '<ul>' +
  59. '<li>item 1</li>' +
  60. '<li>item 2</li>' +
  61. '<li>item 3</li>' +
  62. '</ul>',
  63. // List will be normalized to asterisks, 3-space representation.
  64. '* item 1\n' +
  65. '* item 2\n' +
  66. '* item 3'
  67. );
  68. } );
  69. it( 'should process loose pluses', () => {
  70. test(
  71. '+ item 1\n' +
  72. '\n' +
  73. '+ item 2\n' +
  74. '\n' +
  75. '+ item 3',
  76. '<ul>' +
  77. '<li>' +
  78. '<p>item 1</p>' +
  79. '</li>' +
  80. '<li>' +
  81. '<p>item 2</p>' +
  82. '</li>' +
  83. '<li>' +
  84. '<p>item 3</p>' +
  85. '</li>' +
  86. '</ul>',
  87. // List will be normalized to asterisks, 3-space representation.
  88. '* item 1\n' +
  89. '\n' +
  90. '* item 2\n' +
  91. '\n' +
  92. '* item 3'
  93. );
  94. } );
  95. it( 'should process tight minuses', () => {
  96. test(
  97. '- item 1\n' +
  98. '- item 2\n' +
  99. '- item 3',
  100. '<ul>' +
  101. '<li>item 1</li>' +
  102. '<li>item 2</li>' +
  103. '<li>item 3</li>' +
  104. '</ul>',
  105. // List will be normalized to asterisks, 3-space representation.
  106. '* item 1\n' +
  107. '* item 2\n' +
  108. '* item 3'
  109. );
  110. } );
  111. it( 'should process loose minuses', () => {
  112. test(
  113. '- item 1\n' +
  114. '\n' +
  115. '- item 2\n' +
  116. '\n' +
  117. '- item 3' ,
  118. '<ul>' +
  119. '<li>' +
  120. '<p>item 1</p>' +
  121. '</li>' +
  122. '<li>' +
  123. '<p>item 2</p>' +
  124. '</li>' +
  125. '<li>' +
  126. '<p>item 3</p>' +
  127. '</li>' +
  128. '</ul>',
  129. // List will be normalized to asterisks, 3-space representation.
  130. '* item 1\n' +
  131. '\n' +
  132. '* item 2\n' +
  133. '\n' +
  134. '* item 3'
  135. );
  136. } );
  137. it( 'should process ordered list with tabs', () => {
  138. test(
  139. '1. item 1\n' +
  140. '2. item 2\n' +
  141. '3. item 3',
  142. '<ol>' +
  143. '<li>item 1</li>' +
  144. '<li>item 2</li>' +
  145. '<li>item 3</li>' +
  146. '</ol>',
  147. // List will be normalized to 2-space representation.
  148. '1. item 1\n' +
  149. '2. item 2\n' +
  150. '3. item 3'
  151. );
  152. } );
  153. it( 'should process ordered list with spaces', () => {
  154. test(
  155. '1. item 1\n' +
  156. '2. item 2\n' +
  157. '3. item 3',
  158. '<ol>' +
  159. '<li>item 1</li>' +
  160. '<li>item 2</li>' +
  161. '<li>item 3</li>' +
  162. '</ol>',
  163. // List will be normalized to 2-space representation.
  164. '1. item 1\n' +
  165. '2. item 2\n' +
  166. '3. item 3'
  167. );
  168. } );
  169. it( 'should process loose ordered list with tabs', () => {
  170. test(
  171. '1. item 1\n' +
  172. '\n' +
  173. '2. item 2\n' +
  174. '\n' +
  175. '3. item 3',
  176. '<ol>' +
  177. '<li>' +
  178. '<p>item 1</p>' +
  179. '</li>' +
  180. '<li>' +
  181. '<p>item 2</p>' +
  182. '</li>' +
  183. '<li>' +
  184. '<p>item 3</p>' +
  185. '</li>' +
  186. '</ol>',
  187. // List will be normalized to 2-space representation.
  188. '1. item 1\n' +
  189. '\n' +
  190. '2. item 2\n' +
  191. '\n' +
  192. '3. item 3'
  193. );
  194. } );
  195. it( 'should process loose ordered list with spaces', () => {
  196. test(
  197. '1. item 1\n' +
  198. '\n' +
  199. '2. item 2\n' +
  200. '\n' +
  201. '3. item 3',
  202. '<ol>' +
  203. '<li>' +
  204. '<p>item 1</p>' +
  205. '</li>' +
  206. '<li>' +
  207. '<p>item 2</p>' +
  208. '</li>' +
  209. '<li>' +
  210. '<p>item 3</p>' +
  211. '</li>' +
  212. '</ol>',
  213. // List will be normalized to 2-space representation.
  214. '1. item 1\n' +
  215. '\n' +
  216. '2. item 2\n' +
  217. '\n' +
  218. '3. item 3'
  219. );
  220. } );
  221. it( 'should process nested and mixed lists', () => {
  222. test(
  223. '1. First\n' +
  224. '2. Second:\n' +
  225. ' * Fee\n' +
  226. ' * Fie\n' +
  227. ' * Foe\n' +
  228. '3. Third',
  229. '<ol>' +
  230. '<li>First</li>' +
  231. '<li>Second:' +
  232. '<ul>' +
  233. '<li>Fee</li>' +
  234. '<li>Fie</li>' +
  235. '<li>Foe</li>' +
  236. '</ul>' +
  237. '</li>' +
  238. '<li>Third</li>' +
  239. '</ol>',
  240. // All lists will be normalized after converting back.
  241. '1. First\n' +
  242. '2. Second:\n' +
  243. ' * Fee\n' +
  244. ' * Fie\n' +
  245. ' * Foe\n' +
  246. '3. Third'
  247. );
  248. } );
  249. it( 'should process nested and mixed loose lists', () => {
  250. test(
  251. '1. First\n' +
  252. '\n' +
  253. '2. Second:\n' +
  254. ' * Fee\n' +
  255. ' * Fie\n' +
  256. ' * Foe\n' +
  257. '\n' +
  258. '3. Third',
  259. '<ol>' +
  260. '<li>' +
  261. '<p>First</p>' +
  262. '</li>' +
  263. '<li>' +
  264. '<p>Second:</p>' +
  265. '<ul>' +
  266. '<li>Fee</li>' +
  267. '<li>Fie</li>' +
  268. '<li>Foe</li>' +
  269. '</ul>' +
  270. '</li>' +
  271. '<li>' +
  272. '<p>Third</p>' +
  273. '</li>' +
  274. '</ol>',
  275. // All lists will be normalized after converting back.
  276. '1. First\n' +
  277. '\n' +
  278. '2. Second:\n' +
  279. '\n' +
  280. ' * Fee\n' +
  281. ' * Fie\n' +
  282. ' * Foe\n' +
  283. '3. Third'
  284. );
  285. } );
  286. it( 'should create same bullet from different list indicators', () => {
  287. test(
  288. '* test\n' +
  289. '+ test\n' +
  290. '- test',
  291. '<ul>' +
  292. '<li>test</li>' +
  293. '<li>test</li>' +
  294. '<li>test</li>' +
  295. '</ul>',
  296. // After converting back list items will be unified.
  297. '* test\n' +
  298. '* test\n' +
  299. '* test'
  300. );
  301. } );
  302. } );
  303. } );