kramdown 0.14.2 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of kramdown might be problematic. Click here for more details.

Files changed (323) hide show
  1. checksums.yaml +7 -0
  2. data/CONTRIBUTERS +63 -1
  3. data/COPYING +17 -11
  4. data/README.md +35 -14
  5. data/VERSION +1 -1
  6. data/bin/kramdown +92 -40
  7. data/data/kramdown/document.html +4 -0
  8. data/data/kramdown/document.latex +7 -0
  9. data/lib/kramdown.rb +3 -16
  10. data/lib/kramdown/converter.rb +42 -16
  11. data/lib/kramdown/converter/base.rb +102 -38
  12. data/lib/kramdown/converter/hash_ast.rb +38 -0
  13. data/lib/kramdown/converter/html.rb +232 -141
  14. data/lib/kramdown/converter/kramdown.rb +122 -104
  15. data/lib/kramdown/converter/latex.rb +95 -78
  16. data/lib/kramdown/converter/man.rb +300 -0
  17. data/lib/kramdown/converter/math_engine/mathjax.rb +32 -0
  18. data/lib/kramdown/converter/remove_html_tags.rb +8 -17
  19. data/lib/kramdown/converter/syntax_highlighter.rb +56 -0
  20. data/lib/kramdown/converter/syntax_highlighter/minted.rb +35 -0
  21. data/lib/kramdown/converter/syntax_highlighter/rouge.rb +85 -0
  22. data/lib/kramdown/converter/toc.rb +7 -20
  23. data/lib/kramdown/document.rb +30 -37
  24. data/lib/kramdown/element.rb +54 -27
  25. data/lib/kramdown/error.rb +3 -16
  26. data/lib/kramdown/options.rb +392 -247
  27. data/lib/kramdown/parser.rb +3 -16
  28. data/lib/kramdown/parser/base.rb +28 -33
  29. data/lib/kramdown/parser/html.rb +151 -119
  30. data/lib/kramdown/parser/kramdown.rb +87 -50
  31. data/lib/kramdown/parser/kramdown/abbreviation.rb +33 -27
  32. data/lib/kramdown/parser/kramdown/autolink.rb +7 -25
  33. data/lib/kramdown/parser/kramdown/blank_line.rb +6 -19
  34. data/lib/kramdown/parser/kramdown/block_boundary.rb +6 -18
  35. data/lib/kramdown/parser/kramdown/blockquote.rb +6 -19
  36. data/lib/kramdown/parser/kramdown/codeblock.rb +15 -24
  37. data/lib/kramdown/parser/kramdown/codespan.rb +20 -22
  38. data/lib/kramdown/parser/kramdown/emphasis.rb +15 -24
  39. data/lib/kramdown/parser/kramdown/eob.rb +3 -16
  40. data/lib/kramdown/parser/kramdown/escaped_chars.rb +3 -16
  41. data/lib/kramdown/parser/kramdown/extensions.rb +66 -56
  42. data/lib/kramdown/parser/kramdown/footnote.rb +21 -31
  43. data/lib/kramdown/parser/kramdown/header.rb +37 -37
  44. data/lib/kramdown/parser/kramdown/horizontal_rule.rb +5 -17
  45. data/lib/kramdown/parser/kramdown/html.rb +47 -56
  46. data/lib/kramdown/parser/kramdown/html_entity.rb +9 -19
  47. data/lib/kramdown/parser/kramdown/line_break.rb +4 -17
  48. data/lib/kramdown/parser/kramdown/link.rb +39 -38
  49. data/lib/kramdown/parser/kramdown/list.rb +124 -82
  50. data/lib/kramdown/parser/kramdown/math.rb +12 -24
  51. data/lib/kramdown/parser/kramdown/paragraph.rb +23 -24
  52. data/lib/kramdown/parser/kramdown/smart_quotes.rb +26 -66
  53. data/lib/kramdown/parser/kramdown/table.rb +41 -48
  54. data/lib/kramdown/parser/kramdown/typographic_symbol.rb +14 -22
  55. data/lib/kramdown/parser/markdown.rb +11 -23
  56. data/lib/kramdown/utils.rb +21 -18
  57. data/lib/kramdown/utils/configurable.rb +45 -0
  58. data/lib/kramdown/utils/entities.rb +287 -292
  59. data/lib/kramdown/utils/html.rb +27 -30
  60. data/lib/kramdown/utils/lru_cache.rb +41 -0
  61. data/lib/kramdown/utils/string_scanner.rb +81 -0
  62. data/lib/kramdown/utils/unidecoder.rb +50 -0
  63. data/lib/kramdown/version.rb +4 -17
  64. data/man/man1/kramdown.1 +340 -347
  65. data/test/run_tests.rb +7 -20
  66. data/test/test_files.rb +188 -100
  67. data/test/test_location.rb +216 -0
  68. data/test/test_string_scanner_kramdown.rb +27 -0
  69. data/test/testcases/block/03_paragraph/indented.html.gfm +18 -0
  70. data/test/testcases/block/03_paragraph/line_break_last_line.html +9 -0
  71. data/test/testcases/block/03_paragraph/line_break_last_line.text +9 -0
  72. data/test/testcases/block/03_paragraph/standalone_image.html +8 -0
  73. data/test/testcases/block/03_paragraph/standalone_image.text +6 -0
  74. data/test/testcases/block/03_paragraph/with_html_to_native.html +1 -0
  75. data/test/testcases/block/03_paragraph/with_html_to_native.options +1 -0
  76. data/test/testcases/block/03_paragraph/with_html_to_native.text +1 -0
  77. data/test/testcases/block/04_header/atx_header.html +15 -1
  78. data/test/testcases/block/04_header/atx_header.text +14 -1
  79. data/test/testcases/block/04_header/setext_header.html +3 -1
  80. data/test/testcases/block/04_header/setext_header.text +4 -1
  81. data/test/testcases/block/04_header/with_auto_id_stripping.html +1 -0
  82. data/test/testcases/block/04_header/with_auto_id_stripping.options +1 -0
  83. data/test/testcases/block/04_header/with_auto_id_stripping.text +1 -0
  84. data/test/testcases/block/04_header/with_auto_ids.html +2 -0
  85. data/test/testcases/block/04_header/with_auto_ids.options +1 -0
  86. data/test/testcases/block/04_header/with_auto_ids.text +2 -0
  87. data/test/testcases/block/06_codeblock/guess_lang_css_class.html +15 -0
  88. data/test/testcases/block/06_codeblock/guess_lang_css_class.options +2 -0
  89. data/test/testcases/block/06_codeblock/guess_lang_css_class.text +13 -0
  90. data/test/testcases/block/06_codeblock/highlighting-minted-with-opts.latex +9 -0
  91. data/test/testcases/block/06_codeblock/highlighting-minted-with-opts.options +4 -0
  92. data/test/testcases/block/06_codeblock/highlighting-minted-with-opts.text +5 -0
  93. data/test/testcases/block/06_codeblock/highlighting-minted.latex +8 -0
  94. data/test/testcases/block/06_codeblock/highlighting-minted.options +3 -0
  95. data/test/testcases/block/06_codeblock/highlighting-minted.text +4 -0
  96. data/test/testcases/block/06_codeblock/highlighting-opts.html +6 -0
  97. data/test/testcases/block/06_codeblock/highlighting-opts.options +7 -0
  98. data/test/testcases/block/06_codeblock/highlighting-opts.text +4 -0
  99. data/test/testcases/block/06_codeblock/highlighting.html +5 -6
  100. data/test/testcases/block/06_codeblock/issue_gh45.html +164 -0
  101. data/test/testcases/block/06_codeblock/issue_gh45.test +188 -0
  102. data/test/testcases/block/06_codeblock/rouge/disabled.html +2 -0
  103. data/test/testcases/block/06_codeblock/rouge/disabled.options +4 -0
  104. data/test/testcases/block/06_codeblock/rouge/disabled.text +1 -0
  105. data/test/testcases/block/06_codeblock/rouge/multiple.html +11 -0
  106. data/test/testcases/block/06_codeblock/rouge/multiple.options +4 -0
  107. data/test/testcases/block/06_codeblock/rouge/multiple.text +11 -0
  108. data/test/testcases/block/06_codeblock/rouge/simple.html +10 -0
  109. data/test/testcases/block/06_codeblock/rouge/simple.options +3 -0
  110. data/test/testcases/block/06_codeblock/rouge/simple.text +9 -0
  111. data/test/testcases/block/06_codeblock/with_lang_in_fenced_block.options +1 -1
  112. data/test/testcases/block/06_codeblock/with_lang_in_fenced_block_any_char.html +8 -0
  113. data/test/testcases/block/06_codeblock/with_lang_in_fenced_block_any_char.options +2 -0
  114. data/test/testcases/block/06_codeblock/with_lang_in_fenced_block_any_char.text +11 -0
  115. data/test/testcases/block/06_codeblock/with_lang_in_fenced_block_name_with_dash.html +3 -0
  116. data/test/testcases/block/06_codeblock/with_lang_in_fenced_block_name_with_dash.options +2 -0
  117. data/test/testcases/block/06_codeblock/with_lang_in_fenced_block_name_with_dash.text +4 -0
  118. data/test/testcases/block/07_horizontal_rule/error.html +2 -2
  119. data/test/testcases/block/07_horizontal_rule/normal.html +2 -0
  120. data/test/testcases/block/07_horizontal_rule/normal.text +3 -0
  121. data/test/testcases/block/08_list/brackets_in_item.latex +3 -0
  122. data/test/testcases/block/08_list/brackets_in_item.text +1 -0
  123. data/test/testcases/block/08_list/lazy_and_nested.html +9 -0
  124. data/test/testcases/block/08_list/lazy_and_nested.text +4 -0
  125. data/test/testcases/block/09_html/html5_attributes.html +2 -0
  126. data/test/testcases/block/09_html/html5_attributes.text +2 -0
  127. data/test/testcases/block/09_html/html_after_block.html +7 -0
  128. data/test/testcases/block/09_html/html_after_block.text +5 -0
  129. data/test/testcases/block/09_html/html_to_native/table_simple.html +13 -0
  130. data/test/testcases/block/09_html/html_to_native/table_simple.text +15 -0
  131. data/test/testcases/block/09_html/html_to_native/typography.html +1 -1
  132. data/test/testcases/block/09_html/not_parsed.html +1 -1
  133. data/test/testcases/block/09_html/processing_instruction.html +5 -6
  134. data/test/testcases/block/09_html/simple.html +1 -5
  135. data/test/testcases/block/09_html/simple.text +1 -5
  136. data/test/testcases/block/09_html/standalone_image_in_div.htmlinput +7 -0
  137. data/test/testcases/block/09_html/standalone_image_in_div.text +8 -0
  138. data/test/testcases/block/09_html/textarea.html +8 -0
  139. data/test/testcases/block/09_html/textarea.text +8 -0
  140. data/test/testcases/block/09_html/xml.html +8 -0
  141. data/test/testcases/block/09_html/xml.text +7 -0
  142. data/test/testcases/block/11_ial/simple.html +5 -1
  143. data/test/testcases/block/11_ial/simple.text +8 -1
  144. data/test/testcases/block/12_extension/options.html +4 -4
  145. data/test/testcases/block/12_extension/options.text +2 -0
  146. data/test/testcases/block/12_extension/options2.html +4 -4
  147. data/test/testcases/block/12_extension/options3.html +7 -6
  148. data/test/testcases/block/12_extension/options3.text +2 -2
  149. data/test/testcases/block/13_definition_list/auto_ids.html +15 -0
  150. data/test/testcases/block/13_definition_list/auto_ids.text +18 -0
  151. data/test/testcases/block/13_definition_list/item_ial.html +5 -0
  152. data/test/testcases/block/13_definition_list/item_ial.text +8 -0
  153. data/test/testcases/block/14_table/empty_tag_in_cell.html +8 -0
  154. data/test/testcases/block/14_table/empty_tag_in_cell.options +1 -0
  155. data/test/testcases/block/14_table/empty_tag_in_cell.text +1 -0
  156. data/test/testcases/block/14_table/errors.html +4 -0
  157. data/test/testcases/block/14_table/errors.text +4 -0
  158. data/test/testcases/block/14_table/header.html +21 -0
  159. data/test/testcases/block/14_table/header.text +7 -0
  160. data/test/testcases/block/14_table/simple.html +22 -7
  161. data/test/testcases/block/14_table/simple.text +4 -0
  162. data/test/testcases/block/14_table/table_with_footnote.html +4 -4
  163. data/test/testcases/block/15_math/gh_128.html +1 -0
  164. data/test/testcases/block/15_math/gh_128.text +1 -0
  165. data/test/testcases/block/15_math/no_engine.html +3 -0
  166. data/test/testcases/block/15_math/no_engine.options +1 -0
  167. data/test/testcases/block/15_math/no_engine.text +2 -0
  168. data/test/testcases/block/15_math/normal.html +17 -14
  169. data/test/testcases/block/15_math/normal.text +2 -0
  170. data/test/testcases/block/16_toc/toc_exclude.html +7 -7
  171. data/test/testcases/block/16_toc/toc_levels.html +5 -5
  172. data/test/testcases/block/16_toc/toc_levels.text +1 -1
  173. data/test/testcases/block/16_toc/toc_with_footnotes.html +5 -5
  174. data/test/testcases/block/16_toc/toc_with_links.html +8 -0
  175. data/test/testcases/block/16_toc/toc_with_links.options +2 -0
  176. data/test/testcases/block/16_toc/toc_with_links.text +8 -0
  177. data/test/testcases/cjk-line-break.html +4 -0
  178. data/test/testcases/cjk-line-break.options +1 -0
  179. data/test/testcases/cjk-line-break.text +12 -0
  180. data/test/testcases/man/example.man +123 -0
  181. data/test/testcases/man/example.text +85 -0
  182. data/test/testcases/man/heading-name-dash-description.man +4 -0
  183. data/test/testcases/man/heading-name-dash-description.text +1 -0
  184. data/test/testcases/man/heading-name-description.man +4 -0
  185. data/test/testcases/man/heading-name-description.text +2 -0
  186. data/test/testcases/man/heading-name-section-description.man +4 -0
  187. data/test/testcases/man/heading-name-section-description.text +1 -0
  188. data/test/testcases/man/heading-name-section.man +2 -0
  189. data/test/testcases/man/heading-name-section.text +1 -0
  190. data/test/testcases/man/heading-name.man +2 -0
  191. data/test/testcases/man/heading-name.text +1 -0
  192. data/test/testcases/man/sections.man +4 -0
  193. data/test/testcases/man/sections.text +11 -0
  194. data/test/testcases/man/text-escaping.man +8 -0
  195. data/test/testcases/man/text-escaping.text +7 -0
  196. data/test/testcases/span/01_link/empty.html +1 -1
  197. data/test/testcases/span/01_link/empty_title.htmlinput +3 -0
  198. data/test/testcases/span/01_link/empty_title.text +7 -0
  199. data/test/testcases/span/01_link/imagelinks.html +1 -0
  200. data/test/testcases/span/01_link/imagelinks.text +2 -0
  201. data/test/testcases/span/01_link/inline.html +1 -1
  202. data/test/testcases/span/01_link/latex_escaping.latex +6 -0
  203. data/test/testcases/span/01_link/latex_escaping.text +5 -0
  204. data/test/testcases/span/01_link/link_defs.html +1 -1
  205. data/test/testcases/span/01_link/link_defs.text +2 -1
  206. data/test/testcases/span/01_link/link_defs_with_ial.html +4 -0
  207. data/test/testcases/span/01_link/link_defs_with_ial.text +16 -0
  208. data/test/testcases/span/01_link/reference.html +3 -3
  209. data/test/testcases/span/02_emphasis/nesting.html +3 -0
  210. data/test/testcases/span/02_emphasis/nesting.text +4 -1
  211. data/test/testcases/span/02_emphasis/normal.html +19 -0
  212. data/test/testcases/span/02_emphasis/normal.options +1 -0
  213. data/test/testcases/span/02_emphasis/normal.text +17 -0
  214. data/test/testcases/span/03_codespan/highlighting-minted.latex +2 -0
  215. data/test/testcases/span/03_codespan/highlighting-minted.options +1 -0
  216. data/test/testcases/span/03_codespan/highlighting-minted.text +1 -0
  217. data/test/testcases/span/03_codespan/highlighting.html +1 -1
  218. data/test/testcases/span/03_codespan/normal-css-class.html +1 -0
  219. data/test/testcases/span/03_codespan/normal-css-class.options +2 -0
  220. data/test/testcases/span/03_codespan/normal-css-class.text +1 -0
  221. data/test/testcases/span/03_codespan/rouge/disabled.html +1 -0
  222. data/test/testcases/span/03_codespan/rouge/disabled.options +4 -0
  223. data/test/testcases/span/03_codespan/rouge/disabled.text +1 -0
  224. data/test/testcases/span/03_codespan/rouge/simple.html +1 -0
  225. data/test/testcases/span/03_codespan/rouge/simple.options +1 -0
  226. data/test/testcases/span/03_codespan/rouge/simple.text +1 -0
  227. data/test/testcases/span/04_footnote/backlink_inline.html +79 -0
  228. data/test/testcases/span/04_footnote/backlink_inline.options +1 -0
  229. data/test/testcases/span/04_footnote/backlink_inline.text +38 -0
  230. data/test/testcases/span/04_footnote/backlink_text.html +9 -0
  231. data/test/testcases/span/04_footnote/backlink_text.options +1 -0
  232. data/test/testcases/span/04_footnote/backlink_text.text +3 -0
  233. data/test/testcases/span/04_footnote/definitions.latex +2 -2
  234. data/test/testcases/span/04_footnote/footnote_nr.html +6 -6
  235. data/test/testcases/span/04_footnote/footnote_prefix.html +12 -0
  236. data/test/testcases/span/04_footnote/footnote_prefix.options +1 -0
  237. data/test/testcases/span/04_footnote/footnote_prefix.text +4 -0
  238. data/test/testcases/span/04_footnote/inside_footnote.html +17 -0
  239. data/test/testcases/span/04_footnote/inside_footnote.text +9 -0
  240. data/test/testcases/span/04_footnote/markers.html +16 -16
  241. data/test/testcases/span/04_footnote/markers.latex +3 -3
  242. data/test/testcases/span/04_footnote/markers.options +2 -0
  243. data/test/testcases/span/04_footnote/markers.text +2 -1
  244. data/test/testcases/span/04_footnote/placement.html +11 -0
  245. data/test/testcases/span/04_footnote/placement.options +1 -0
  246. data/test/testcases/span/04_footnote/placement.text +8 -0
  247. data/test/testcases/span/04_footnote/regexp_problem.html +14 -0
  248. data/test/testcases/span/04_footnote/regexp_problem.options +2 -0
  249. data/test/testcases/span/04_footnote/regexp_problem.text +52 -0
  250. data/test/testcases/span/04_footnote/without_backlink.html +9 -0
  251. data/test/testcases/span/04_footnote/without_backlink.options +1 -0
  252. data/test/testcases/span/04_footnote/without_backlink.text +3 -0
  253. data/test/testcases/span/05_html/button.html +7 -0
  254. data/test/testcases/span/05_html/button.text +7 -0
  255. data/test/testcases/span/05_html/mark_element.html +3 -0
  256. data/test/testcases/span/05_html/mark_element.text +3 -0
  257. data/test/testcases/span/05_html/normal.html +10 -1
  258. data/test/testcases/span/05_html/normal.text +9 -0
  259. data/test/testcases/span/05_html/raw_span_elements.html +2 -0
  260. data/test/testcases/span/05_html/raw_span_elements.text +2 -0
  261. data/test/testcases/span/05_html/xml.html +5 -0
  262. data/test/testcases/span/05_html/xml.text +5 -0
  263. data/test/testcases/span/abbreviations/abbrev.html +14 -1
  264. data/test/testcases/span/abbreviations/abbrev.text +18 -2
  265. data/test/testcases/span/abbreviations/in_footnote.html +9 -0
  266. data/test/testcases/span/abbreviations/in_footnote.text +5 -0
  267. data/test/testcases/span/autolinks/url_links.html +5 -4
  268. data/test/testcases/span/autolinks/url_links.text +1 -0
  269. data/test/testcases/span/line_breaks/normal.html +2 -2
  270. data/test/testcases/span/line_breaks/normal.latex +2 -2
  271. data/test/testcases/span/math/no_engine.html +1 -0
  272. data/test/testcases/span/math/no_engine.options +1 -0
  273. data/test/testcases/span/math/no_engine.text +1 -0
  274. data/test/testcases/span/math/normal.html +4 -3
  275. data/test/testcases/span/math/normal.text +2 -1
  276. data/test/testcases/span/text_substitutions/entities_as_char.html +1 -1
  277. data/test/testcases/span/text_substitutions/entities_as_char.options +1 -0
  278. data/test/testcases/span/text_substitutions/entities_as_char.text +1 -1
  279. data/test/testcases/span/text_substitutions/typography.html +22 -0
  280. data/test/testcases/span/text_substitutions/typography.text +22 -0
  281. data/test/testcases/span/text_substitutions/typography_subst.html +3 -0
  282. data/test/testcases/span/text_substitutions/typography_subst.latex +4 -0
  283. data/test/testcases/span/text_substitutions/typography_subst.options +8 -0
  284. data/test/testcases/span/text_substitutions/typography_subst.text +3 -0
  285. metadata +218 -67
  286. data/ChangeLog +0 -7436
  287. data/GPL +0 -674
  288. data/Rakefile +0 -306
  289. data/benchmark/benchmark.rb +0 -36
  290. data/benchmark/benchmark.sh +0 -74
  291. data/benchmark/generate_data.rb +0 -119
  292. data/benchmark/mdbasics.text +0 -306
  293. data/benchmark/mdsyntax.text +0 -888
  294. data/benchmark/testing.sh +0 -9
  295. data/benchmark/timing.sh +0 -10
  296. data/doc/bg.png +0 -0
  297. data/doc/default.scss.css +0 -181
  298. data/doc/default.template +0 -68
  299. data/doc/design.scss.css +0 -441
  300. data/doc/documentation.page +0 -84
  301. data/doc/documentation.template +0 -20
  302. data/doc/index.page +0 -94
  303. data/doc/installation.page +0 -88
  304. data/doc/links.markdown +0 -6
  305. data/doc/metainfo +0 -3
  306. data/doc/news.feed +0 -10
  307. data/doc/news.page +0 -29
  308. data/doc/options.page +0 -10
  309. data/doc/quickref.page +0 -598
  310. data/doc/sidebar.template +0 -21
  311. data/doc/syntax.page +0 -1700
  312. data/doc/tests.page +0 -91
  313. data/doc/virtual +0 -2
  314. data/lib/kramdown/compatibility.rb +0 -49
  315. data/lib/kramdown/utils/ordered_hash.rb +0 -100
  316. data/setup.rb +0 -1585
  317. data/test/testcases/block/07_horizontal_rule/error.html.19 +0 -7
  318. data/test/testcases/block/09_html/html_to_native/typography.html.19 +0 -1
  319. data/test/testcases/block/09_html/simple.html.19 +0 -64
  320. data/test/testcases/block/14_table/simple.html.19 +0 -177
  321. data/test/testcases/span/01_link/inline.html.19 +0 -46
  322. data/test/testcases/span/01_link/reference.html.19 +0 -37
  323. data/test/testcases/span/text_substitutions/entities_as_char.html.19 +0 -1
