code.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import { testDataProcessor as test } from '/tests/markdown-gfm/_utils/utils.js';
  6. describe( 'GFMDataProcessor', () => {
  7. describe( 'code', () => {
  8. it( 'should process inline code', () => {
  9. test(
  10. 'regular text and `inline code`',
  11. // GitHub is rendering as:
  12. // <p>regular text and <code>inline code</code></p>
  13. '<p>regular text and <code>inline code</code></p>'
  14. );
  15. } );
  16. it( 'should properly process multiple code', () => {
  17. test(
  18. '`this is code` and this is `too`',
  19. // GitHub is rendering as:
  20. // <p><code>this is code</code> and this is <code>too</code></p>
  21. '<p><code>this is code</code> and this is <code>too</code></p>'
  22. );
  23. } );
  24. it( 'should process spaces inside inline code', () => {
  25. test(
  26. 'regular text and` inline code`',
  27. // GitHub is rendering as:
  28. // <p>regular text and<code>inline code</code></p>
  29. '<p>regular text and<code>inline code</code></p>',
  30. // When converting back it will be normalized and spaces
  31. // at the beginning of inline code will be removed.
  32. 'regular text and`inline code`'
  33. );
  34. } );
  35. it( 'should properly process backticks inside code spans #1', () => {
  36. test(
  37. '`` `backticks` ``',
  38. // GitHub is rendering as:
  39. // <p><code>`backticks`</code></p>
  40. '<p><code>`backticks`</code></p>'
  41. );
  42. } );
  43. it( 'should properly process backticks inside code spans #2', () => {
  44. test(
  45. '`` some `backticks` inside ``',
  46. // GitHub is rendering as:
  47. // <p><code>some `backticks` inside</code></p>
  48. '<p><code>some `backticks` inside</code></p>'
  49. );
  50. } );
  51. it( 'should process code blocks indented with tabs', () => {
  52. test(
  53. ' code block',
  54. // GitHub is rendering as:
  55. // <pre><code>code block
  56. // </code></pre>
  57. '<pre><code>code block</code></pre>',
  58. // When converting back tabs are normalized to ```.
  59. '```\n' +
  60. 'code block\n' +
  61. '```'
  62. );
  63. } );
  64. it( 'should process code blocks indented with spaces', () => {
  65. test(
  66. ' code block',
  67. // GitHub is rendering as:
  68. // <pre><code>code block
  69. // </code></pre>
  70. '<pre><code>code block</code></pre>',
  71. // When converting back tabs are normalized to ```.
  72. '```\n' +
  73. 'code block\n' +
  74. '```'
  75. );
  76. } );
  77. it( 'should process multi line code blocks indented with tabs', () => {
  78. test(
  79. ' first line\n' +
  80. ' second line',
  81. // GitHub is rendering as:
  82. // <pre><code>first line
  83. // second line
  84. // </code></pre>
  85. '<pre><code>first line\n' +
  86. 'second line</code></pre>',
  87. // When converting back tabs are normalized to ```.
  88. '```\n' +
  89. 'first line\n' +
  90. 'second line\n' +
  91. '```'
  92. );
  93. } );
  94. it( 'should process multi line code blocks indented with spaces', () => {
  95. test(
  96. ' first line\n' +
  97. ' second line',
  98. // GitHub is rendering as:
  99. // <pre><code>first line
  100. // second line
  101. // </code></pre>
  102. '<pre><code>first line\n' +
  103. 'second line</code></pre>',
  104. // When converting back spaces are normalized to ```.
  105. '```\n' +
  106. 'first line\n' +
  107. 'second line\n' +
  108. '```'
  109. );
  110. } );
  111. it( 'should process multi line code blocks with trailing spaces', () => {
  112. test(
  113. ' the lines in this block \n' +
  114. ' all contain trailing spaces ',
  115. // GitHub is rendering as:
  116. // <pre><code>the lines in this block
  117. // all contain trailing spaces
  118. // </code></pre>
  119. '<pre><code>the lines in this block \n' +
  120. 'all contain trailing spaces </code></pre>',
  121. // When converting back tabs are normalized to ```.
  122. '```\n' +
  123. 'the lines in this block \n' +
  124. 'all contain trailing spaces \n' +
  125. '```'
  126. );
  127. } );
  128. it( 'should process code block with language name', () => {
  129. test(
  130. '``` js\n' +
  131. 'var a = \'hello\';\n' +
  132. 'console.log(a + \' world\');\n' +
  133. '```',
  134. // GitHub is rendering as special html with syntax highlighting.
  135. // We will need to handle this separately by some feature.
  136. '<pre><code class="lang-js">var a = \'hello\';\n' +
  137. 'console.log(a + \' world\');</code></pre>'
  138. );
  139. } );
  140. it( 'should process code block with language name and using ~~~ as delimiter', () => {
  141. test(
  142. '~~~ bash\n' +
  143. '#!/bin/bash\n' +
  144. '~~~',
  145. // GitHub is rendering as special html with syntax highlighting.
  146. // We will need to handle this separately by some feature.
  147. '<pre><code class="lang-bash">#!/bin/bash</code></pre>',
  148. // When converting back ~~~ are normalized to ```.
  149. '``` bash\n' +
  150. '#!/bin/bash\n' +
  151. '```'
  152. );
  153. } );
  154. it( 'should process code block with language name and using ``````` as delimiter', () => {
  155. test(
  156. '``````` js\n' +
  157. 'var a = \'hello\';\n' +
  158. 'console.log(a + \' world\');\n' +
  159. '```````',
  160. // GitHub is rendering as special html with syntax highlighting.
  161. // We will need to handle this separately by some feature.
  162. '<pre><code class="lang-js">var a = \'hello\';\n' +
  163. 'console.log(a + \' world\');</code></pre>',
  164. // When converting back ``````` are normalized to ```.
  165. '``` js\n' +
  166. 'var a = \'hello\';\n' +
  167. 'console.log(a + \' world\');\n' +
  168. '```'
  169. );
  170. } );
  171. it( 'should process code block with language name and using ~~~~~~~~~~ as delimiter', () => {
  172. test(
  173. '~~~~~~~~~~ js\n' +
  174. 'var a = \'hello\';\n' +
  175. 'console.log(a + \' world\');\n' +
  176. '~~~~~~~~~~',
  177. // GitHub is rendering as special html with syntax highlighting.
  178. // We will need to handle this separately by some feature.
  179. '<pre><code class="lang-js">var a = \'hello\';\n' +
  180. 'console.log(a + \' world\');</code></pre>',
  181. // When converting back ~~~~~~~~~~ are normalized to ```.
  182. '``` js\n' +
  183. 'var a = \'hello\';\n' +
  184. 'console.log(a + \' world\');\n' +
  185. '```'
  186. );
  187. } );
  188. it( 'should process empty code block', () => {
  189. test(
  190. '``` js\n' +
  191. '```',
  192. // GitHub is rendering as special html with syntax highlighting.
  193. // We will need to handle this separately by some feature.
  194. '<pre><code class="lang-js"></code></pre>',
  195. // When converting back, empty code blocks will be removed.
  196. // This might be an issue when switching from source to editor
  197. // but changing this cannot be done in to-markdown converters.
  198. ''
  199. );
  200. } );
  201. it( 'should process code block with empty line', () => {
  202. test(
  203. '``` js\n' +
  204. '\n' +
  205. '```',
  206. // GitHub is rendering as special html with syntax highlighting.
  207. // We will need to handle this separately by some feature.
  208. '<pre><code class="lang-js"></code></pre>',
  209. // When converting back, empty code blocks will be removed.
  210. // This might be an issue when switching from source to editor
  211. // but changing this cannot be done in to-markdown converters.
  212. ''
  213. );
  214. } );
  215. it( 'should process nested code', () => {
  216. test(
  217. '````` code `` code ``` `````',
  218. // GitHub is rendering as:
  219. // <p><code>code `` code ```</code></p>
  220. '<p><code>code `` code ```</code></p>',
  221. // When converting back ````` will be normalized to ``.
  222. '`` code `` code ``` ``'
  223. );
  224. } );
  225. } );
  226. } );