daqing_kramdown 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (557) hide show
  1. checksums.yaml +7 -0
  2. data/AUTHORS +1 -0
  3. data/CONTRIBUTERS +78 -0
  4. data/COPYING +30 -0
  5. data/README.md +71 -0
  6. data/VERSION +1 -0
  7. data/bin/daqing_kramdown +132 -0
  8. data/data/kramdown/document.html +22 -0
  9. data/data/kramdown/document.latex +50 -0
  10. data/lib/kramdown.rb +10 -0
  11. data/lib/kramdown/converter.rb +68 -0
  12. data/lib/kramdown/converter/base.rb +261 -0
  13. data/lib/kramdown/converter/hash_ast.rb +38 -0
  14. data/lib/kramdown/converter/html.rb +535 -0
  15. data/lib/kramdown/converter/kramdown.rb +448 -0
  16. data/lib/kramdown/converter/latex.rb +625 -0
  17. data/lib/kramdown/converter/man.rb +300 -0
  18. data/lib/kramdown/converter/math_engine/mathjax.rb +32 -0
  19. data/lib/kramdown/converter/remove_html_tags.rb +57 -0
  20. data/lib/kramdown/converter/syntax_highlighter.rb +56 -0
  21. data/lib/kramdown/converter/syntax_highlighter/minted.rb +35 -0
  22. data/lib/kramdown/converter/syntax_highlighter/rouge.rb +85 -0
  23. data/lib/kramdown/converter/toc.rb +69 -0
  24. data/lib/kramdown/document.rb +139 -0
  25. data/lib/kramdown/element.rb +551 -0
  26. data/lib/kramdown/error.rb +17 -0
  27. data/lib/kramdown/options.rb +604 -0
  28. data/lib/kramdown/parser.rb +26 -0
  29. data/lib/kramdown/parser/base.rb +131 -0
  30. data/lib/kramdown/parser/html.rb +608 -0
  31. data/lib/kramdown/parser/kramdown.rb +376 -0
  32. data/lib/kramdown/parser/kramdown/abbreviation.rb +78 -0
  33. data/lib/kramdown/parser/kramdown/autolink.rb +31 -0
  34. data/lib/kramdown/parser/kramdown/blank_line.rb +30 -0
  35. data/lib/kramdown/parser/kramdown/block_boundary.rb +34 -0
  36. data/lib/kramdown/parser/kramdown/blockquote.rb +38 -0
  37. data/lib/kramdown/parser/kramdown/codeblock.rb +57 -0
  38. data/lib/kramdown/parser/kramdown/codespan.rb +54 -0
  39. data/lib/kramdown/parser/kramdown/emphasis.rb +61 -0
  40. data/lib/kramdown/parser/kramdown/eob.rb +26 -0
  41. data/lib/kramdown/parser/kramdown/escaped_chars.rb +25 -0
  42. data/lib/kramdown/parser/kramdown/extensions.rb +214 -0
  43. data/lib/kramdown/parser/kramdown/footnote.rb +64 -0
  44. data/lib/kramdown/parser/kramdown/header.rb +70 -0
  45. data/lib/kramdown/parser/kramdown/horizontal_rule.rb +27 -0
  46. data/lib/kramdown/parser/kramdown/html.rb +162 -0
  47. data/lib/kramdown/parser/kramdown/html_entity.rb +34 -0
  48. data/lib/kramdown/parser/kramdown/line_break.rb +25 -0
  49. data/lib/kramdown/parser/kramdown/link.rb +149 -0
  50. data/lib/kramdown/parser/kramdown/list.rb +284 -0
  51. data/lib/kramdown/parser/kramdown/math.rb +53 -0
  52. data/lib/kramdown/parser/kramdown/paragraph.rb +62 -0
  53. data/lib/kramdown/parser/kramdown/smart_quotes.rb +174 -0
  54. data/lib/kramdown/parser/kramdown/table.rb +171 -0
  55. data/lib/kramdown/parser/kramdown/typographic_symbol.rb +44 -0
  56. data/lib/kramdown/parser/markdown.rb +57 -0
  57. data/lib/kramdown/utils.rb +45 -0
  58. data/lib/kramdown/utils/configurable.rb +45 -0
  59. data/lib/kramdown/utils/entities.rb +344 -0
  60. data/lib/kramdown/utils/html.rb +84 -0
  61. data/lib/kramdown/utils/lru_cache.rb +41 -0
  62. data/lib/kramdown/utils/string_scanner.rb +81 -0
  63. data/lib/kramdown/utils/unidecoder.rb +50 -0
  64. data/lib/kramdown/version.rb +15 -0
  65. data/man/man1/kramdown.1 +0 -0
  66. data/test/run_tests.rb +46 -0
  67. data/test/test_files.rb +298 -0
  68. data/test/test_location.rb +216 -0
  69. data/test/test_string_scanner_kramdown.rb +27 -0
  70. data/test/testcases/block/01_blank_line/spaces.html +1 -0
  71. data/test/testcases/block/01_blank_line/spaces.text +3 -0
  72. data/test/testcases/block/01_blank_line/tabs.html +1 -0
  73. data/test/testcases/block/01_blank_line/tabs.text +6 -0
  74. data/test/testcases/block/02_eob/beginning.html +1 -0
  75. data/test/testcases/block/02_eob/beginning.text +3 -0
  76. data/test/testcases/block/02_eob/end.html +1 -0
  77. data/test/testcases/block/02_eob/end.text +3 -0
  78. data/test/testcases/block/02_eob/middle.html +1 -0
  79. data/test/testcases/block/02_eob/middle.text +5 -0
  80. data/test/testcases/block/03_paragraph/indented.html +18 -0
  81. data/test/testcases/block/03_paragraph/indented.html.gfm +18 -0
  82. data/test/testcases/block/03_paragraph/indented.text +19 -0
  83. data/test/testcases/block/03_paragraph/line_break_last_line.html +9 -0
  84. data/test/testcases/block/03_paragraph/line_break_last_line.text +9 -0
  85. data/test/testcases/block/03_paragraph/no_newline_at_end.html +5 -0
  86. data/test/testcases/block/03_paragraph/no_newline_at_end.text +5 -0
  87. data/test/testcases/block/03_paragraph/one_para.html +1 -0
  88. data/test/testcases/block/03_paragraph/one_para.text +1 -0
  89. data/test/testcases/block/03_paragraph/standalone_image.html +8 -0
  90. data/test/testcases/block/03_paragraph/standalone_image.text +6 -0
  91. data/test/testcases/block/03_paragraph/two_para.html +4 -0
  92. data/test/testcases/block/03_paragraph/two_para.text +4 -0
  93. data/test/testcases/block/03_paragraph/with_html_to_native.html +1 -0
  94. data/test/testcases/block/03_paragraph/with_html_to_native.options +1 -0
  95. data/test/testcases/block/03_paragraph/with_html_to_native.text +1 -0
  96. data/test/testcases/block/04_header/atx_header.html +57 -0
  97. data/test/testcases/block/04_header/atx_header.text +54 -0
  98. data/test/testcases/block/04_header/atx_header_no_newline_at_end.html +1 -0
  99. data/test/testcases/block/04_header/atx_header_no_newline_at_end.text +1 -0
  100. data/test/testcases/block/04_header/header_type_offset.html +11 -0
  101. data/test/testcases/block/04_header/header_type_offset.kramdown +12 -0
  102. data/test/testcases/block/04_header/header_type_offset.latex +12 -0
  103. data/test/testcases/block/04_header/header_type_offset.options +2 -0
  104. data/test/testcases/block/04_header/header_type_offset.text +13 -0
  105. data/test/testcases/block/04_header/setext_header.html +32 -0
  106. data/test/testcases/block/04_header/setext_header.text +39 -0
  107. data/test/testcases/block/04_header/setext_header_no_newline_at_end.html +1 -0
  108. data/test/testcases/block/04_header/setext_header_no_newline_at_end.text +2 -0
  109. data/test/testcases/block/04_header/with_auto_id_prefix.html +3 -0
  110. data/test/testcases/block/04_header/with_auto_id_prefix.options +2 -0
  111. data/test/testcases/block/04_header/with_auto_id_prefix.text +3 -0
  112. data/test/testcases/block/04_header/with_auto_id_stripping.html +1 -0
  113. data/test/testcases/block/04_header/with_auto_id_stripping.options +1 -0
  114. data/test/testcases/block/04_header/with_auto_id_stripping.text +1 -0
  115. data/test/testcases/block/04_header/with_auto_ids.html +21 -0
  116. data/test/testcases/block/04_header/with_auto_ids.options +2 -0
  117. data/test/testcases/block/04_header/with_auto_ids.text +24 -0
  118. data/test/testcases/block/05_blockquote/indented.html +25 -0
  119. data/test/testcases/block/05_blockquote/indented.text +14 -0
  120. data/test/testcases/block/05_blockquote/lazy.html +34 -0
  121. data/test/testcases/block/05_blockquote/lazy.text +20 -0
  122. data/test/testcases/block/05_blockquote/nested.html +10 -0
  123. data/test/testcases/block/05_blockquote/nested.text +6 -0
  124. data/test/testcases/block/05_blockquote/no_newline_at_end.html +4 -0
  125. data/test/testcases/block/05_blockquote/no_newline_at_end.text +2 -0
  126. data/test/testcases/block/05_blockquote/very_long_line.html +3 -0
  127. data/test/testcases/block/05_blockquote/very_long_line.text +1 -0
  128. data/test/testcases/block/05_blockquote/with_code_blocks.html +15 -0
  129. data/test/testcases/block/05_blockquote/with_code_blocks.text +11 -0
  130. data/test/testcases/block/06_codeblock/disable-highlighting.html +4 -0
  131. data/test/testcases/block/06_codeblock/disable-highlighting.options +1 -0
  132. data/test/testcases/block/06_codeblock/disable-highlighting.text +4 -0
  133. data/test/testcases/block/06_codeblock/error.html +4 -0
  134. data/test/testcases/block/06_codeblock/error.text +4 -0
  135. data/test/testcases/block/06_codeblock/guess_lang_css_class.html +15 -0
  136. data/test/testcases/block/06_codeblock/guess_lang_css_class.options +2 -0
  137. data/test/testcases/block/06_codeblock/guess_lang_css_class.text +13 -0
  138. data/test/testcases/block/06_codeblock/highlighting-minted-with-opts.latex +9 -0
  139. data/test/testcases/block/06_codeblock/highlighting-minted-with-opts.options +4 -0
  140. data/test/testcases/block/06_codeblock/highlighting-minted-with-opts.text +5 -0
  141. data/test/testcases/block/06_codeblock/highlighting-minted.latex +8 -0
  142. data/test/testcases/block/06_codeblock/highlighting-minted.options +3 -0
  143. data/test/testcases/block/06_codeblock/highlighting-minted.text +4 -0
  144. data/test/testcases/block/06_codeblock/highlighting-opts.html +6 -0
  145. data/test/testcases/block/06_codeblock/highlighting-opts.options +7 -0
  146. data/test/testcases/block/06_codeblock/highlighting-opts.text +4 -0
  147. data/test/testcases/block/06_codeblock/highlighting.html +5 -0
  148. data/test/testcases/block/06_codeblock/highlighting.options +5 -0
  149. data/test/testcases/block/06_codeblock/highlighting.text +4 -0
  150. data/test/testcases/block/06_codeblock/issue_gh45.html +164 -0
  151. data/test/testcases/block/06_codeblock/issue_gh45.test +188 -0
  152. data/test/testcases/block/06_codeblock/lazy.html +4 -0
  153. data/test/testcases/block/06_codeblock/lazy.text +5 -0
  154. data/test/testcases/block/06_codeblock/no_newline_at_end.html +2 -0
  155. data/test/testcases/block/06_codeblock/no_newline_at_end.text +1 -0
  156. data/test/testcases/block/06_codeblock/no_newline_at_end_1.html +2 -0
  157. data/test/testcases/block/06_codeblock/no_newline_at_end_1.text +2 -0
  158. data/test/testcases/block/06_codeblock/normal.html +13 -0
  159. data/test/testcases/block/06_codeblock/normal.text +10 -0
  160. data/test/testcases/block/06_codeblock/rouge/disabled.html +2 -0
  161. data/test/testcases/block/06_codeblock/rouge/disabled.options +4 -0
  162. data/test/testcases/block/06_codeblock/rouge/disabled.text +1 -0
  163. data/test/testcases/block/06_codeblock/rouge/multiple.html +11 -0
  164. data/test/testcases/block/06_codeblock/rouge/multiple.options +4 -0
  165. data/test/testcases/block/06_codeblock/rouge/multiple.text +11 -0
  166. data/test/testcases/block/06_codeblock/rouge/simple.html +10 -0
  167. data/test/testcases/block/06_codeblock/rouge/simple.options +3 -0
  168. data/test/testcases/block/06_codeblock/rouge/simple.text +9 -0
  169. data/test/testcases/block/06_codeblock/tilde_syntax.html +7 -0
  170. data/test/testcases/block/06_codeblock/tilde_syntax.text +9 -0
  171. data/test/testcases/block/06_codeblock/whitespace.html +3 -0
  172. data/test/testcases/block/06_codeblock/whitespace.text +3 -0
  173. data/test/testcases/block/06_codeblock/with_blank_line.html +13 -0
  174. data/test/testcases/block/06_codeblock/with_blank_line.text +12 -0
  175. data/test/testcases/block/06_codeblock/with_eob_marker.html +6 -0
  176. data/test/testcases/block/06_codeblock/with_eob_marker.text +5 -0
  177. data/test/testcases/block/06_codeblock/with_ial.html +6 -0
  178. data/test/testcases/block/06_codeblock/with_ial.text +5 -0
  179. data/test/testcases/block/06_codeblock/with_lang_in_fenced_block.html +24 -0
  180. data/test/testcases/block/06_codeblock/with_lang_in_fenced_block.options +2 -0
  181. data/test/testcases/block/06_codeblock/with_lang_in_fenced_block.text +33 -0
  182. data/test/testcases/block/06_codeblock/with_lang_in_fenced_block_any_char.html +8 -0
  183. data/test/testcases/block/06_codeblock/with_lang_in_fenced_block_any_char.options +2 -0
  184. data/test/testcases/block/06_codeblock/with_lang_in_fenced_block_any_char.text +11 -0
  185. data/test/testcases/block/06_codeblock/with_lang_in_fenced_block_name_with_dash.html +3 -0
  186. data/test/testcases/block/06_codeblock/with_lang_in_fenced_block_name_with_dash.options +2 -0
  187. data/test/testcases/block/06_codeblock/with_lang_in_fenced_block_name_with_dash.text +4 -0
  188. data/test/testcases/block/07_horizontal_rule/error.html +7 -0
  189. data/test/testcases/block/07_horizontal_rule/error.text +7 -0
  190. data/test/testcases/block/07_horizontal_rule/normal.html +19 -0
  191. data/test/testcases/block/07_horizontal_rule/normal.text +20 -0
  192. data/test/testcases/block/07_horizontal_rule/sepspaces.html +3 -0
  193. data/test/testcases/block/07_horizontal_rule/sepspaces.text +3 -0
  194. data/test/testcases/block/07_horizontal_rule/septabs.html +3 -0
  195. data/test/testcases/block/07_horizontal_rule/septabs.text +3 -0
  196. data/test/testcases/block/08_list/brackets_in_item.latex +3 -0
  197. data/test/testcases/block/08_list/brackets_in_item.text +1 -0
  198. data/test/testcases/block/08_list/escaping.html +17 -0
  199. data/test/testcases/block/08_list/escaping.text +17 -0
  200. data/test/testcases/block/08_list/item_ial.html +10 -0
  201. data/test/testcases/block/08_list/item_ial.text +8 -0
  202. data/test/testcases/block/08_list/lazy.html +39 -0
  203. data/test/testcases/block/08_list/lazy.text +29 -0
  204. data/test/testcases/block/08_list/lazy_and_nested.html +9 -0
  205. data/test/testcases/block/08_list/lazy_and_nested.text +4 -0
  206. data/test/testcases/block/08_list/list_and_hr.html +9 -0
  207. data/test/testcases/block/08_list/list_and_hr.text +5 -0
  208. data/test/testcases/block/08_list/list_and_others.html +40 -0
  209. data/test/testcases/block/08_list/list_and_others.text +26 -0
  210. data/test/testcases/block/08_list/mixed.html +117 -0
  211. data/test/testcases/block/08_list/mixed.text +66 -0
  212. data/test/testcases/block/08_list/nested.html +17 -0
  213. data/test/testcases/block/08_list/nested.text +7 -0
  214. data/test/testcases/block/08_list/other_first_element.html +39 -0
  215. data/test/testcases/block/08_list/other_first_element.text +18 -0
  216. data/test/testcases/block/08_list/simple_ol.html +19 -0
  217. data/test/testcases/block/08_list/simple_ol.text +13 -0
  218. data/test/testcases/block/08_list/simple_ul.html +48 -0
  219. data/test/testcases/block/08_list/simple_ul.text +36 -0
  220. data/test/testcases/block/08_list/single_item.html +3 -0
  221. data/test/testcases/block/08_list/single_item.text +1 -0
  222. data/test/testcases/block/08_list/special_cases.html +62 -0
  223. data/test/testcases/block/08_list/special_cases.text +40 -0
  224. data/test/testcases/block/09_html/comment.html +18 -0
  225. data/test/testcases/block/09_html/comment.text +15 -0
  226. data/test/testcases/block/09_html/content_model/deflists.html +6 -0
  227. data/test/testcases/block/09_html/content_model/deflists.options +1 -0
  228. data/test/testcases/block/09_html/content_model/deflists.text +6 -0
  229. data/test/testcases/block/09_html/content_model/tables.html +14 -0
  230. data/test/testcases/block/09_html/content_model/tables.options +1 -0
  231. data/test/testcases/block/09_html/content_model/tables.text +14 -0
  232. data/test/testcases/block/09_html/html5_attributes.html +15 -0
  233. data/test/testcases/block/09_html/html5_attributes.text +15 -0
  234. data/test/testcases/block/09_html/html_after_block.html +7 -0
  235. data/test/testcases/block/09_html/html_after_block.text +5 -0
  236. data/test/testcases/block/09_html/html_and_codeblocks.html +15 -0
  237. data/test/testcases/block/09_html/html_and_codeblocks.options +1 -0
  238. data/test/testcases/block/09_html/html_and_codeblocks.text +13 -0
  239. data/test/testcases/block/09_html/html_and_headers.html +5 -0
  240. data/test/testcases/block/09_html/html_and_headers.text +6 -0
  241. data/test/testcases/block/09_html/html_to_native/code.html +10 -0
  242. data/test/testcases/block/09_html/html_to_native/code.text +9 -0
  243. data/test/testcases/block/09_html/html_to_native/comment.html +7 -0
  244. data/test/testcases/block/09_html/html_to_native/comment.text +8 -0
  245. data/test/testcases/block/09_html/html_to_native/emphasis.html +6 -0
  246. data/test/testcases/block/09_html/html_to_native/emphasis.text +6 -0
  247. data/test/testcases/block/09_html/html_to_native/entity.html +1 -0
  248. data/test/testcases/block/09_html/html_to_native/entity.text +1 -0
  249. data/test/testcases/block/09_html/html_to_native/header.html +6 -0
  250. data/test/testcases/block/09_html/html_to_native/header.options +2 -0
  251. data/test/testcases/block/09_html/html_to_native/header.text +6 -0
  252. data/test/testcases/block/09_html/html_to_native/list_dl.html +8 -0
  253. data/test/testcases/block/09_html/html_to_native/list_dl.text +8 -0
  254. data/test/testcases/block/09_html/html_to_native/list_ol.html +15 -0
  255. data/test/testcases/block/09_html/html_to_native/list_ol.text +17 -0
  256. data/test/testcases/block/09_html/html_to_native/list_ul.html +19 -0
  257. data/test/testcases/block/09_html/html_to_native/list_ul.text +22 -0
  258. data/test/testcases/block/09_html/html_to_native/options +1 -0
  259. data/test/testcases/block/09_html/html_to_native/paragraph.html +3 -0
  260. data/test/testcases/block/09_html/html_to_native/paragraph.text +4 -0
  261. data/test/testcases/block/09_html/html_to_native/table_normal.html +12 -0
  262. data/test/testcases/block/09_html/html_to_native/table_normal.text +12 -0
  263. data/test/testcases/block/09_html/html_to_native/table_simple.html +61 -0
  264. data/test/testcases/block/09_html/html_to_native/table_simple.text +71 -0
  265. data/test/testcases/block/09_html/html_to_native/typography.html +1 -0
  266. data/test/testcases/block/09_html/html_to_native/typography.text +1 -0
  267. data/test/testcases/block/09_html/invalid_html_1.html +5 -0
  268. data/test/testcases/block/09_html/invalid_html_1.text +5 -0
  269. data/test/testcases/block/09_html/invalid_html_2.html +5 -0
  270. data/test/testcases/block/09_html/invalid_html_2.text +5 -0
  271. data/test/testcases/block/09_html/markdown_attr.html +38 -0
  272. data/test/testcases/block/09_html/markdown_attr.text +38 -0
  273. data/test/testcases/block/09_html/not_parsed.html +24 -0
  274. data/test/testcases/block/09_html/not_parsed.text +24 -0
  275. data/test/testcases/block/09_html/parse_as_raw.html +35 -0
  276. data/test/testcases/block/09_html/parse_as_raw.htmlinput +34 -0
  277. data/test/testcases/block/09_html/parse_as_raw.options +1 -0
  278. data/test/testcases/block/09_html/parse_as_raw.text +33 -0
  279. data/test/testcases/block/09_html/parse_as_span.html +12 -0
  280. data/test/testcases/block/09_html/parse_as_span.htmlinput +12 -0
  281. data/test/testcases/block/09_html/parse_as_span.options +1 -0
  282. data/test/testcases/block/09_html/parse_as_span.text +9 -0
  283. data/test/testcases/block/09_html/parse_block_html.html +21 -0
  284. data/test/testcases/block/09_html/parse_block_html.options +1 -0
  285. data/test/testcases/block/09_html/parse_block_html.text +17 -0
  286. data/test/testcases/block/09_html/processing_instruction.html +12 -0
  287. data/test/testcases/block/09_html/processing_instruction.text +12 -0
  288. data/test/testcases/block/09_html/simple.html +60 -0
  289. data/test/testcases/block/09_html/simple.options +1 -0
  290. data/test/testcases/block/09_html/simple.text +55 -0
  291. data/test/testcases/block/09_html/standalone_image_in_div.htmlinput +7 -0
  292. data/test/testcases/block/09_html/standalone_image_in_div.text +8 -0
  293. data/test/testcases/block/09_html/textarea.html +8 -0
  294. data/test/testcases/block/09_html/textarea.text +8 -0
  295. data/test/testcases/block/09_html/xml.html +8 -0
  296. data/test/testcases/block/09_html/xml.text +7 -0
  297. data/test/testcases/block/10_ald/simple.html +2 -0
  298. data/test/testcases/block/10_ald/simple.text +8 -0
  299. data/test/testcases/block/11_ial/auto_id_and_ial.html +1 -0
  300. data/test/testcases/block/11_ial/auto_id_and_ial.options +1 -0
  301. data/test/testcases/block/11_ial/auto_id_and_ial.text +2 -0
  302. data/test/testcases/block/11_ial/nested.html +11 -0
  303. data/test/testcases/block/11_ial/nested.text +15 -0
  304. data/test/testcases/block/11_ial/simple.html +29 -0
  305. data/test/testcases/block/11_ial/simple.text +41 -0
  306. data/test/testcases/block/12_extension/comment.html +8 -0
  307. data/test/testcases/block/12_extension/comment.text +12 -0
  308. data/test/testcases/block/12_extension/ignored.html +8 -0
  309. data/test/testcases/block/12_extension/ignored.text +8 -0
  310. data/test/testcases/block/12_extension/nomarkdown.html +10 -0
  311. data/test/testcases/block/12_extension/nomarkdown.kramdown +20 -0
  312. data/test/testcases/block/12_extension/nomarkdown.latex +13 -0
  313. data/test/testcases/block/12_extension/nomarkdown.text +21 -0
  314. data/test/testcases/block/12_extension/options.html +21 -0
  315. data/test/testcases/block/12_extension/options.text +23 -0
  316. data/test/testcases/block/12_extension/options2.html +10 -0
  317. data/test/testcases/block/12_extension/options2.text +5 -0
  318. data/test/testcases/block/12_extension/options3.html +8 -0
  319. data/test/testcases/block/12_extension/options3.text +7 -0
  320. data/test/testcases/block/13_definition_list/auto_ids.html +15 -0
  321. data/test/testcases/block/13_definition_list/auto_ids.text +18 -0
  322. data/test/testcases/block/13_definition_list/definition_at_beginning.html +1 -0
  323. data/test/testcases/block/13_definition_list/definition_at_beginning.text +1 -0
  324. data/test/testcases/block/13_definition_list/deflist_ial.html +4 -0
  325. data/test/testcases/block/13_definition_list/deflist_ial.text +4 -0
  326. data/test/testcases/block/13_definition_list/item_ial.html +17 -0
  327. data/test/testcases/block/13_definition_list/item_ial.text +16 -0
  328. data/test/testcases/block/13_definition_list/multiple_terms.html +13 -0
  329. data/test/testcases/block/13_definition_list/multiple_terms.text +10 -0
  330. data/test/testcases/block/13_definition_list/no_def_list.html +2 -0
  331. data/test/testcases/block/13_definition_list/no_def_list.text +2 -0
  332. data/test/testcases/block/13_definition_list/para_wrapping.html +10 -0
  333. data/test/testcases/block/13_definition_list/para_wrapping.text +6 -0
  334. data/test/testcases/block/13_definition_list/separated_by_eob.html +8 -0
  335. data/test/testcases/block/13_definition_list/separated_by_eob.text +5 -0
  336. data/test/testcases/block/13_definition_list/simple.html +10 -0
  337. data/test/testcases/block/13_definition_list/simple.text +10 -0
  338. data/test/testcases/block/13_definition_list/styled_terms.html +4 -0
  339. data/test/testcases/block/13_definition_list/styled_terms.text +2 -0
  340. data/test/testcases/block/13_definition_list/too_much_space.html +3 -0
  341. data/test/testcases/block/13_definition_list/too_much_space.text +4 -0
  342. data/test/testcases/block/13_definition_list/with_blocks.html +38 -0
  343. data/test/testcases/block/13_definition_list/with_blocks.text +24 -0
  344. data/test/testcases/block/14_table/empty_tag_in_cell.html +8 -0
  345. data/test/testcases/block/14_table/empty_tag_in_cell.options +1 -0
  346. data/test/testcases/block/14_table/empty_tag_in_cell.text +1 -0
  347. data/test/testcases/block/14_table/errors.html +12 -0
  348. data/test/testcases/block/14_table/errors.text +13 -0
  349. data/test/testcases/block/14_table/escaping.html +52 -0
  350. data/test/testcases/block/14_table/escaping.text +19 -0
  351. data/test/testcases/block/14_table/footer.html +65 -0
  352. data/test/testcases/block/14_table/footer.text +25 -0
  353. data/test/testcases/block/14_table/header.html +117 -0
  354. data/test/testcases/block/14_table/header.text +39 -0
  355. data/test/testcases/block/14_table/no_table.html +3 -0
  356. data/test/testcases/block/14_table/no_table.text +3 -0
  357. data/test/testcases/block/14_table/simple.html +192 -0
  358. data/test/testcases/block/14_table/simple.text +53 -0
  359. data/test/testcases/block/14_table/table_with_footnote.html +25 -0
  360. data/test/testcases/block/14_table/table_with_footnote.latex +11 -0
  361. data/test/testcases/block/14_table/table_with_footnote.text +6 -0
  362. data/test/testcases/block/15_math/gh_128.html +1 -0
  363. data/test/testcases/block/15_math/gh_128.text +1 -0
  364. data/test/testcases/block/15_math/no_engine.html +3 -0
  365. data/test/testcases/block/15_math/no_engine.options +1 -0
  366. data/test/testcases/block/15_math/no_engine.text +2 -0
  367. data/test/testcases/block/15_math/normal.html +30 -0
  368. data/test/testcases/block/15_math/normal.text +30 -0
  369. data/test/testcases/block/16_toc/no_toc.html +14 -0
  370. data/test/testcases/block/16_toc/no_toc.text +16 -0
  371. data/test/testcases/block/16_toc/toc_exclude.html +35 -0
  372. data/test/testcases/block/16_toc/toc_exclude.options +1 -0
  373. data/test/testcases/block/16_toc/toc_exclude.text +19 -0
  374. data/test/testcases/block/16_toc/toc_levels.html +24 -0
  375. data/test/testcases/block/16_toc/toc_levels.options +2 -0
  376. data/test/testcases/block/16_toc/toc_levels.text +16 -0
  377. data/test/testcases/block/16_toc/toc_with_footnotes.html +13 -0
  378. data/test/testcases/block/16_toc/toc_with_footnotes.options +1 -0
  379. data/test/testcases/block/16_toc/toc_with_footnotes.text +6 -0
  380. data/test/testcases/block/16_toc/toc_with_links.html +8 -0
  381. data/test/testcases/block/16_toc/toc_with_links.options +2 -0
  382. data/test/testcases/block/16_toc/toc_with_links.text +8 -0
  383. data/test/testcases/cjk-line-break.html +4 -0
  384. data/test/testcases/cjk-line-break.options +1 -0
  385. data/test/testcases/cjk-line-break.text +12 -0
  386. data/test/testcases/encoding.html +46 -0
  387. data/test/testcases/encoding.text +28 -0
  388. data/test/testcases/man/example.man +123 -0
  389. data/test/testcases/man/example.text +85 -0
  390. data/test/testcases/man/heading-name-dash-description.man +4 -0
  391. data/test/testcases/man/heading-name-dash-description.text +1 -0
  392. data/test/testcases/man/heading-name-description.man +4 -0
  393. data/test/testcases/man/heading-name-description.text +2 -0
  394. data/test/testcases/man/heading-name-section-description.man +4 -0
  395. data/test/testcases/man/heading-name-section-description.text +1 -0
  396. data/test/testcases/man/heading-name-section.man +2 -0
  397. data/test/testcases/man/heading-name-section.text +1 -0
  398. data/test/testcases/man/heading-name.man +2 -0
  399. data/test/testcases/man/heading-name.text +1 -0
  400. data/test/testcases/man/sections.man +4 -0
  401. data/test/testcases/man/sections.text +11 -0
  402. data/test/testcases/man/text-escaping.man +8 -0
  403. data/test/testcases/man/text-escaping.text +7 -0
  404. data/test/testcases/span/01_link/empty.html +5 -0
  405. data/test/testcases/span/01_link/empty.text +5 -0
  406. data/test/testcases/span/01_link/empty_title.htmlinput +3 -0
  407. data/test/testcases/span/01_link/empty_title.text +7 -0
  408. data/test/testcases/span/01_link/image_in_a.html +5 -0
  409. data/test/testcases/span/01_link/image_in_a.text +5 -0
  410. data/test/testcases/span/01_link/imagelinks.html +15 -0
  411. data/test/testcases/span/01_link/imagelinks.text +18 -0
  412. data/test/testcases/span/01_link/inline.html +46 -0
  413. data/test/testcases/span/01_link/inline.text +48 -0
  414. data/test/testcases/span/01_link/latex_escaping.latex +6 -0
  415. data/test/testcases/span/01_link/latex_escaping.text +5 -0
  416. data/test/testcases/span/01_link/link_defs.html +9 -0
  417. data/test/testcases/span/01_link/link_defs.text +27 -0
  418. data/test/testcases/span/01_link/link_defs_with_ial.html +4 -0
  419. data/test/testcases/span/01_link/link_defs_with_ial.text +16 -0
  420. data/test/testcases/span/01_link/links_with_angle_brackets.html +3 -0
  421. data/test/testcases/span/01_link/links_with_angle_brackets.text +3 -0
  422. data/test/testcases/span/01_link/reference.html +37 -0
  423. data/test/testcases/span/01_link/reference.options +3 -0
  424. data/test/testcases/span/01_link/reference.text +53 -0
  425. data/test/testcases/span/02_emphasis/empty.html +3 -0
  426. data/test/testcases/span/02_emphasis/empty.text +3 -0
  427. data/test/testcases/span/02_emphasis/errors.html +9 -0
  428. data/test/testcases/span/02_emphasis/errors.text +9 -0
  429. data/test/testcases/span/02_emphasis/nesting.html +41 -0
  430. data/test/testcases/span/02_emphasis/nesting.text +36 -0
  431. data/test/testcases/span/02_emphasis/normal.html +65 -0
  432. data/test/testcases/span/02_emphasis/normal.options +1 -0
  433. data/test/testcases/span/02_emphasis/normal.text +63 -0
  434. data/test/testcases/span/03_codespan/empty.html +5 -0
  435. data/test/testcases/span/03_codespan/empty.text +5 -0
  436. data/test/testcases/span/03_codespan/errors.html +1 -0
  437. data/test/testcases/span/03_codespan/errors.text +1 -0
  438. data/test/testcases/span/03_codespan/highlighting-minted.latex +2 -0
  439. data/test/testcases/span/03_codespan/highlighting-minted.options +1 -0
  440. data/test/testcases/span/03_codespan/highlighting-minted.text +1 -0
  441. data/test/testcases/span/03_codespan/highlighting.html +1 -0
  442. data/test/testcases/span/03_codespan/highlighting.text +1 -0
  443. data/test/testcases/span/03_codespan/normal-css-class.html +1 -0
  444. data/test/testcases/span/03_codespan/normal-css-class.options +2 -0
  445. data/test/testcases/span/03_codespan/normal-css-class.text +1 -0
  446. data/test/testcases/span/03_codespan/normal.html +16 -0
  447. data/test/testcases/span/03_codespan/normal.text +16 -0
  448. data/test/testcases/span/03_codespan/rouge/disabled.html +1 -0
  449. data/test/testcases/span/03_codespan/rouge/disabled.options +4 -0
  450. data/test/testcases/span/03_codespan/rouge/disabled.text +1 -0
  451. data/test/testcases/span/03_codespan/rouge/simple.html +1 -0
  452. data/test/testcases/span/03_codespan/rouge/simple.options +1 -0
  453. data/test/testcases/span/03_codespan/rouge/simple.text +1 -0
  454. data/test/testcases/span/04_footnote/backlink_inline.html +79 -0
  455. data/test/testcases/span/04_footnote/backlink_inline.options +1 -0
  456. data/test/testcases/span/04_footnote/backlink_inline.text +38 -0
  457. data/test/testcases/span/04_footnote/backlink_text.html +9 -0
  458. data/test/testcases/span/04_footnote/backlink_text.options +1 -0
  459. data/test/testcases/span/04_footnote/backlink_text.text +3 -0
  460. data/test/testcases/span/04_footnote/definitions.html +17 -0
  461. data/test/testcases/span/04_footnote/definitions.latex +17 -0
  462. data/test/testcases/span/04_footnote/definitions.text +24 -0
  463. data/test/testcases/span/04_footnote/footnote_nr.html +12 -0
  464. data/test/testcases/span/04_footnote/footnote_nr.latex +2 -0
  465. data/test/testcases/span/04_footnote/footnote_nr.options +1 -0
  466. data/test/testcases/span/04_footnote/footnote_nr.text +4 -0
  467. data/test/testcases/span/04_footnote/footnote_prefix.html +12 -0
  468. data/test/testcases/span/04_footnote/footnote_prefix.options +1 -0
  469. data/test/testcases/span/04_footnote/footnote_prefix.text +4 -0
  470. data/test/testcases/span/04_footnote/inside_footnote.html +17 -0
  471. data/test/testcases/span/04_footnote/inside_footnote.text +9 -0
  472. data/test/testcases/span/04_footnote/markers.html +46 -0
  473. data/test/testcases/span/04_footnote/markers.latex +23 -0
  474. data/test/testcases/span/04_footnote/markers.options +2 -0
  475. data/test/testcases/span/04_footnote/markers.text +27 -0
  476. data/test/testcases/span/04_footnote/placement.html +11 -0
  477. data/test/testcases/span/04_footnote/placement.options +1 -0
  478. data/test/testcases/span/04_footnote/placement.text +8 -0
  479. data/test/testcases/span/04_footnote/regexp_problem.html +14 -0
  480. data/test/testcases/span/04_footnote/regexp_problem.options +2 -0
  481. data/test/testcases/span/04_footnote/regexp_problem.text +52 -0
  482. data/test/testcases/span/04_footnote/without_backlink.html +9 -0
  483. data/test/testcases/span/04_footnote/without_backlink.options +1 -0
  484. data/test/testcases/span/04_footnote/without_backlink.text +3 -0
  485. data/test/testcases/span/05_html/across_lines.html +1 -0
  486. data/test/testcases/span/05_html/across_lines.text +2 -0
  487. data/test/testcases/span/05_html/button.html +7 -0
  488. data/test/testcases/span/05_html/button.text +7 -0
  489. data/test/testcases/span/05_html/invalid.html +1 -0
  490. data/test/testcases/span/05_html/invalid.text +1 -0
  491. data/test/testcases/span/05_html/link_with_mailto.html +1 -0
  492. data/test/testcases/span/05_html/link_with_mailto.text +1 -0
  493. data/test/testcases/span/05_html/mark_element.html +3 -0
  494. data/test/testcases/span/05_html/mark_element.text +3 -0
  495. data/test/testcases/span/05_html/markdown_attr.html +6 -0
  496. data/test/testcases/span/05_html/markdown_attr.text +6 -0
  497. data/test/testcases/span/05_html/normal.html +43 -0
  498. data/test/testcases/span/05_html/normal.text +43 -0
  499. data/test/testcases/span/05_html/raw_span_elements.html +2 -0
  500. data/test/testcases/span/05_html/raw_span_elements.text +2 -0
  501. data/test/testcases/span/05_html/xml.html +5 -0
  502. data/test/testcases/span/05_html/xml.text +5 -0
  503. data/test/testcases/span/abbreviations/abbrev.html +21 -0
  504. data/test/testcases/span/abbreviations/abbrev.text +34 -0
  505. data/test/testcases/span/abbreviations/abbrev_defs.html +2 -0
  506. data/test/testcases/span/abbreviations/abbrev_defs.text +5 -0
  507. data/test/testcases/span/abbreviations/in_footnote.html +9 -0
  508. data/test/testcases/span/abbreviations/in_footnote.text +5 -0
  509. data/test/testcases/span/autolinks/url_links.html +15 -0
  510. data/test/testcases/span/autolinks/url_links.text +16 -0
  511. data/test/testcases/span/escaped_chars/normal.html +47 -0
  512. data/test/testcases/span/escaped_chars/normal.text +47 -0
  513. data/test/testcases/span/extension/comment.html +6 -0
  514. data/test/testcases/span/extension/comment.text +6 -0
  515. data/test/testcases/span/extension/ignored.html +1 -0
  516. data/test/testcases/span/extension/ignored.text +1 -0
  517. data/test/testcases/span/extension/nomarkdown.html +1 -0
  518. data/test/testcases/span/extension/nomarkdown.text +1 -0
  519. data/test/testcases/span/extension/options.html +1 -0
  520. data/test/testcases/span/extension/options.text +1 -0
  521. data/test/testcases/span/ial/simple.html +6 -0
  522. data/test/testcases/span/ial/simple.text +6 -0
  523. data/test/testcases/span/line_breaks/normal.html +11 -0
  524. data/test/testcases/span/line_breaks/normal.latex +12 -0
  525. data/test/testcases/span/line_breaks/normal.text +11 -0
  526. data/test/testcases/span/math/no_engine.html +1 -0
  527. data/test/testcases/span/math/no_engine.options +1 -0
  528. data/test/testcases/span/math/no_engine.text +1 -0
  529. data/test/testcases/span/math/normal.html +10 -0
  530. data/test/testcases/span/math/normal.text +10 -0
  531. data/test/testcases/span/text_substitutions/entities.html +6 -0
  532. data/test/testcases/span/text_substitutions/entities.options +1 -0
  533. data/test/testcases/span/text_substitutions/entities.text +6 -0
  534. data/test/testcases/span/text_substitutions/entities_as_char.html +1 -0
  535. data/test/testcases/span/text_substitutions/entities_as_char.options +2 -0
  536. data/test/testcases/span/text_substitutions/entities_as_char.text +1 -0
  537. data/test/testcases/span/text_substitutions/entities_as_input.html +1 -0
  538. data/test/testcases/span/text_substitutions/entities_as_input.options +1 -0
  539. data/test/testcases/span/text_substitutions/entities_as_input.text +1 -0
  540. data/test/testcases/span/text_substitutions/entities_numeric.html +1 -0
  541. data/test/testcases/span/text_substitutions/entities_numeric.options +1 -0
  542. data/test/testcases/span/text_substitutions/entities_numeric.text +1 -0
  543. data/test/testcases/span/text_substitutions/entities_symbolic.html +1 -0
  544. data/test/testcases/span/text_substitutions/entities_symbolic.options +1 -0
  545. data/test/testcases/span/text_substitutions/entities_symbolic.text +1 -0
  546. data/test/testcases/span/text_substitutions/greaterthan.html +1 -0
  547. data/test/testcases/span/text_substitutions/greaterthan.text +1 -0
  548. data/test/testcases/span/text_substitutions/lowerthan.html +1 -0
  549. data/test/testcases/span/text_substitutions/lowerthan.text +1 -0
  550. data/test/testcases/span/text_substitutions/typography.html +40 -0
  551. data/test/testcases/span/text_substitutions/typography.options +1 -0
  552. data/test/testcases/span/text_substitutions/typography.text +40 -0
  553. data/test/testcases/span/text_substitutions/typography_subst.html +3 -0
  554. data/test/testcases/span/text_substitutions/typography_subst.latex +4 -0
  555. data/test/testcases/span/text_substitutions/typography_subst.options +8 -0
  556. data/test/testcases/span/text_substitutions/typography_subst.text +3 -0
  557. metadata +659 -0