@@ -1,22 +1,9 @@
1
- # -*- coding: utf-8 -*-
1
+ # -*- coding: utf-8; frozen_string_literal: true -*-
2
2
  #
3
3
  #--
4
- # Copyright (C) 2009-2012 Thomas Leitner <t_leitner@gmx.at>
4
+ # Copyright (C) 2009-2019 Thomas Leitner <t_leitner@gmx.at>
5
5
  #
6
- # This file is part of kramdown.
7
- #
8
- # kramdown is free software: you can redistribute it and/or modify
9
- # it under the terms of the GNU General Public License as published by
10
- # the Free Software Foundation, either version 3 of the License, or
11
- # (at your option) any later version.
12
- #
13
- # This program is distributed in the hope that it will be useful,
14
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- # GNU General Public License for more details.
17
- #
18
- # You should have received a copy of the GNU General Public License
19
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
6
+ # This file is part of kramdown which is licensed under the MIT.
20
7
  #++
21
8
  #
22
9
 
@@ -35,7 +22,7 @@ arg = if File.directory?(arg)
35
22
  arg + '.text'
36
23
  end
37
24
 
38
- width = ((size = %x{stty size 2>/dev/null}).length > 0 ? size.split.last.to_i : 72) rescue 72
25
+ width = ((size = `stty size 2>/dev/null`).length > 0 ? size.split.last.to_i : 72) rescue 72
39
26
  width -= 8
40
27
  fwidth = 0
41
28
  Dir[arg].each {|f| fwidth = [fwidth, f.length + 10].max }.each do |file|
@@ -44,13 +31,13 @@ Dir[arg].each {|f| fwidth = [fwidth, f.length + 10].max }.each do |file|
44
31
 
45
32
  html_file = file.sub('.text', '.html')
46
33
  opts_file = file.sub('.text', '.options')
47
- opts_file = File.join(File.dirname(file), 'options') if !File.exist?(opts_file)
48
- options = File.exist?(opts_file) ? YAML::load(File.read(opts_file)) : {:auto_ids => false, :footnote_nr => 1}
34
+ opts_file = File.join(File.dirname(file), 'options') unless File.exist?(opts_file)
35
+ options = File.exist?(opts_file) ? YAML.safe_load(File.read(opts_file)) : {auto_ids: false, footnote_nr: 1}
49
36
  doc = Kramdown::Document.new(File.read(file), options)
50
37
  begin
51
38
  assert_equal(File.read(html_file), doc.to_html)
52
39
  puts 'PASSED'
53
- rescue Exception => e
40
+ rescue StandardError
54
41
  puts ' FAILED'
55
42
  puts $!.message if $VERBOSE
56
43
  puts $!.backtrace if $DEBUG