@@ -0,0 +1,85 @@
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
+ module Kramdown::Converter::SyntaxHighlighter
11
+
12
+ # Uses Rouge which is CSS-compatible to Pygments to highlight code blocks and code spans.
13
+ module Rouge
14
+
15
+ begin
16
+ require 'rouge'
17
+
18
+ # Highlighting via Rouge is available if this constant is +true+.
19
+ AVAILABLE = true
20
+ rescue LoadError, SyntaxError
21
+ AVAILABLE = false # :nodoc:
22
+ end
23
+
24
+ def self.call(converter, text, lang, type, call_opts)
25
+ opts = options(converter, type)
26
+ call_opts[:default_lang] = opts[:default_lang]
27
+ return nil unless lang || opts[:default_lang] || opts[:guess_lang]
28
+
29
+ lexer = ::Rouge::Lexer.find_fancy(lang || opts[:default_lang], text)
30
+ return nil if opts[:disable] || !lexer || (lexer.tag == "plaintext" && !opts[:guess_lang])
31
+
32
+ opts[:css_class] ||= 'highlight' # For backward compatibility when using Rouge 2.0
33
+ formatter = formatter_class(opts).new(opts)
34
+ formatter.format(lexer.lex(text))
35
+ end
36
+
37
+ def self.options(converter, type)
38
+ prepare_options(converter)
39
+ converter.data[:syntax_highlighter_rouge][type]
40
+ end
41
+
42
+ def self.prepare_options(converter)
43
+ return if converter.data.key?(:syntax_highlighter_rouge)
44
+
45
+ cache = converter.data[:syntax_highlighter_rouge] = {}
46
+
47
+ opts = converter.options[:syntax_highlighter_opts].dup
48
+
49
+ span_opts = opts.delete(:span)&.dup || {}
50
+ block_opts = opts.delete(:block)&.dup || {}
51
+ normalize_keys(span_opts)
52
+ normalize_keys(block_opts)
53
+
54
+ cache[:span] = opts.merge(span_opts)
55
+ cache[:span][:wrap] = false
56
+
57
+ cache[:block] = opts.merge(block_opts)
58
+ end
59
+
60
+ def self.normalize_keys(hash)
61
+ return if hash.empty?
62
+
63
+ hash.keys.each do |k|
64
+ hash[k.kind_of?(String) ? Kramdown::Options.str_to_sym(k) : k] = hash.delete(k)
65
+ end
66
+ end
67
+
68
+ def self.formatter_class(opts = {})
69
+ case formatter = opts[:formatter]
70
+ when Class
71
+ formatter
72
+ when /\A[[:upper:]][[:alnum:]_]*\z/
73
+ ::Rouge::Formatters.const_get(formatter)
74
+ else
75
+ # Available in Rouge 2.0 or later
76
+ ::Rouge::Formatters::HTMLLegacy
77
+ end
78
+ rescue NameError
79
+ # Fallback to Rouge 1.x
80
+ ::Rouge::Formatters::HTML
81
+ end
82
+
83
+ end
84
+
85
+ end
@@ -0,0 +1,69 @@
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 'kramdown/converter'
11
+
12
+ module Kramdown
13
+
14
+ module Converter
15
+
16
+ # Converts a Kramdown::Document to an element tree that represents the table of contents.
17
+ #
18
+ # The returned tree consists of Element objects of type :toc where the root element is just used
19
+ # as container object. Each :toc element contains as value the wrapped :header element and under
20
+ # the attribute key :id the header ID that should be used (note that this ID may not exist in
21
+ # the wrapped element).
22
+ #
23
+ # Since the TOC tree consists of special :toc elements, one cannot directly feed this tree to
24
+ # other converters!
25
+ class Toc < Base
26
+
27
+ def initialize(root, options)
28
+ super
29
+ @toc = Element.new(:toc)
30
+ @stack = []
31
+ @options[:template] = ''
32
+ end
33
+
34
+ def convert(el)
35
+ if el.type == :header && in_toc?(el)
36
+ attr = el.attr.dup
37
+ attr['id'] = generate_id(el.options[:raw_text]) if @options[:auto_ids] && !attr['id']
38
+ add_to_toc(el, attr['id']) if attr['id']
39
+ else
40
+ el.children.each {|child| convert(child) }
41
+ end
42
+ @toc
43
+ end
44
+
45
+ private
46
+
47
+ def add_to_toc(el, id)
48
+ toc_element = Element.new(:toc, el, id: id)
49
+
50
+ success = false
51
+ until success
52
+ if @stack.empty?
53
+ @toc.children << toc_element
54
+ @stack << toc_element
55
+ success = true
56
+ elsif @stack.last.value.options[:level] < el.options[:level]
57
+ @stack.last.children << toc_element
58
+ @stack << toc_element
59
+ success = true
60
+ else
61
+ @stack.pop
62
+ end
63
+ end
64
+ end
65
+
66
+ end
67
+
68
+ end
69
+ end
@@ -0,0 +1,139 @@
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
+ # = kramdown
10
+ #
11
+ # kramdown is fast, pure Ruby Markdown superset converter, using a strict syntax definition and
12
+ # supporting several common extensions.
13
+ #
14
+ # The kramdown library is mainly written to support the kramdown-to-HTML conversion chain. However,
15
+ # due to its flexibility it supports other input and output formats as well. Here is a list of the
16
+ # supported formats:
17
+ #
18
+ # * input formats: kramdown (a Markdown superset), Markdown, GFM, HTML
19
+ # * output formats: HTML, kramdown, LaTeX (and therefore PDF), PDF via Prawn
20
+ #
21
+ # All the documentation on the available input and output formats is available at
22
+ # http://kramdown.gettalong.org.
23
+ #
24
+ # == Usage
25
+ #
26
+ # kramdown has a simple API, so using kramdown is as easy as
27
+ #
28
+ # require 'kramdown'
29
+ #
30
+ # Kramdown::Document.new(text).to_html
31
+ #
32
+ # For detailed information have a look at the *\Kramdown::Document* class.
33
+ #
34
+ # == License
35
+ #
36
+ # MIT - see the COPYING file.
37
+
38
+ require 'kramdown/version'
39
+ require 'kramdown/element'
40
+ require 'kramdown/error'
41
+ require 'kramdown/parser'
42
+ require 'kramdown/converter'
43
+ require 'kramdown/options'
44
+ require 'kramdown/utils'
45
+
46
+ module Kramdown
47
+
48
+ # Return the data directory for kramdown.
49
+ def self.data_dir
50
+ unless defined?(@data_dir)
51
+ require 'rbconfig'
52
+ @data_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'data', 'kramdown'))
53
+ @data_dir = File.expand_path(File.join(RbConfig::CONFIG["datadir"], "kramdown")) unless File.exist?(@data_dir)
54
+ raise "kramdown data directory not found! This is a bug, please report it!" unless File.directory?(@data_dir)
55
+ end
56
+ @data_dir
57
+ end
58
+
59
+ # The main interface to kramdown.
60
+ #
61
+ # This class provides a one-stop-shop for using kramdown to convert text into various output
62
+ # formats. Use it like this:
63
+ #
64
+ # require 'kramdown'
65
+ # doc = Kramdown::Document.new('This *is* some kramdown text')
66
+ # puts doc.to_html
67
+ #
68
+ # The #to_html method is a shortcut for using the Converter::Html class. See #method_missing for
69
+ # more information.
70
+ #
71
+ # The second argument to the ::new method is an options hash for customizing the behaviour of the
72
+ # used parser and the converter. See ::new for more information!
73
+ class Document
74
+
75
+ # The root Element of the element tree. It is immediately available after the ::new method has
76
+ # been called.
77
+ attr_accessor :root
78
+
79
+ # The options hash which holds the options for parsing/converting the Kramdown document.
80
+ attr_reader :options
81
+
82
+ # An array of warning messages. It is filled with warnings during the parsing phase (i.e. in
83
+ # ::new) and the conversion phase.
84
+ attr_reader :warnings
85
+
86
+ # Create a new Kramdown document from the string +source+ and use the provided +options+. The
87
+ # options that can be used are defined in the Options module.
88
+ #
89
+ # The special options key :input can be used to select the parser that should parse the
90
+ # +source+. It has to be the name of a class in the Kramdown::Parser module. For example, to
91
+ # select the kramdown parser, one would set the :input key to +Kramdown+. If this key is not
92
+ # set, it defaults to +Kramdown+.
93
+ #
94
+ # The +source+ is immediately parsed by the selected parser so that the root element is
95
+ # immediately available and the output can be generated.
96
+ def initialize(source, options = {})
97
+ @options = Options.merge(options).freeze
98
+ parser = (@options[:input] || 'kramdown').to_s
99
+ parser = parser[0..0].upcase + parser[1..-1]
100
+ try_require('parser', parser)
101
+ if Parser.const_defined?(parser)
102
+ @root, @warnings = Parser.const_get(parser).parse(source, @options)
103
+ else
104
+ raise Kramdown::Error, "kramdown has no parser to handle the specified " \
105
+ "input format: #{@options[:input]}"
106
+ end
107
+ end
108
+
109
+ # Check if a method is invoked that begins with +to_+ and if so, try to instantiate a converter
110
+ # class (i.e. a class in the Kramdown::Converter module) and use it for converting the document.
111
+ #
112
+ # For example, +to_html+ would instantiate the Kramdown::Converter::Html class.
113
+ def method_missing(id, *attr, &block)
114
+ if id.to_s =~ /^to_(\w+)$/ && (name = Utils.camelize($1)) &&
115
+ try_require('converter', name) && Converter.const_defined?(name)
116
+ output, warnings = Converter.const_get(name).convert(@root, @options)
117
+ @warnings.concat(warnings)
118
+ output
119
+ else
120
+ super
121
+ end
122
+ end
123
+
124
+ def inspect #:nodoc:
125
+ "<KD:Document: options=#{@options.inspect} root=#{@root.inspect} warnings=#{@warnings.inspect}>"
126
+ end
127
+
128
+ # Try requiring a parser or converter class and don't raise an error if the file is not found.
129
+ def try_require(type, name)
130
+ require("kramdown/#{type}/#{Utils.snake_case(name)}")
131
+ true
132
+ rescue LoadError
133
+ true
134
+ end
135
+ protected :try_require
136
+
137
+ end
138
+
139
+ end
@@ -0,0 +1,551 @@
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
+ module Kramdown
11
+
12
+ # Represents all elements in the element tree.
13
+ #
14
+ # kramdown only uses this one class for representing all available elements in an element tree
15
+ # (paragraphs, headers, emphasis, ...). The type of element can be set via the #type accessor.
16
+ #
17
+ # The root of a kramdown element tree has to be an element of type :root. It needs to have certain
18
+ # option keys set so that conversions work correctly. If only a part of a tree should be
19
+ # converted, duplicate the root node and assign the #children appropriately, e.g:
20
+ #
21
+ # root = doc.root
22
+ # new_root = root.dup
23
+ # new_root.children = [root.children[0]] # assign new array with elements to convert
24
+ #
25
+ # Following is a description of all supported element types.
26
+ #
27
+ # Note that the option :location may contain the start line number of an element in the source
28
+ # document.
29
+ #
30
+ # == Structural Elements
31
+ #
32
+ # === :root
33
+ #
34
+ # [Category] None
35
+ # [Usage context] As the root element of a document
36
+ # [Content model] Block-level elements
37
+ #
38
+ # Represents the root of a kramdown document.
39
+ #
40
+ # The root element contains the following option keys:
41
+ #
42
+ # :encoding:: When running on Ruby 1.9 this key has to be set to the encoding used for the text
43
+ # parts of the kramdown document.
44
+ #
45
+ # :abbrev_defs:: This key may be used to store the mapping of abbreviation to abbreviation
46
+ # definition.
47
+ #
48
+ # :abbrev_attr:: This key may be used to store the mapping of abbreviation to abbreviation
49
+ # attributes.
50
+ #
51
+ # :options:: This key may be used to store options that were set during parsing of the document.
52
+ #
53
+ # :footnote_count:: This key stores the number of actually referenced footnotes of the document.
54
+ #
55
+ # === :blank
56
+ #
57
+ # [Category] Block-level element
58
+ # [Usage context] Where block-level elements are expected
59
+ # [Content model] Empty
60
+ #
61
+ # Represents one or more blank lines. It is not allowed to have two or more consecutive blank
62
+ # elements.
63
+ #
64
+ # The +value+ field may contain the original content of the blank lines.
65
+ #
66
+ #
67
+ # === :p
68
+ #
69
+ # [Category] Block-level element
70
+ # [Usage context] Where block-level elements are expected
71
+ # [Content model] Span-level elements
72
+ #
73
+ # Represents a paragraph.
74
+ #
75
+ # If the option :transparent is +true+, this element just represents a block of text. I.e. this
76
+ # element just functions as a container for span-level elements.
77
+ #
78
+ #
79
+ # === :header
80
+ #
81
+ # [Category] Block-level element
82
+ # [Usage context] Where block-level elements are expected
83
+ # [Content model] Span-level elements
84
+ #
85
+ # Represents a header.
86
+ #
87
+ # The option :level specifies the header level and has to contain a number between 1 and \6. The
88
+ # option :raw_text has to contain the raw header text.
89
+ #
90
+ #
91
+ # === :blockquote
92
+ #
93
+ # [Category] Block-level element
94
+ # [Usage context] Where block-level elements are expected
95
+ # [Content model] Block-level elements
96
+ #
97
+ # Represents a blockquote.
98
+ #
99
+ #
100
+ # === :codeblock
101
+ #
102
+ # [Category] Block-level element
103
+ # [Usage context] Where block-level elements are expected
104
+ # [Content model] Empty
105
+ #
106
+ # Represents a code block, i.e. a block of text that should be used as-is.
107
+ #
108
+ # The +value+ field has to contain the content of the code block.
109
+ #
110
+ # The option :lang specifies a highlighting language with possible HTML style options (e.g.
111
+ # php?start_inline=1) and should be used instead of a possibly also available language embedded in
112
+ # a class name of the form 'language-LANG'.
113
+ #
114
+ #
115
+ # === :ul
116
+ #
117
+ # [Category] Block-level element
118
+ # [Usage context] Where block-level elements are expected
119
+ # [Content model] One or more :li elements
120
+ #
121
+ # Represents an unordered list.
122
+ #
123
+ #
124
+ # === :ol
125
+ #
126
+ # [Category] Block-level element
127
+ # [Usage context] Where block-level elements are expected
128
+ # [Content model] One or more :li elements
129
+ #
130
+ # Represents an ordered list.
131
+ #
132
+ #
133
+ # === :li
134
+ #
135
+ # [Category] Block-level element
136
+ # [Usage context] Inside :ol and :ul elements
137
+ # [Content model] Block-level elements
138
+ #
139
+ # Represents a list item of an ordered or unordered list.
140
+ #
141
+ # Note that the first child of a list item must not be a :blank element!
142
+ #
143
+ #
144
+ # === :dl
145
+ #
146
+ # [Category] Block-level element
147
+ # [Usage context] Where block-level elements are expected
148
+ # [Content model] One or more groups each consisting of one or more :dt elements followed by one
149
+ # or more :dd elements.
150
+ #
151
+ # Represents a definition list which contains groups consisting of terms and definitions for them.
152
+ #
153
+ #
154
+ # === :dt
155
+ #
156
+ # [Category] Block-level element
157
+ # [Usage context] Before :dt or :dd elements inside a :dl elment
158
+ # [Content model] Span-level elements
159
+ #
160
+ # Represents the term part of a term-definition group in a definition list.
161
+ #
162
+ #
163
+ # === :dd
164
+ #
165
+ # [Category] Block-level element
166
+ # [Usage context] After :dt or :dd elements inside a :dl elment
167
+ # [Content model] Block-level elements
168
+ #
169
+ # Represents the definition part of a term-definition group in a definition list.
170
+ #
171
+ #
172
+ # === :hr
173
+ #
174
+ # [Category] Block-level element
175
+ # [Usage context] Where block-level elements are expected
176
+ # [Content model] None
177
+ #
178
+ # Represents a horizontal line.
179
+ #
180
+ #
181
+ # === :table
182
+ #
183
+ # [Category] Block-level element
184
+ # [Usage context] Where block-level elements are expected
185
+ # [Content model] Zero or one :thead elements, one or more :tbody elements, zero or one :tfoot
186
+ # elements
187
+ #
188
+ # Represents a table. Each table row (i.e. :tr element) of the table has to contain the same
189
+ # number of :td elements.
190
+ #
191
+ # The option :alignment has to be an array containing the alignment values, exactly one for each
192
+ # column of the table. The possible alignment values are :left, :center, :right and :default.
193
+ #
194
+ #
195
+ # === :thead
196
+ #
197
+ # [Category] None
198
+ # [Usage context] As first element inside a :table element
199
+ # [Content model] One or more :tr elements
200
+ #
201
+ # Represents the table header.
202
+ #
203
+ #
204
+ # === :tbody
205
+ #
206
+ # [Category] None
207
+ # [Usage context] After a :thead element but before a :tfoot element inside a :table element
208
+ # [Content model] One or more :tr elements
209
+ #
210
+ # Represents a table body.
211
+ #
212
+ #
213
+ # === :tfoot
214
+ #
215
+ # [Category] None
216
+ # [Usage context] As last element inside a :table element
217
+ # [Content model] One or more :tr elements
218
+ #
219
+ # Represents the table footer.
220
+ #
221
+ #
222
+ # === :tr
223
+ #
224
+ # [Category] None
225
+ # [Usage context] Inside :thead, :tbody and :tfoot elements
226
+ # [Content model] One or more :td elements
227
+ #
228
+ # Represents a table row.
229
+ #
230
+ #
231
+ # === :td
232
+ #
233
+ # [Category] Block-level element
234
+ # [Usage context] Inside :tr elements
235
+ # [Content model] As child of :thead/:tr span-level elements, as child of :tbody/:tr and
236
+ # :tfoot/:tr block-level elements
237
+ #
238
+ # Represents a table cell.
239
+ #
240
+ #
241
+ # === :math
242
+ #
243
+ # [Category] Block/span-level element
244
+ # [Usage context] Where block/span-level elements are expected
245
+ # [Content model] None
246
+ #
247
+ # Represents mathematical text that is written in LaTeX.
248
+ #
249
+ # The +value+ field has to contain the actual mathematical text.
250
+ #
251
+ # The option :category has to be set to either :span or :block depending on the context where the
252
+ # element is used.
253
+ #
254
+ #
255
+ # == Text Markup Elements
256
+ #
257
+ # === :text
258
+ #
259
+ # [Category] Span-level element
260
+ # [Usage context] Where span-level elements are expected
261
+ # [Content model] None
262
+ #
263
+ # Represents text.
264
+ #
265
+ # The +value+ field has to contain the text itself.
266
+ #
267
+ #
268
+ # === :br
269
+ #
270
+ # [Category] Span-level element
271
+ # [Usage context] Where span-level elements are expected
272
+ # [Content model] None
273
+ #
274
+ # Represents a hard line break.
275
+ #
276
+ #
277
+ # === :a
278
+ #
279
+ # [Category] Span-level element
280
+ # [Usage context] Where span-level elements are expected
281
+ # [Content model] Span-level elements
282
+ #
283
+ # Represents a link to an URL.
284
+ #
285
+ # The attribute +href+ has to be set to the URL to which the link points. The attribute +title+
286
+ # optionally contains the title of the link.
287
+ #
288
+ #
289
+ # === :img
290
+ #
291
+ # [Category] Span-level element
292
+ # [Usage context] Where span-level elements are expected
293
+ # [Content model] None
294
+ #
295
+ # Represents an image.
296
+ #
297
+ # The attribute +src+ has to be set to the URL of the image. The attribute +alt+ has to contain a
298
+ # text description of the image. The attribute +title+ optionally contains the title of the image.
299
+ #
300
+ #
301
+ # === :codespan
302
+ #
303
+ # [Category] Span-level element
304
+ # [Usage context] Where span-level elements are expected
305
+ # [Content model] None
306
+ #
307
+ # Represents verbatim text.
308
+ #
309
+ # The +value+ field has to contain the content of the code span.
310
+ #
311
+ #
312
+ # === :footnote
313
+ #
314
+ # [Category] Span-level element
315
+ # [Usage context] Where span-level elements are expected
316
+ # [Content model] None
317
+ #
318
+ # Represents a footnote marker.
319
+ #
320
+ # The +value+ field has to contain an element whose children are the content of the footnote. The
321
+ # option :name has to contain a valid and unique footnote name. A valid footnote name consists of
322
+ # a word character or a digit and then optionally followed by other word characters, digits or
323
+ # dashes.
324
+ #
325
+ #
326
+ # === :em
327
+ #
328
+ # [Category] Span-level element
329
+ # [Usage context] Where span-level elements are expected
330
+ # [Content model] Span-level elements
331
+ #
332
+ # Represents emphasis of its contents.
333
+ #
334
+ #
335
+ # === :strong
336
+ #
337
+ # [Category] Span-level element
338
+ # [Usage context] Where span-level elements are expected
339
+ # [Content model] Span-level elements
340
+ #
341
+ # Represents strong importance for its contents.
342
+ #
343
+ #
344
+ # === :entity
345
+ #
346
+ # [Category] Span-level element
347
+ # [Usage context] Where span-level elements are expected
348
+ # [Content model] None
349
+ #
350
+ # Represents an HTML entity.
351
+ #
352
+ # The +value+ field has to contain an instance of Kramdown::Utils::Entities::Entity. The option
353
+ # :original can be used to store the original representation of the entity.
354
+ #
355
+ #
356
+ # === :typographic_sym
357
+ #
358
+ # [Category] Span-level element
359
+ # [Usage context] Where span-level elements are expected
360
+ # [Content model] None
361
+ #
362
+ # Represents a typographic symbol.
363
+ #
364
+ # The +value+ field needs to contain a Symbol representing the specific typographic symbol from
365
+ # the following list:
366
+ #
367
+ # :mdash:: An mdash character (---)
368
+ # :ndash:: An ndash character (--)
369
+ # :hellip:: An ellipsis (...)
370
+ # :laquo:: A left guillemet (<<)
371
+ # :raquo:: A right guillemet (>>)
372
+ # :laquo_space:: A left guillemet with a space (<< )
373
+ # :raquo_space:: A right guillemet with a space ( >>)
374
+ #
375
+ #
376
+ # === :smart_quote
377
+ #
378
+ # [Category] Span-level element
379
+ # [Usage context] Where span-level elements are expected
380
+ # [Content model] None
381
+ #
382
+ # Represents a quotation character.
383
+ #
384
+ # The +value+ field needs to contain a Symbol representing the specific quotation character:
385
+ #
386
+ # :lsquo:: Left single quote
387
+ # :rsquo:: Right single quote
388
+ # :ldquo:: Left double quote
389
+ # :rdquo:: Right double quote
390
+ #
391
+ #
392
+ # === :abbreviation
393
+ #
394
+ # [Category] Span-level element
395
+ # [Usage context] Where span-level elements are expected
396
+ # [Content model] None
397
+ #
398
+ # Represents a text part that is an abbreviation.
399
+ #
400
+ # The +value+ field has to contain the text part that is the abbreviation. The definition of the
401
+ # abbreviation is stored in the :root element of the document.
402
+ #
403
+ #
404
+ # == Other Elements
405
+ #
406
+ # === :html_element
407
+ #
408
+ # [Category] Block/span-level element
409
+ # [Usage context] Where block/span-level elements or raw HTML elements are expected
410
+ # [Content model] Depends on the element
411
+ #
412
+ # Represents an HTML element.
413
+ #
414
+ # The +value+ field has to contain the name of the HTML element the element is representing.
415
+ #
416
+ # The option :category has to be set to either :span or :block depending on the whether the
417
+ # element is a block-level or a span-level element. The option :content_model has to be set to the
418
+ # content model for the element (either :block if it contains block-level elements, :span if it
419
+ # contains span-level elements or :raw if it contains raw content).
420
+ #
421
+ #
422
+ # === :xml_comment
423
+ #
424
+ # [Category] Block/span-level element
425
+ # [Usage context] Where block/span-level elements are expected or in raw HTML elements
426
+ # [Content model] None
427
+ #
428
+ # Represents an XML/HTML comment.
429
+ #
430
+ # The +value+ field has to contain the whole XML/HTML comment including the delimiters.
431
+ #
432
+ # The option :category has to be set to either :span or :block depending on the context where the
433
+ # element is used.
434
+ #
435
+ #
436
+ # === :xml_pi
437
+ #
438
+ # [Category] Block/span-level element
439
+ # [Usage context] Where block/span-level elements are expected or in raw HTML elements
440
+ # [Content model] None
441
+ #
442
+ # Represents an XML/HTML processing instruction.
443
+ #
444
+ # The +value+ field has to contain the whole XML/HTML processing instruction including the
445
+ # delimiters.
446
+ #
447
+ # The option :category has to be set to either :span or :block depending on the context where the
448
+ # element is used.
449
+ #
450
+ #
451
+ # === :comment
452
+ #
453
+ # [Category] Block/span-level element
454
+ # [Usage context] Where block/span-level elements are expected
455
+ # [Content model] None
456
+ #
457
+ # Represents a comment.
458
+ #
459
+ # The +value+ field has to contain the comment.
460
+ #
461
+ # The option :category has to be set to either :span or :block depending on the context where the
462
+ # element is used. If it is set to :span, then no blank lines are allowed in the comment.
463
+ #
464
+ #
465
+ # === :raw
466
+ #
467
+ # [Category] Block/span-level element
468
+ # [Usage context] Where block/span-level elements are expected
469
+ # [Content model] None
470
+ #
471
+ # Represents a raw string that should not be modified. For example, the element could contain some
472
+ # HTML code that should be output as-is without modification and escaping.
473
+ #
474
+ # The +value+ field has to contain the actual raw text.
475
+ #
476
+ # The option :category has to be set to either :span or :block depending on the context where the
477
+ # element is used. If it is set to :span, then no blank lines are allowed in the raw text.
478
+ #
479
+ # The option :type can be set to an array of strings to define for which converters the raw string
480
+ # is valid.
481
+ #
482
+ class Element
483
+
484
+ # A symbol representing the element type. For example, :p or :blockquote.
485
+ attr_accessor :type
486
+
487
+ # The value of the element. The interpretation of this field depends on the type of the element.
488
+ # Many elements don't use this field.
489
+ attr_accessor :value
490
+
491
+ # The child elements of this element.
492
+ attr_accessor :children
493
+
494
+ # Create a new Element object of type +type+. The optional parameters +value+, +attr+ and
495
+ # +options+ can also be set in this constructor for convenience.
496
+ def initialize(type, value = nil, attr = nil, options = nil)
497
+ @type, @value, @attr, @options = type, value, attr, options
498
+ @children = []
499
+ end
500
+
501
+ # The attributes of the element.
502
+ def attr
503
+ @attr ||= {}
504
+ end
505
+
506
+ # The options hash for the element. It is used for storing arbitray options.
507
+ def options
508
+ @options ||= {}
509
+ end
510
+
511
+ def inspect #:nodoc:
512
+ "<kd:#{@type}" \
513
+ "#{value.nil? ? '' : ' value=' + value.inspect}" \
514
+ "#{attr.empty? ? '' : ' attr=' + attr.inspect}" \
515
+ "#{options.empty? ? '' : ' options=' + options.inspect}" \
516
+ "#{children.empty? ? '' : ' children=' + children.inspect}>"
517
+ end
518
+
519
+ CATEGORY = {} # :nodoc:
520
+ [:blank, :p, :header, :blockquote, :codeblock, :ul, :ol, :li, :dl, :dt, :dd,
521
+ :table, :td, :hr].each {|b| CATEGORY[b] = :block }
522
+ [:text, :a, :auto_a, :br, :img, :codespan, :footnote, :em, :strong, :entity, :typographic_sym,
523
+ :smart_quote, :abbreviation].each {|b| CATEGORY[b] = :span }
524
+
525
+ # Return the category of +el+ which can be :block, :span or +nil+.
526
+ #
527
+ # Most elements have a fixed category, however, some elements can either appear in a block-level
528
+ # or a span-level context. These elements need to have the option :category correctly set.
529
+ def self.category(el)
530
+ CATEGORY[el.type] || el.options[:category]
531
+ end
532
+
533
+ # syntactic sugar to simplify calls such as +Kramdown::Element.category(el) == :block+ with
534
+ # +el.block?+.
535
+ #
536
+ # Returns boolean true or false.
537
+ def block?
538
+ (CATEGORY[type] || options[:category]) == :block
539
+ end
540
+
541
+ # syntactic sugar to simplify calls such as +Kramdown::Element.category(el) == :span+ with
542
+ # +el.span?+.
543
+ #
544
+ # Returns boolean true or false.
545
+ def span?
546
+ (CATEGORY[type] || options[:category]) == :span
547
+ end
548
+
549
+ end
550
+
551
+ end