@@ -1,85 +1,121 @@
1
- # -*- coding: utf-8 -*-
1
+ # -*- coding: utf-8; frozen_string_literal: true -*-
2
2
  #
3
3
  #--
4
- # Copyright (C) 2009-2012 Thomas Leitner <t_leitner@gmx.at>
4
+ # Copyright (C) 2009-2019 Thomas Leitner <t_leitner@gmx.at>
5
5
  #
6
- # This file is part of kramdown.
7
- #
8
- # kramdown is free software: you can redistribute it and/or modify
9
- # it under the terms of the GNU General Public License as published by
10
- # the Free Software Foundation, either version 3 of the License, or
11
- # (at your option) any later version.
12
- #
13
- # This program is distributed in the hope that it will be useful,
14
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- # GNU General Public License for more details.
17
- #
18
- # You should have received a copy of the GNU General Public License
19
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
6
+ # This file is part of kramdown which is licensed under the MIT.
20
7
  #++
21
8
  #
22
9
 
23
- require 'test/unit'
10
+ require 'minitest/autorun'
24
11
  require 'kramdown'
25
12
  require 'yaml'
26
13
  require 'tmpdir'
14
+ require 'open3'
15
+
16
+ begin
17
+ require 'kramdown/converter/syntax_highlighter/rouge'
18
+
19
+ Kramdown::Converter::SyntaxHighlighter::Rouge.formatter_class.send(:define_method, :format) do |tokens, &b|
20
+ super(tokens, &b).sub(/<\/code><\/pre>\n?/, "</code></pre>\n")
21
+ end
27
22
 
28
- Encoding.default_external = 'utf-8' if RUBY_VERSION >= '1.9'
23
+ # custom formatter for tests
24
+ class RougeHTMLFormatters < Kramdown::Converter::SyntaxHighlighter::Rouge.formatter_class
29
25
 
30
- class TestFiles < Test::Unit::TestCase
26
+ tag 'rouge_html_formatters'
27
+
28
+ def stream(tokens, &b)
29
+ yield %(<div class="custom-class">)
30
+ super
31
+ yield %(</div>)
32
+ end
33
+
34
+ end
35
+ rescue LoadError, SyntaxError, NameError
36
+ end
37
+
38
+ Encoding.default_external = 'utf-8'
39
+
40
+ class TestFiles < Minitest::Test
41
+
42
+ EXCLUDE_KD_FILES = [].compact
31
43
 
32
44
  # Generate test methods for kramdown-to-xxx conversion
33
45
  Dir[File.dirname(__FILE__) + '/testcases/**/*.text'].each do |text_file|
46
+ next if EXCLUDE_KD_FILES.any? {|f| text_file =~ /#{f}/ }
34
47
  basename = text_file.sub(/\.text$/, '')
35
48
  opts_file = text_file.sub(/\.text$/, '.options')
36
49
  (Dir[basename + ".*"] - [text_file, opts_file]).each do |output_file|
37
- next if (RUBY_VERSION >= '1.9' && File.exist?(output_file + '.19')) ||
38
- (RUBY_VERSION < '1.9' && output_file =~ /\.19$/)
39
- output_format = File.extname(output_file.sub(/\.19$/, ''))[1..-1]
40
- next if !Kramdown::Converter.const_defined?(output_format[0..0].upcase + output_format[1..-1])
50
+ output_format = File.extname(output_file)[1..-1]
51
+ next unless Kramdown::Converter.const_defined?(output_format[0..0].upcase + output_format[1..-1])
41
52
  define_method('test_' + text_file.tr('.', '_') + "_to_#{output_format}") do
42
- opts_file = File.join(File.dirname(text_file), 'options') if !File.exist?(opts_file)
43
- options = File.exist?(opts_file) ? YAML::load(File.read(opts_file)) : {:auto_ids => false, :footnote_nr => 1}
53
+ opts_file = File.join(File.dirname(text_file), 'options') unless File.exist?(opts_file)
54
+ options = File.exist?(opts_file) ? YAML.load(File.read(opts_file)) : {auto_ids: false, footnote_nr: 1}
44
55
  doc = Kramdown::Document.new(File.read(text_file), options)
45
56
  assert_equal(File.read(output_file), doc.send("to_#{output_format}"))
46
57
  end
47
58
  end
48
59
  end
49
60
 
50
- # Generate test methods for html-to-html conversion
61
+ # Generate test methods for html-to-{html,kramdown} conversion
51
62
  `tidy -v 2>&1`
52
63
  if $?.exitstatus != 0
53
- warn("Skipping html-to-html tests because tidy executable is missing")
64
+ warn("Skipping html-to-{html,kramdown} tests because tidy executable is missing")
54
65
  else
55
- EXCLUDE_HTML_FILES = ['test/testcases/block/06_codeblock/whitespace.html', # bc of span inside pre
56
- 'test/testcases/block/09_html/simple.html', # bc of xml elements
57
- 'test/testcases/span/03_codespan/highlighting.html', # bc of span elements inside code element
58
- 'test/testcases/block/04_header/with_auto_ids.html', # bc of auto_ids=true option
59
- 'test/testcases/block/04_header/header_type_offset.html', # bc of header_offset option
60
- ]
61
- Dir[File.dirname(__FILE__) + '/testcases/**/*.{html, htmlinput}'].each do |html_file|
62
- next if EXCLUDE_HTML_FILES.any? {|f| html_file =~ /#{f}$/}
63
- out_file = (html_file =~ /\.htmlinput$/ ? html_file.sub(/input$/, '') : html_file)
64
- define_method('test_' + html_file.tr('.', '_') + "_to_html") do
65
- opts_file = html_file.sub(/\.html$/, '.options')
66
- opts_file = File.join(File.dirname(html_file), 'options') if !File.exist?(opts_file)
67
- options = File.exist?(opts_file) ? YAML::load(File.read(opts_file)) : {:auto_ids => false, :footnote_nr => 1}
68
- doc = Kramdown::Document.new(File.read(html_file), options.merge(:input => 'html'))
69
- assert_equal(tidy_output(File.read(out_file)), tidy_output(doc.to_html))
66
+ EXCLUDE_HTML_FILES = [
67
+ 'test/testcases/block/06_codeblock/whitespace.html', # bc of span inside pre
68
+ 'test/testcases/block/09_html/simple.html', # bc of xml elements
69
+ 'test/testcases/span/03_codespan/highlighting.html', # bc of span elements inside code element
70
+ 'test/testcases/block/04_header/with_auto_ids.html', # bc of auto_ids=true option
71
+ 'test/testcases/block/04_header/header_type_offset.html', # bc of header_offset option
72
+ 'test/testcases/block/06_codeblock/rouge/simple.html', # bc of double surrounding <div>
73
+ 'test/testcases/block/06_codeblock/rouge/multiple.html', # bc of double surrounding <div>
74
+ 'test/testcases/block/06_codeblock/highlighting.html', # bc of span elements inside code element
75
+ 'test/testcases/block/06_codeblock/highlighting-opts.html', # bc of span elements inside code element
76
+ 'test/testcases/block/06_codeblock/guess_lang_css_class.html', # bc of double surrounding <div>
77
+ 'test/testcases/block/12_extension/options3.html', # bc of rouge
78
+ 'test/testcases/block/14_table/empty_tag_in_cell.html', # bc of tidy
79
+ 'test/testcases/block/15_math/mathjax_preview.html', # bc of mathjax preview
80
+ 'test/testcases/block/15_math/mathjax_preview_simple.html', # bc of mathjax preview
81
+ 'test/testcases/block/15_math/mathjax_preview_as_code.html', # bc of mathjax preview
82
+ 'test/testcases/span/05_html/mark_element.html', # bc of tidy
83
+ 'test/testcases/block/09_html/xml.html', # bc of tidy
84
+ 'test/testcases/span/05_html/xml.html', # bc of tidy
85
+ ].compact
86
+ EXCLUDE_HTML_TEXT_FILES = [
87
+ 'test/testcases/block/09_html/parse_as_span.htmlinput',
88
+ 'test/testcases/block/09_html/parse_as_raw.htmlinput',
89
+ ].compact
90
+ Dir[File.dirname(__FILE__) + '/testcases/**/*.{html,htmlinput}'].each do |html_file|
91
+ next if EXCLUDE_HTML_FILES.any? {|f| html_file =~ /#{f}/ }
92
+
93
+ out_files = []
94
+ out_files << [(html_file =~ /\.htmlinput$/ ? html_file.sub(/input$/, '') : html_file), :to_html]
95
+ if html_file =~ /\.htmlinput$/ && EXCLUDE_HTML_TEXT_FILES.none? {|f| html_file =~ /#{f}/ }
96
+ out_files << [html_file.sub(/htmlinput$/, 'text'), :to_kramdown]
97
+ end
98
+ out_files.select {|f, _| File.exist?(f) }.each do |out_file, out_method|
99
+ define_method('test_' + html_file.tr('.', '_') + "_to_#{File.extname(out_file)}") do
100
+ opts_file = html_file.sub(/\.html(input)?$/, '.options')
101
+ opts_file = File.join(File.dirname(html_file), 'options') unless File.exist?(opts_file)
102
+ options = File.exist?(opts_file) ? YAML.load(File.read(opts_file)) : {auto_ids: false, footnote_nr: 1}
103
+ doc = Kramdown::Document.new(File.read(html_file), options.merge(input: 'html'))
104
+ if out_method == :to_html
105
+ assert_equal(tidy_output(File.read(out_file)), tidy_output(doc.send(out_method)))
106
+ else
107
+ assert_equal(File.read(out_file), doc.send(out_method))
108
+ end
109
+ end
70
110
  end
71
111
  end
72
112
  end
73
113
 
74
114
  def tidy_output(out)
75
- cmd = "tidy -q --doctype omit #{RUBY_VERSION >= '1.9' ? '-utf8' : '-raw'} 2>/dev/null"
76
- result = IO.popen(cmd, 'r+') do |io|
77
- io.write(out)
78
- io.close_write
79
- io.read
80
- end
81
- if $?.exitstatus == 2
82
- raise "Problem using tidy"
115
+ cmd = "tidy -q --doctype omit -utf8"
116
+ result, error, status = Open3.capture3(cmd, stdin_data: out)
117
+ if status.exitstatus == 2
118
+ raise "Problem using tidy: #{error}"
83
119
  end
84
120
  result
85
121
  end
@@ -89,22 +125,29 @@ class TestFiles < Test::Unit::TestCase
89
125
  if $?.exitstatus != 0
90
126
  warn("Skipping latex compilation tests because latex executable is missing")
91
127
  else
92
- EXCLUDE_LATEX_FILES = ['test/testcases/span/01_link/image_in_a.text', # bc of image link
93
- 'test/testcases/span/01_link/imagelinks.text', # bc of image links
94
- 'test/testcases/span/04_footnote/markers.text', # bc of footnote in header
95
- ]
128
+ EXCLUDE_LATEX_FILES = [
129
+ 'test/testcases/span/01_link/image_in_a.text', # bc of image link
130
+ 'test/testcases/span/01_link/imagelinks.text', # bc of image links
131
+ 'test/testcases/span/01_link/empty_title.text',
132
+ 'test/testcases/span/04_footnote/markers.text', # bc of footnote in header
133
+ 'test/testcases/block/06_codeblock/with_lang_in_fenced_block_name_with_dash.text',
134
+ 'test/testcases/block/06_codeblock/with_lang_in_fenced_block_any_char.text',
135
+ 'test/testcases/block/03_paragraph/standalone_image.text', # bc of standalone image
136
+ 'test/testcases/cjk-line-break.text', # latex unicode support
137
+ ].compact
96
138
  Dir[File.dirname(__FILE__) + '/testcases/**/*.text'].each do |text_file|
97
- next if EXCLUDE_LATEX_FILES.any? {|f| text_file =~ /#{f}$/}
139
+ next if EXCLUDE_LATEX_FILES.any? {|f| text_file =~ /#{f}$/ }
98
140
  define_method('test_' + text_file.tr('.', '_') + "_to_latex_compilation") do
99
- latex = Kramdown::Document.new(File.read(text_file),
100
- :auto_ids => false, :footnote_nr => 1,
101
- :template => 'document').to_latex
102
- result = IO.popen("latex -output-directory='#{Dir.tmpdir}' 2>/dev/null", 'r+') do |io|
103
- io.write(latex)
104
- io.close_write
105
- io.read
141
+ latex = Kramdown::Document.new(File.read(text_file), auto_ids: false, footnote_nr: 1,
142
+ template: 'document').to_latex
143
+ Dir.mktmpdir do |tmpdir|
144
+ result = IO.popen("latex -output-directory='#{tmpdir}' 2>/dev/null", 'r+') do |io|
145
+ io.write(latex)
146
+ io.close_write
147
+ io.read
148
+ end
149
+ assert($?.exitstatus == 0, result.scan(/^!(.*\n.*)/).join("\n"))
106
150
  end
107
- assert($?.exitstatus == 0, result.scan(/^!(.*\n.*)/).join("\n"))
108
151
  end
109
152
  end
110
153
  end
@@ -114,26 +157,38 @@ class TestFiles < Test::Unit::TestCase
114
157
  if $?.exitstatus != 0
115
158
  warn("Skipping text->kramdown->html tests because tidy executable is missing")
116
159
  else
117
- EXCLUDE_TEXT_FILES = ['test/testcases/span/05_html/markdown_attr.text', # bc of markdown attr
118
- 'test/testcases/block/09_html/markdown_attr.text', # bc of markdown attr
119
- 'test/testcases/span/extension/options.text', # bc of parse_span_html option
120
- 'test/testcases/block/12_extension/options.text', # bc of options option
121
- 'test/testcases/block/12_extension/options3.text', # bc of options option
122
- 'test/testcases/block/09_html/content_model/tables.text', # bc of parse_block_html option
123
- 'test/testcases/block/09_html/html_to_native/header.text', # bc of auto_ids option that interferes
124
- 'test/testcases/block/09_html/simple.text', # bc of webgen:block elements
125
- 'test/testcases/block/11_ial/simple.text', # bc of change of ordering of attributes in header
126
- 'test/testcases/span/extension/comment.text', # bc of comment text modifications (can this be avoided?)
127
- 'test/testcases/block/04_header/header_type_offset.text', # bc of header_offset being applied twice
128
- ]
160
+ EXCLUDE_TEXT_FILES = [
161
+ 'test/testcases/span/05_html/markdown_attr.text', # bc of markdown attr
162
+ 'test/testcases/block/09_html/markdown_attr.text', # bc of markdown attr
163
+ 'test/testcases/span/extension/options.text', # bc of parse_span_html option
164
+ 'test/testcases/block/12_extension/options.text', # bc of options option
165
+ 'test/testcases/block/12_extension/options3.text', # bc of options option
166
+ 'test/testcases/block/09_html/content_model/tables.text', # bc of parse_block_html option
167
+ 'test/testcases/block/09_html/html_to_native/header.text', # bc of auto_ids option that interferes
168
+ 'test/testcases/block/09_html/html_to_native/table_simple.text', # bc of tr style attr getting removed
169
+ 'test/testcases/block/09_html/simple.text', # bc of webgen:block elements
170
+ 'test/testcases/block/11_ial/simple.text', # bc of change of ordering of attributes in header
171
+ 'test/testcases/span/extension/comment.text', # bc of comment text modifications (can this be avoided?)
172
+ 'test/testcases/block/04_header/header_type_offset.text', # bc of header_offset being applied twice
173
+ 'test/testcases/block/06_codeblock/rouge/simple.text',
174
+ 'test/testcases/block/06_codeblock/rouge/multiple.text', # check, what document contain more, than one code block
175
+ 'test/testcases/block/14_table/empty_tag_in_cell.text', # bc of tidy
176
+ 'test/testcases/span/01_link/link_defs_with_ial.text', # bc of attribute ordering
177
+ 'test/testcases/span/05_html/mark_element.text', # bc of tidy
178
+ 'test/testcases/block/09_html/xml.text', # bc of tidy
179
+ 'test/testcases/span/05_html/xml.text', # bc of tidy
180
+ 'test/testcases/block/03_paragraph/standalone_image.text', # bc of standalone image
181
+ 'test/testcases/cjk-line-break.text',
182
+ 'test/testcases/block/09_html/standalone_image_in_div.html', # bc of standalone image
183
+ ].compact
129
184
  Dir[File.dirname(__FILE__) + '/testcases/**/*.text'].each do |text_file|
130
- next if EXCLUDE_TEXT_FILES.any? {|f| text_file =~ /#{f}$/}
185
+ next if EXCLUDE_TEXT_FILES.any? {|f| text_file =~ /#{f}$/ }
186
+ html_file = text_file.sub(/\.text$/, '.html')
187
+ next unless File.exist?(html_file)
131
188
  define_method('test_' + text_file.tr('.', '_') + "_to_kramdown_to_html") do
132
- html_file = text_file.sub(/\.text$/, '.html')
133
- html_file += '.19' if RUBY_VERSION >= '1.9' && File.exist?(html_file + '.19')
134
189
  opts_file = text_file.sub(/\.text$/, '.options')
135
- opts_file = File.join(File.dirname(text_file), 'options') if !File.exist?(opts_file)
136
- options = File.exist?(opts_file) ? YAML::load(File.read(opts_file)) : {:auto_ids => false, :footnote_nr => 1}
190
+ opts_file = File.join(File.dirname(text_file), 'options') unless File.exist?(opts_file)
191
+ options = File.exist?(opts_file) ? YAML.load(File.read(opts_file)) : {auto_ids: false, footnote_nr: 1}
137
192
  kdtext = Kramdown::Document.new(File.read(text_file), options).to_kramdown
138
193
  html = Kramdown::Document.new(kdtext, options).to_html
139
194
  assert_equal(tidy_output(File.read(html_file)), tidy_output(html))
@@ -146,39 +201,72 @@ class TestFiles < Test::Unit::TestCase
146
201
  if $?.exitstatus != 0
147
202
  warn("Skipping html-to-kramdown-to-html tests because tidy executable is missing")
148
203
  else
149
- EXCLUDE_HTML_KD_FILES = ['test/testcases/span/extension/options.html', # bc of parse_span_html option
150
- 'test/testcases/span/05_html/normal.html', # bc of br tag before closing p tag
151
- 'test/testcases/block/12_extension/nomarkdown.html', # bc of nomarkdown extension
152
- 'test/testcases/block/09_html/simple.html', # bc of webgen:block elements
153
- 'test/testcases/block/09_html/markdown_attr.html', # bc of markdown attr
154
- 'test/testcases/block/09_html/html_to_native/table_simple.html', # bc of invalidly converted simple table
155
- 'test/testcases/block/06_codeblock/whitespace.html', # bc of entity to char conversion
156
- 'test/testcases/block/11_ial/simple.html', # bc of change of ordering of attributes in header
157
- 'test/testcases/span/03_codespan/highlighting.html', # bc of span elements inside code element
158
- 'test/testcases/block/04_header/with_auto_ids.html', # bc of auto_ids=true option
159
- 'test/testcases/block/04_header/header_type_offset.html', # bc of header_offset option
160
- 'test/testcases/block/16_toc/toc_exclude.html', # bc of different attribute ordering
161
- ]
204
+ EXCLUDE_HTML_KD_FILES = [
205
+ 'test/testcases/span/extension/options.html', # bc of parse_span_html option
206
+ 'test/testcases/span/05_html/normal.html', # bc of br tag before closing p tag
207
+ 'test/testcases/block/12_extension/nomarkdown.html', # bc of nomarkdown extension
208
+ 'test/testcases/block/12_extension/options3.html', # bc of rouge
209
+ 'test/testcases/block/09_html/simple.html', # bc of webgen:block elements
210
+ 'test/testcases/block/09_html/markdown_attr.html', # bc of markdown attr
211
+ 'test/testcases/block/09_html/html_to_native/table_simple.html', # bc of invalidly converted simple table
212
+ 'test/testcases/block/06_codeblock/whitespace.html', # bc of entity to char conversion
213
+ 'test/testcases/block/06_codeblock/rouge/simple.html', # bc of double surrounding <div>
214
+ 'test/testcases/block/06_codeblock/rouge/multiple.html', # bc of double surrounding <div>
215
+ 'test/testcases/block/06_codeblock/guess_lang_css_class.html', # bc of double surrounding <div>
216
+ 'test/testcases/block/06_codeblock/highlighting.html', # bc of span elements inside code element
217
+ 'test/testcases/block/06_codeblock/highlighting-opts.html', # bc of span elements inside code element
218
+ 'test/testcases/block/11_ial/simple.html', # bc of change of ordering of attributes in header
219
+ 'test/testcases/span/03_codespan/highlighting.html', # bc of span elements inside code element
220
+ 'test/testcases/block/04_header/with_auto_ids.html', # bc of auto_ids=true option
221
+ 'test/testcases/block/04_header/header_type_offset.html', # bc of header_offset option
222
+ 'test/testcases/block/16_toc/toc_exclude.html', # bc of different attribute ordering
223
+ 'test/testcases/span/autolinks/url_links.html', # bc of quot entity being converted to char
224
+ 'test/testcases/block/14_table/empty_tag_in_cell.html', # bc of tidy
225
+ 'test/testcases/span/01_link/link_defs_with_ial.html', # bc of attribute ordering
226
+ 'test/testcases/span/05_html/mark_element.html', # bc of tidy
227
+ 'test/testcases/block/09_html/xml.html', # bc of tidy
228
+ 'test/testcases/span/05_html/xml.html', # bc of tidy
229
+ 'test/testcases/block/03_paragraph/standalone_image.html', # bc of standalone image
230
+ 'test/testcases/block/15_math/normal.html', # bc of mathjax and HTML parser
231
+ 'test/testcases/block/15_math/gh_128.html', # bc of mathjax and HTML parser
232
+ 'test/testcases/span/04_footnote/backlink_inline.html', # bc of mathjax
233
+ 'test/testcases/block/09_html/standalone_image_in_div.html', # bc of standalone image
234
+ 'test/testcases/block/09_html/processing_instruction.html', # bc of PI
235
+ ].compact
162
236
  Dir[File.dirname(__FILE__) + '/testcases/**/*.html'].each do |html_file|
163
- next if EXCLUDE_HTML_KD_FILES.any? {|f| html_file =~ /#{f}$/}
237
+ next if EXCLUDE_HTML_KD_FILES.any? {|f| html_file =~ /#{f}$/ }
164
238
  define_method('test_' + html_file.tr('.', '_') + "_to_kramdown_to_html") do
165
- kd = Kramdown::Document.new(File.read(html_file), :input => 'html', :auto_ids => false, :footnote_nr => 1).to_kramdown
239
+ kd = Kramdown::Document.new(File.read(html_file), input: 'html',
240
+ auto_ids: false, footnote_nr: 1).to_kramdown
166
241
  opts_file = html_file.sub(/\.html$/, '.options')
167
- opts_file = File.join(File.dirname(html_file), 'options') if !File.exist?(opts_file)
168
- options = File.exist?(opts_file) ? YAML::load(File.read(opts_file)) : {:auto_ids => false, :footnote_nr => 1}
242
+ opts_file = File.join(File.dirname(html_file), 'options') unless File.exist?(opts_file)
243
+ options = File.exist?(opts_file) ? YAML.load(File.read(opts_file)) : {auto_ids: false, footnote_nr: 1}
169
244
  doc = Kramdown::Document.new(kd, options)
170
245
  assert_equal(tidy_output(File.read(html_file)), tidy_output(doc.to_html))
171
246
  end
172
247
  end
173
248
  end
174
249
 
250
+ # Generate test methods for text-manpage conversion
251
+ Dir[File.dirname(__FILE__) + '/testcases/man/**/*.text'].each do |text_file|
252
+ define_method('test_' + text_file.tr('.', '_') + "_to_man") do
253
+ man_file = text_file.sub(/\.text$/, '.man')
254
+ doc = Kramdown::Document.new(File.read(text_file))
255
+ assert_equal(File.read(man_file), doc.to_man)
256
+ end
257
+ end
175
258
 
259
+ EXCLUDE_MODIFY = [
260
+ 'test/testcases/block/06_codeblock/rouge/multiple.text', # bc of HTMLFormater in options
261
+ ].compact
176
262
 
177
263
  # Generate test methods for asserting that converters don't modify the document tree.
178
264
  Dir[File.dirname(__FILE__) + '/testcases/**/*.text'].each do |text_file|
179
265
  opts_file = text_file.sub(/\.text$/, '.options')
180
- options = File.exist?(opts_file) ? YAML::load(File.read(opts_file)) : {:auto_ids => false, :footnote_nr => 1}
181
- (Kramdown::Converter.constants.map {|c| c.to_sym} - [:Base, :RemoveHtmlTags]).each do |conv_class|
266
+ options = File.exist?(opts_file) ? YAML.load(File.read(opts_file)) : {auto_ids: false, footnote_nr: 1}
267
+ (Kramdown::Converter.constants.map(&:to_sym) -
268
+ [:Base, :RemoveHtmlTags, :MathEngine, :SyntaxHighlighter]).each do |conv_class|
269
+ next if EXCLUDE_MODIFY.any? {|f| text_file =~ /#{f}$/ }
182
270
  define_method("test_whether_#{conv_class}_modifies_tree_with_file_#{text_file.tr('.', '_')}") do
183
271
  doc = Kramdown::Document.new(File.read(text_file), options)
184
272
  options_before = Marshal.load(Marshal.dump(doc.options))
@@ -195,7 +283,7 @@ class TestFiles < Test::Unit::TestCase
195
283
  if old.value.kind_of?(Kramdown::Element)
196
284
  assert_tree_not_changed(old.value, new.value)
197
285
  else
198
- assert_equal(old.value, new.value, "value mismatch")
286
+ assert(old.value == new.value, "value mismatch")
199
287
  end
200
288
  assert_equal(old.attr, new.attr, "attr mismatch")
201
289
  assert_equal(old.options, new.options, "options mismatch")
@@ -0,0 +1,216 @@
1
+ # -*- coding: utf-8; frozen_string_literal: true -*-
2
+ #
3
+ #--
4
+ # Copyright (C) 2009-2019 Thomas Leitner <t_leitner@gmx.at>
5
+ #
6
+ # This file is part of kramdown which is licensed under the MIT.
7
+ #++
8
+ #
9
+
10
+ require 'minitest/autorun'
11
+ require 'kramdown'
12
+
13
+ Encoding.default_external = 'utf-8'
14
+
15
+ describe 'location' do
16
+ # checks that +element+'s :location option corresponds to the location stored
17
+ # in the element.attr['class']
18
+ def check_element_for_location(element)
19
+ if (match = /^line-(\d+)/.match(element.attr['class'] || ''))
20
+ expected_line = match[1].to_i
21
+ assert_equal(expected_line, element.options[:location])
22
+ end
23
+ element.children.each do |child|
24
+ check_element_for_location(child)
25
+ end
26
+ end
27
+
28
+ # Test cases consist of a kramdown string that uses IALs to specify the expected
29
+ # line numbers for a given element.
30
+ test_cases = {
31
+ 'autolink' => %(testing autolinks\n\n<http://kramdown.org>{:.line-3}),
32
+ 'blockquote' => %(
33
+ > block quote1
34
+ >
35
+ > * {:.line-3} list item in block quote
36
+ > * {:.line-4} list item in block quote
37
+ > {:.line-3}
38
+ {:.line-1}
39
+
40
+ > block quote2
41
+ {:.line-8}
42
+ ),
43
+ 'codeblock' => %(\na para\n\n~~~~\ntest code 1\n~~~~\n{:.line-3}\n\n test code 2\n{:.line-8}\n),
44
+ 'codespan' => %(a para\n\nanother para `<code>`{:.line-3} with code\n),
45
+ 'emphasis' => %(
46
+ para *span*{:.line-1}
47
+ {:.line-1}
48
+
49
+ ## header *span*{:.line-4}
50
+ {:.line-4}
51
+
52
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
53
+ tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
54
+ quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
55
+ consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
56
+ cillum *short span on single line*{:.line-11}
57
+ dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
58
+ *long span over multiple lines - proident, sunt in culpa qui officia deserunt
59
+ mollit anim id est laborum.*{:.line-13}
60
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
61
+ tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
62
+ quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
63
+ `code span`{:.line-18}
64
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
65
+ tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
66
+ quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
67
+ {:.line-7}
68
+ ),
69
+ 'header' => %(
70
+ # header1
71
+ {:.line-1}
72
+
73
+ ## header2
74
+ {:.line-4}
75
+
76
+ ## header3
77
+ {:.line-7}
78
+
79
+ header4
80
+ =======
81
+ {:.line-10}
82
+
83
+ ^
84
+
85
+ header5
86
+ -------
87
+ {:.line-16}
88
+ ),
89
+ 'horizontal_rule' => %(\na para\n\n----\n{:.line-3}\n),
90
+ 'html_entity' => "a para\n\nanother para with &amp;{:.line-3} html entity.\n",
91
+ 'link' => %(
92
+ a para
93
+
94
+ This is [a link](http://rubyforge.org){:.line-3} to a page.
95
+
96
+ Here comes a ![smiley](../images/smiley.png){:.line-5}
97
+ ),
98
+ 'list' => %(
99
+ * {:.line-1} list item
100
+ * {:.line-2} list item
101
+ * {:.line-3} list item
102
+ {:.line-1}
103
+
104
+ {:.line-7}
105
+ 1. {:.line-7} list item
106
+ 2. {:.line-8} list item
107
+ 3. {:.line-9} list item
108
+
109
+ {:.line-12}
110
+ definition term 1
111
+ : {:.line-13} definition definition 1
112
+ definition term 2
113
+ : {:.line-15} definition definition 2
114
+ ),
115
+ 'math_block' => %(\na para\n\n$$5+5$$\n{:.line-3}\n),
116
+ 'math_inline' => %(\na para\n\nanother para with inline math $$5+5$${:.line-3}\n),
117
+ 'paragraph' => %(
118
+ para1
119
+ {:.line-1}
120
+
121
+ para2
122
+ {:.line-4}
123
+
124
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
125
+ tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
126
+ quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
127
+ consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
128
+ {:.line-7}
129
+
130
+ {:.line-14}
131
+ para with leading IAL
132
+ ),
133
+ 'table' => %(
134
+ a para
135
+
136
+ |first|second|third|
137
+ |-----|------|-----|
138
+ |a |b |c |
139
+ {:.line-3}
140
+ ),
141
+ 'typographic_symbol' => %(
142
+ a para
143
+
144
+ another para ---{:.line-3}
145
+
146
+ another para ...{:.line-5}
147
+ ),
148
+ 'gh issue 129' => %(
149
+ `|`
150
+ {:.line-1}
151
+ ),
152
+ 'gh issue 131' => %(
153
+ * {:.line-1} test
154
+ line 2
155
+ * {:.line-3} second
156
+ * {:.line-4} third
157
+ * {:.line-5} * {:.line-5} one
158
+ * {:.line-6} two
159
+ ),
160
+ 'gh issue 158' => %(
161
+ 😁😁😁😁😁😁😁😁😁😁😁😁😁😁😁😁😁😁😁😁😁😁😁😁😁😁😁😁😁😁
162
+ {:.line-1}
163
+
164
+ - {:.line-4} T
165
+ {:.line-4}
166
+
167
+ # T
168
+ {:.line-7}
169
+ ),
170
+ 'gh issue 243 - HTML raw elements' => %(
171
+ <ul class="line-1">
172
+ <li class="line-2">Test</li>
173
+ </ul>
174
+ ),
175
+ }
176
+ test_cases.each do |name, test_string|
177
+ it "Handles #{name}" do
178
+ doc = Kramdown::Document.new(test_string.gsub(/^ /, '').strip)
179
+ check_element_for_location(doc.root)
180
+ end
181
+ end
182
+
183
+ it 'adds location info to duplicate abbreviation definition warnings' do
184
+ test_string = %(This snippet contains a duplicate abbreviation definition
185
+
186
+ *[duplicate]: The first definition
187
+ *[duplicate]: The second definition
188
+ )
189
+ doc = Kramdown::Document.new(test_string.strip)
190
+ assert_equal(["Duplicate abbreviation ID 'duplicate' on line 4 - overwriting"], doc.warnings)
191
+ end
192
+
193
+ it 'handles abbreviations' do
194
+ str = "This *is* ABC and\n**and** ABC second\nanother ABC\nas ABC as\nABC at the end.\n\n*[ABC]: ABC"
195
+ doc = Kramdown::Document.new(str)
196
+ doc.root.children.first.children.select {|e| e.type == :abbreviation }.each_with_index do |e, i|
197
+ assert_equal(i + 1, e.options[:location])
198
+ end
199
+ end
200
+
201
+ it 'handles line breaks' do
202
+ str = "First \nsecond\\\\\nthird \n"
203
+ doc = Kramdown::Document.new(str)
204
+ doc.root.children.first.children.select {|e| e.type == :br }.each_with_index do |e, i|
205
+ assert_equal(i + 1, e.options[:location])
206
+ end
207
+ end
208
+
209
+ it 'handles smart quotes' do
210
+ str = "This is 'first'\nand 'second' and\n'third'"
211
+ doc = Kramdown::Document.new(str)
212
+ doc.root.children.first.children.select {|e| e.type == :smart_quote }.each_with_index do |e, i|
213
+ assert_equal(((i + 1) / 2.0).ceil, e.options[:location])
214
+ end
215
+ end
216
+ end