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
 
@@ -27,8 +14,19 @@ module Kramdown
27
14
  # kramdown only uses this one class for representing all available elements in an element tree
28
15
  # (paragraphs, headers, emphasis, ...). The type of element can be set via the #type accessor.
29
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
+ #
30
25
  # Following is a description of all supported element types.
31
26
  #
27
+ # Note that the option :location may contain the start line number of an element in the source
28
+ # document.
29
+ #
32
30
  # == Structural Elements
33
31
  #
34
32
  # === :root
@@ -47,8 +45,12 @@ module Kramdown
47
45
  # :abbrev_defs:: This key may be used to store the mapping of abbreviation to abbreviation
48
46
  # definition.
49
47
  #
48
+ # :abbrev_attr:: This key may be used to store the mapping of abbreviation to abbreviation
49
+ # attributes.
50
+ #
50
51
  # :options:: This key may be used to store options that were set during parsing of the document.
51
52
  #
53
+ # :footnote_count:: This key stores the number of actually referenced footnotes of the document.
52
54
  #
53
55
  # === :blank
54
56
  #
@@ -105,6 +107,10 @@ module Kramdown
105
107
  #
106
108
  # The +value+ field has to contain the content of the code block.
107
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
+ #
108
114
  #
109
115
  # === :ul
110
116
  #
@@ -126,7 +132,7 @@ module Kramdown
126
132
  #
127
133
  # === :li
128
134
  #
129
- # [Category] None
135
+ # [Category] Block-level element
130
136
  # [Usage context] Inside :ol and :ul elements
131
137
  # [Content model] Block-level elements
132
138
  #
@@ -147,7 +153,7 @@ module Kramdown
147
153
  #
148
154
  # === :dt
149
155
  #
150
- # [Category] None
156
+ # [Category] Block-level element
151
157
  # [Usage context] Before :dt or :dd elements inside a :dl elment
152
158
  # [Content model] Span-level elements
153
159
  #
@@ -156,7 +162,7 @@ module Kramdown
156
162
  #
157
163
  # === :dd
158
164
  #
159
- # [Category] None
165
+ # [Category] Block-level element
160
166
  # [Usage context] After :dt or :dd elements inside a :dl elment
161
167
  # [Content model] Block-level elements
162
168
  #
@@ -224,7 +230,7 @@ module Kramdown
224
230
  #
225
231
  # === :td
226
232
  #
227
- # [Category] None
233
+ # [Category] Block-level element
228
234
  # [Usage context] Inside :tr elements
229
235
  # [Content model] As child of :thead/:tr span-level elements, as child of :tbody/:tr and
230
236
  # :tfoot/:tr block-level elements
@@ -472,6 +478,7 @@ module Kramdown
472
478
  #
473
479
  # The option :type can be set to an array of strings to define for which converters the raw string
474
480
  # is valid.
481
+ #
475
482
  class Element
476
483
 
477
484
  # A symbol representing the element type. For example, :p or :blockquote.
@@ -484,17 +491,16 @@ module Kramdown
484
491
  # The child elements of this element.
485
492
  attr_accessor :children
486
493
 
487
-
488
494
  # Create a new Element object of type +type+. The optional parameters +value+, +attr+ and
489
495
  # +options+ can also be set in this constructor for convenience.
490
496
  def initialize(type, value = nil, attr = nil, options = nil)
491
- @type, @value, @attr, @options = type, value, (Utils::OrderedHash.new.merge!(attr) if attr), options
497
+ @type, @value, @attr, @options = type, value, attr, options
492
498
  @children = []
493
499
  end
494
500
 
495
- # The attributes of the element. Uses an Utils::OrderedHash to retain the insertion order.
501
+ # The attributes of the element.
496
502
  def attr
497
- @attr ||= Utils::OrderedHash.new
503
+ @attr ||= {}
498
504
  end
499
505
 
500
506
  # The options hash for the element. It is used for storing arbitray options.
@@ -503,13 +509,18 @@ module Kramdown
503
509
  end
504
510
 
505
511
  def inspect #:nodoc:
506
- "<kd:#{@type}#{@value.nil? ? '' : ' ' + @value.inspect} #{@attr.inspect}#{options.empty? ? '' : ' ' + @options.inspect}#{@children.empty? ? '' : ' ' + @children.inspect}>"
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}>"
507
517
  end
508
518
 
509
519
  CATEGORY = {} # :nodoc:
510
- [:blank, :p, :header, :blockquote, :codeblock, :ul, :ol, :dl, :table, :hr].each {|b| CATEGORY[b] = :block}
520
+ [:blank, :p, :header, :blockquote, :codeblock, :ul, :ol, :li, :dl, :dt, :dd,
521
+ :table, :td, :hr].each {|b| CATEGORY[b] = :block }
511
522
  [:text, :a, :br, :img, :codespan, :footnote, :em, :strong, :entity, :typographic_sym,
512
- :smart_quote, :abbreviation].each {|b| CATEGORY[b] = :span}
523
+ :smart_quote, :abbreviation].each {|b| CATEGORY[b] = :span }
513
524
 
514
525
  # Return the category of +el+ which can be :block, :span or +nil+.
515
526
  #
@@ -519,6 +530,22 @@ module Kramdown
519
530
  CATEGORY[el.type] || el.options[:category]
520
531
  end
521
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
+
522
549
  end
523
550
 
524
551
  end
@@ -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
 
@@ -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
 
@@ -61,8 +48,9 @@ module Kramdown
61
48
  # suffices. A block needs to be specified when using type 'Object' and it has to cope with
62
49
  # a value given as string and as the opaque type.
63
50
  def self.define(name, type, default, desc, &block)
64
- raise ArgumentError, "Option name #{name} is already used" if @options.has_key?(name)
65
- raise ArgumentError, "Invalid option type #{type} specified" if !ALLOWED_TYPES.include?(type)
51
+ name = name.to_sym
52
+ raise ArgumentError, "Option name #{name} is already used" if @options.key?(name)
53
+ raise ArgumentError, "Invalid option type #{type} specified" unless ALLOWED_TYPES.include?(type)
66
54
  raise ArgumentError, "Invalid type for default value" if !(type === default) && !default.nil?
67
55
  raise ArgumentError, "Missing validator block" if type == Object && block.nil?
68
56
  @options[name] = Definition.new(name, type, default, desc, block)
@@ -75,13 +63,13 @@ module Kramdown
75
63
 
76
64
  # Return +true+ if an option called +name+ is defined.
77
65
  def self.defined?(name)
78
- @options.has_key?(name)
66
+ @options.key?(name.to_sym)
79
67
  end
80
68
 
81
69
  # Return a Hash with the default values for all options.
82
70
  def self.defaults
83
71
  temp = {}
84
- @options.each {|n, o| temp[o.name] = o.default}
72
+ @options.each {|_n, o| temp[o.name] = o.default }
85
73
  temp
86
74
  end
87
75
 
@@ -89,9 +77,9 @@ module Kramdown
89
77
  # names are considered and their value is run through the #parse method.
90
78
  def self.merge(hash)
91
79
  temp = defaults
92
- hash.each do |k,v|
93
- next unless @options.has_key?(k)
94
- temp[k] = parse(k, v)
80
+ hash.each do |k, v|
81
+ k = k.to_sym
82
+ temp[k] = @options.key?(k) ? parse(k, v) : v
95
83
  end
96
84
  temp
97
85
  end
@@ -102,8 +90,9 @@ module Kramdown
102
90
  # If +data+ already has the correct type, it is just returned. Otherwise it is converted to a
103
91
  # String and then to the correct type.
104
92
  def self.parse(name, data)
105
- raise ArgumentError, "No option named #{name} defined" if !@options.has_key?(name)
106
- if !(@options[name].type === data)
93
+ name = name.to_sym
94
+ raise ArgumentError, "No option named #{name} defined" unless @options.key?(name)
95
+ unless @options[name].type === data
107
96
  data = data.to_s
108
97
  data = if @options[name].type == String
109
98
  data
@@ -112,9 +101,7 @@ module Kramdown
112
101
  elsif @options[name].type == Float
113
102
  Float(data) rescue raise Kramdown::Error, "Invalid float value for option '#{name}': '#{data}'"
114
103
  elsif @options[name].type == Symbol
115
- data.strip!
116
- data = data[1..-1] if data[0] == ?:
117
- (data.empty? || data == 'nil' ? nil : data.to_sym)
104
+ str_to_sym(data)
118
105
  elsif @options[name].type == Boolean
119
106
  data.downcase.strip != 'false' && !data.empty?
120
107
  end
@@ -123,6 +110,17 @@ module Kramdown
123
110
  data
124
111
  end
125
112
 
113
+ # Converts the given String +data+ into a Symbol or +nil+ with the
114
+ # following provisions:
115
+ #
116
+ # - A leading colon is stripped from the string.
117
+ # - An empty value or a value equal to "nil" results in +nil+.
118
+ def self.str_to_sym(data)
119
+ data = data.strip
120
+ data = data[1..-1] if data[0] == ':'
121
+ (data.empty? || data == 'nil' ? nil : data.to_sym)
122
+ end
123
+
126
124
  # ----------------------------
127
125
  # :section: Option Validators
128
126
  #
@@ -135,19 +133,36 @@ module Kramdown
135
133
  # - a comma separated string which is split into an array of values
136
134
  # - or an array.
137
135
  #
138
- # Additionally, the array is checked for the correct size.
139
- def self.simple_array_validator(val, name, size)
136
+ # Optionally, the array is checked for the correct size.
137
+ def self.simple_array_validator(val, name, size = nil)
140
138
  if String === val
141
139
  val = val.split(/,/)
142
140
  elsif !(Array === val)
143
141
  raise Kramdown::Error, "Invalid type #{val.class} for option #{name}"
144
142
  end
145
- if val.size != size
143
+ if size && val.size != size
146
144
  raise Kramdown::Error, "Option #{name} needs exactly #{size} values"
147
145
  end
148
146
  val
149
147
  end
150
148
 
149
+ # Ensures that the option value +val+ for the option called +name+ is a valid hash. The
150
+ # parameter +val+ can be
151
+ #
152
+ # - a hash in YAML format
153
+ # - or a Ruby Hash object.
154
+ def self.simple_hash_validator(val, name)
155
+ if String === val
156
+ begin
157
+ val = YAML.safe_load(val)
158
+ rescue RuntimeError, ArgumentError, SyntaxError
159
+ raise Kramdown::Error, "Invalid YAML value for option #{name}"
160
+ end
161
+ end
162
+ raise Kramdown::Error, "Invalid type #{val.class} for option #{name}" unless Hash === val
163
+ val
164
+ end
165
+
151
166
  # ----------------------------
152
167
  # :section: Option Definitions
153
168
  #
@@ -155,109 +170,134 @@ module Kramdown
155
170
  # parsers/converters.
156
171
  # ----------------------------
157
172
 
158
- define(:template, String, '', <<EOF)
159
- The name of an ERB template file that should be used to wrap the output
173
+ define(:template, String, '', <<~EOF)
174
+ The name of an ERB template file that should be used to wrap the output
175
+ or the ERB template itself.
160
176
 
161
- This is used to wrap the output in an environment so that the output can
162
- be used as a stand-alone document. For example, an HTML template would
163
- provide the needed header and body tags so that the whole output is a
164
- valid HTML file. If no template is specified, the output will be just
165
- the converted text.
177
+ This is used to wrap the output in an environment so that the output can
178
+ be used as a stand-alone document. For example, an HTML template would
179
+ provide the needed header and body tags so that the whole output is a
180
+ valid HTML file. If no template is specified, the output will be just
181
+ the converted text.
166
182
 
167
- When resolving the template file, the given template name is used first.
168
- If such a file is not found, the converter extension is appended. If the
169
- file still cannot be found, the templates name is interpreted as a
170
- template name that is provided by kramdown (without the converter
171
- extension).
183
+ When resolving the template file, the given template name is used first.
184
+ If such a file is not found, the converter extension (the same as the
185
+ converter name) is appended. If the file still cannot be found, the
186
+ templates name is interpreted as a template name that is provided by
187
+ kramdown (without the converter extension). If the file is still not
188
+ found, the template name is checked if it starts with 'string://' and if
189
+ it does, this prefix is removed and the rest is used as template
190
+ content.
172
191
 
173
- kramdown provides a default template named 'document' for each converter.
192
+ kramdown provides a default template named 'document' for each converter.
174
193
 
175
- Default: ''
176
- Used by: all converters
177
- EOF
194
+ Default: ''
195
+ Used by: all converters
196
+ EOF
178
197
 
179
- define(:auto_ids, Boolean, true, <<EOF)
180
- Use automatic header ID generation
198
+ define(:auto_ids, Boolean, true, <<~EOF)
199
+ Use automatic header ID generation
181
200
 
182
- If this option is `true`, ID values for all headers are automatically
183
- generated if no ID is explicitly specified.
201
+ If this option is `true`, ID values for all headers are automatically
202
+ generated if no ID is explicitly specified.
184
203
 
185
- Default: true
186
- Used by: HTML/Latex converter
187
- EOF
204
+ Default: true
205
+ Used by: HTML/Latex converter
206
+ EOF
188
207
 
189
- define(:auto_id_prefix, String, '', <<EOF)
190
- Prefix used for automatically generated heaer IDs
208
+ define(:auto_id_stripping, Boolean, false, <<~EOF)
209
+ Strip all formatting from header text for automatic ID generation
191
210
 
192
- This option can be used to set a prefix for the automatically generated
193
- header IDs so that there is no conflict when rendering multiple kramdown
194
- documents into one output file separately. The prefix should only
195
- contain characters that are valid in an ID!
211
+ If this option is `true`, only the text elements of a header are used
212
+ for generating the ID later (in contrast to just using the raw header
213
+ text line).
196
214
 
197
- Default: ''
198
- Used by: HTML/Latex converter
199
- EOF
215
+ This option will be removed in version 2.0 because this will be the
216
+ default then.
200
217
 
201
- define(:parse_block_html, Boolean, false, <<EOF)
202
- Process kramdown syntax in block HTML tags
218
+ Default: false
219
+ Used by: kramdown parser
220
+ EOF
203
221
 
204
- If this option is `true`, the kramdown parser processes the content of
205
- block HTML tags as text containing block-level elements. Since this is
206
- not wanted normally, the default is `false`. It is normally better to
207
- selectively enable kramdown processing via the markdown attribute.
222
+ define(:auto_id_prefix, String, '', <<~EOF)
223
+ Prefix used for automatically generated header IDs
208
224
 
209
- Default: false
210
- Used by: kramdown parser
211
- EOF
225
+ This option can be used to set a prefix for the automatically generated
226
+ header IDs so that there is no conflict when rendering multiple kramdown
227
+ documents into one output file separately. The prefix should only
228
+ contain characters that are valid in an ID!
212
229
 
213
- define(:parse_span_html, Boolean, true, <<EOF)
214
- Process kramdown syntax in span HTML tags
230
+ Default: ''
231
+ Used by: HTML/Latex converter
232
+ EOF
215
233
 
216
- If this option is `true`, the kramdown parser processes the content of
217
- span HTML tags as text containing span-level elements.
234
+ define(:transliterated_header_ids, Boolean, false, <<~EOF)
235
+ Transliterate the header text before generating the ID
218
236
 
219
- Default: true
220
- Used by: kramdown parser
221
- EOF
237
+ Only ASCII characters are used in headers IDs. This is not good for
238
+ languages with many non-ASCII characters. By enabling this option
239
+ the header text is transliterated to ASCII as good as possible so that
240
+ the resulting header ID is more useful.
222
241
 
223
- define(:html_to_native, Boolean, false, <<EOF)
224
- Convert HTML elements to native elements
242
+ The stringex library needs to be installed for this feature to work!
225
243
 
226
- If this option is `true`, the parser converts HTML elements to native
227
- elements. For example, when parsing `<em>hallo</em>` the emphasis tag
228
- would normally be converted to an `:html` element with tag type `:em`.
229
- If `html_to_native` is `true`, then the emphasis would be converted to a
230
- native `:em` element.
244
+ Default: false
245
+ Used by: HTML/Latex converter
246
+ EOF
231
247
 
232
- This is useful for converters that cannot deal with HTML elements.
248
+ define(:parse_block_html, Boolean, false, <<~EOF)
249
+ Process kramdown syntax in block HTML tags
233
250
 
234
- Default: false
235
- Used by: kramdown parser
236
- EOF
251
+ If this option is `true`, the kramdown parser processes the content of
252
+ block HTML tags as text containing block-level elements. Since this is
253
+ not wanted normally, the default is `false`. It is normally better to
254
+ selectively enable kramdown processing via the markdown attribute.
237
255
 
238
- define(:link_defs, Object, {}, <<EOF) do |val|
239
- Pre-defines link definitions
256
+ Default: false
257
+ Used by: kramdown parser
258
+ EOF
240
259
 
241
- This option can be used to pre-define link definitions. The value needs
242
- to be a Hash where the keys are the link identifiers and the values are
243
- two element Arrays with the link URL and the link title.
260
+ define(:parse_span_html, Boolean, true, <<~EOF)
261
+ Process kramdown syntax in span HTML tags
244
262
 
245
- If the value is a String, it has to contain a valid YAML hash and the
246
- hash has to follow the above guidelines.
263
+ If this option is `true`, the kramdown parser processes the content of
264
+ span HTML tags as text containing span-level elements.
247
265
 
248
- Default: {}
249
- Used by: kramdown parser
250
- EOF
251
- if String === val
252
- begin
253
- val = YAML.load(val)
254
- rescue RuntimeError, ArgumentError, SyntaxError
255
- raise Kramdown::Error, "Invalid YAML value for option link_defs"
256
- end
257
- end
258
- raise Kramdown::Error, "Invalid type #{val.class} for option #{name}" if !(Hash === val)
259
- val.each do |k,v|
260
- if !(Array === v) || v.size > 2 || v.size < 1
266
+ Default: true
267
+ Used by: kramdown parser
268
+ EOF
269
+
270
+ define(:html_to_native, Boolean, false, <<~EOF)
271
+ Convert HTML elements to native elements
272
+
273
+ If this option is `true`, the parser converts HTML elements to native
274
+ elements. For example, when parsing `<em>hallo</em>` the emphasis tag
275
+ would normally be converted to an `:html` element with tag type `:em`.
276
+ If `html_to_native` is `true`, then the emphasis would be converted to a
277
+ native `:em` element.
278
+
279
+ This is useful for converters that cannot deal with HTML elements.
280
+
281
+ Default: false
282
+ Used by: kramdown parser
283
+ EOF
284
+
285
+ define(:link_defs, Object, {}, <<~EOF) do |val|
286
+ Pre-defines link definitions
287
+
288
+ This option can be used to pre-define link definitions. The value needs
289
+ to be a Hash where the keys are the link identifiers and the values are
290
+ two element Arrays with the link URL and the link title.
291
+
292
+ If the value is a String, it has to contain a valid YAML hash and the
293
+ hash has to follow the above guidelines.
294
+
295
+ Default: {}
296
+ Used by: kramdown parser
297
+ EOF
298
+ val = simple_hash_validator(val, :link_defs)
299
+ val.each do |_k, v|
300
+ if !(Array === v) || v.size > 2 || v.empty?
261
301
  raise Kramdown::Error, "Invalid structure for hash value of option #{name}"
262
302
  end
263
303
  v << nil if v.size == 1
@@ -265,194 +305,299 @@ EOF
265
305
  val
266
306
  end
267
307
 
268
- define(:footnote_nr, Integer, 1, <<EOF)
269
- The number of the first footnote
308
+ define(:footnote_nr, Integer, 1, <<~EOF)
309
+ The number of the first footnote
270
310
 
271
- This option can be used to specify the number that is used for the first
272
- footnote.
311
+ This option can be used to specify the number that is used for the first
312
+ footnote.
273
313
 
274
- Default: 1
275
- Used by: HTML converter
276
- EOF
314
+ Default: 1
315
+ Used by: HTML converter
316
+ EOF
277
317
 
278
- define(:enable_coderay, Boolean, true, <<EOF)
279
- Use coderay for syntax highlighting
318
+ define(:entity_output, Symbol, :as_char, <<~EOF)
319
+ Defines how entities are output
280
320
 
281
- If this option is `true`, coderay is used by the HTML converter for
282
- syntax highlighting the content of code spans and code blocks.
321
+ The possible values are :as_input (entities are output in the same
322
+ form as found in the input), :numeric (entities are output in numeric
323
+ form), :symbolic (entities are output in symbolic form if possible) or
324
+ :as_char (entities are output as characters if possible, only available
325
+ on Ruby 1.9).
283
326
 
284
- Default: true
285
- Used by: HTML converter
286
- EOF
327
+ Default: :as_char
328
+ Used by: HTML converter, kramdown converter
329
+ EOF
287
330
 
288
- define(:coderay_wrap, Symbol, :div, <<EOF)
289
- Defines how the highlighted code should be wrapped
331
+ TOC_LEVELS_RANGE = (1..6).freeze
332
+ TOC_LEVELS_ARRAY = TOC_LEVELS_RANGE.to_a.freeze
333
+ private_constant :TOC_LEVELS_RANGE, :TOC_LEVELS_ARRAY
290
334
 
291
- The possible values are :span, :div or nil.
335
+ define(:toc_levels, Object, TOC_LEVELS_ARRAY, <<~EOF) do |val|
336
+ Defines the levels that are used for the table of contents
292
337
 
293
- Default: :div
294
- Used by: HTML converter
295
- EOF
338
+ The individual levels can be specified by separating them with commas
339
+ (e.g. 1,2,3) or by using the range syntax (e.g. 1..3). Only the
340
+ specified levels are used for the table of contents.
296
341
 
297
- define(:coderay_line_numbers, Symbol, :inline, <<EOF)
298
- Defines how and if line numbers should be shown
342
+ Default: 1..6
343
+ Used by: HTML/Latex converter
344
+ EOF
345
+ case val
346
+ when String
347
+ if val =~ /^(\d)\.\.(\d)$/
348
+ val = Range.new($1.to_i, $2.to_i).to_a
349
+ elsif val =~ /^\d(?:,\d)*$/
350
+ val = val.split(/,/).map(&:to_i).uniq
351
+ else
352
+ raise Kramdown::Error, "Invalid syntax for option toc_levels"
353
+ end
354
+ when Array
355
+ unless val.eql?(TOC_LEVELS_ARRAY)
356
+ val = val.map(&:to_i).uniq
357
+ end
358
+ when Range
359
+ if val.eql?(TOC_LEVELS_RANGE)
360
+ val = TOC_LEVELS_ARRAY
361
+ else
362
+ val = val.map(&:to_i).uniq
363
+ end
364
+ else
365
+ raise Kramdown::Error, "Invalid type #{val.class} for option toc_levels"
366
+ end
367
+ if val.any? {|i| !TOC_LEVELS_RANGE.cover?(i) }
368
+ raise Kramdown::Error, "Level numbers for option toc_levels have to be integers from 1 to 6"
369
+ end
370
+ val
371
+ end
299
372
 
300
- The possible values are :table, :inline or nil. If this option is
301
- nil, no line numbers are shown.
373
+ define(:line_width, Integer, 72, <<~EOF)
374
+ Defines the line width to be used when outputting a document
302
375
 
303
- Default: :inline
304
- Used by: HTML converter
305
- EOF
376
+ Default: 72
377
+ Used by: kramdown converter
378
+ EOF
306
379
 
307
- define(:coderay_line_number_start, Integer, 1, <<EOF)
308
- The start value for the line numbers
380
+ define(:latex_headers, Object, %w[section subsection subsubsection paragraph subparagraph subparagraph], <<~EOF) do |val|
381
+ Defines the LaTeX commands for different header levels
309
382
 
310
- Default: 1
311
- Used by: HTML converter
312
- EOF
383
+ The commands for the header levels one to six can be specified by
384
+ separating them with commas.
313
385
 
314
- define(:coderay_tab_width, Integer, 8, <<EOF)
315
- The tab width used in highlighted code
386
+ Default: section,subsection,subsubsection,paragraph,subparagraph,subparagraph
387
+ Used by: Latex converter
388
+ EOF
389
+ simple_array_validator(val, :latex_headers, 6)
390
+ end
316
391
 
317
- Used by: HTML converter
318
- EOF
392
+ SMART_QUOTES_ENTITIES = %w[lsquo rsquo ldquo rdquo].freeze
393
+ SMART_QUOTES_STR = SMART_QUOTES_ENTITIES.join(',').freeze
394
+ private_constant :SMART_QUOTES_ENTITIES, :SMART_QUOTES_STR
319
395
 
320
- define(:coderay_bold_every, Integer, 10, <<EOF)
321
- Defines how often a line number should be made bold
396
+ define(:smart_quotes, Object, SMART_QUOTES_ENTITIES, <<~EOF) do |val|
397
+ Defines the HTML entity names or code points for smart quote output
322
398
 
323
- Default: 10
324
- Used by: HTML converter
325
- EOF
399
+ The entities identified by entity name or code point that should be
400
+ used for, in order, a left single quote, a right single quote, a left
401
+ double and a right double quote are specified by separating them with
402
+ commas.
326
403
 
327
- define(:coderay_css, Symbol, :style, <<EOF)
328
- Defines how the highlighted code gets styled
404
+ Default: lsquo,rsquo,ldquo,rdquo
405
+ Used by: HTML/Latex converter
406
+ EOF
407
+ if val == SMART_QUOTES_STR || val == SMART_QUOTES_ENTITIES
408
+ SMART_QUOTES_ENTITIES
409
+ else
410
+ val = simple_array_validator(val, :smart_quotes, 4)
411
+ val.map! {|v| Integer(v) rescue v }
412
+ val
413
+ end
414
+ end
329
415
 
330
- Possible values are :class (CSS classes are applied to the code
331
- elements, one must supply the needed CSS file) or :style (default CSS
332
- styles are directly applied to the code elements).
416
+ define(:typographic_symbols, Object, {}, <<~EOF) do |val|
417
+ Defines a mapping from typographical symbol to output characters
418
+
419
+ Typographical symbols are normally output using their equivalent Unicode
420
+ codepoint. However, sometimes one wants to change the output, mostly to
421
+ fallback to a sequence of ASCII characters.
422
+
423
+ This option allows this by specifying a mapping from typographical
424
+ symbol to its output string. For example, the mapping {hellip: ...} would
425
+ output the standard ASCII representation of an ellipsis.
426
+
427
+ The available typographical symbol names are:
428
+
429
+ * hellip: ellipsis
430
+ * mdash: em-dash
431
+ * ndash: en-dash
432
+ * laquo: left guillemet
433
+ * raquo: right guillemet
434
+ * laquo_space: left guillemet followed by a space
435
+ * raquo_space: right guillemet preceeded by a space
436
+
437
+ Default: {}
438
+ Used by: HTML/Latex converter
439
+ EOF
440
+ val = simple_hash_validator(val, :typographic_symbols)
441
+ val.keys.each do |k|
442
+ val[k.kind_of?(String) ? str_to_sym(k) : k] = val.delete(k).to_s
443
+ end
444
+ val
445
+ end
333
446
 
334
- Default: style
335
- Used by: HTML converter
336
- EOF
447
+ define(:remove_block_html_tags, Boolean, true, <<~EOF)
448
+ Remove block HTML tags
337
449
 
338
- define(:coderay_default_lang, Symbol, nil, <<EOF)
339
- Sets the default language for highlighting code blocks
450
+ If this option is `true`, the RemoveHtmlTags converter removes
451
+ block HTML tags.
340
452
 
341
- If no language is set for a code block, the default language is used
342
- instead. The value has to be one of the languages supported by coderay
343
- or nil if no default language should be used.
453
+ Default: true
454
+ Used by: RemoveHtmlTags converter
455
+ EOF
344
456
 
345
- Default: nil
346
- Used by: HTML converter
347
- EOF
457
+ define(:remove_span_html_tags, Boolean, false, <<~EOF)
458
+ Remove span HTML tags
348
459
 
349
- define(:entity_output, Symbol, :as_char, <<EOF)
350
- Defines how entities are output
460
+ If this option is `true`, the RemoveHtmlTags converter removes
461
+ span HTML tags.
351
462
 
352
- The possible values are :as_input (entities are output in the same
353
- form as found in the input), :numeric (entities are output in numeric
354
- form), :symbolic (entities are output in symbolic form if possible) or
355
- :as_char (entities are output as characters if possible, only available
356
- on Ruby 1.9).
463
+ Default: false
464
+ Used by: RemoveHtmlTags converter
465
+ EOF
357
466
 
358
- Default: :as_char
359
- Used by: HTML converter, kramdown converter
360
- EOF
467
+ define(:header_offset, Integer, 0, <<~EOF)
468
+ Sets the output offset for headers
361
469
 
362
- define(:toc_levels, Object, (1..6).to_a, <<EOF) do |val|
363
- Defines the levels that are used for the table of contents
470
+ If this option is c (may also be negative) then a header with level n
471
+ will be output as a header with level c+n. If c+n is lower than 1,
472
+ level 1 will be used. If c+n is greater than 6, level 6 will be used.
364
473
 
365
- The individual levels can be specified by separating them with commas
366
- (e.g. 1,2,3) or by using the range syntax (e.g. 1..3). Only the
367
- specified levels are used for the table of contents.
474
+ Default: 0
475
+ Used by: HTML converter, Kramdown converter, Latex converter
476
+ EOF
368
477
 
369
- Default: 1..6
370
- Used by: HTML/Latex converter
371
- EOF
372
- if String === val
373
- if val =~ /^(\d)\.\.(\d)$/
374
- val = Range.new($1.to_i, $2.to_i).to_a
375
- elsif val =~ /^\d(?:,\d)*$/
376
- val = val.split(/,/).map {|s| s.to_i}.uniq
377
- else
378
- raise Kramdown::Error, "Invalid syntax for option toc_levels"
379
- end
380
- elsif Array === val
381
- val = val.map {|s| s.to_i}.uniq
382
- else
383
- raise Kramdown::Error, "Invalid type #{val.class} for option toc_levels"
384
- end
385
- if val.any? {|i| !(1..6).include?(i)}
386
- raise Kramdown::Error, "Level numbers for option toc_levels have to be integers from 1 to 6"
478
+ define(:syntax_highlighter, Symbol, :rouge, <<~EOF)
479
+ Set the syntax highlighter
480
+
481
+ Specifies the syntax highlighter that should be used for highlighting
482
+ code blocks and spans. If this option is set to +nil+, no syntax
483
+ highlighting is done.
484
+
485
+ Options for the syntax highlighter can be set with the
486
+ syntax_highlighter_opts configuration option.
487
+
488
+ Default: rouge
489
+ Used by: HTML/Latex converter
490
+ EOF
491
+
492
+ define(:syntax_highlighter_opts, Object, {}, <<~EOF) do |val|
493
+ Set the syntax highlighter options
494
+
495
+ Specifies options for the syntax highlighter set via the
496
+ syntax_highlighter configuration option.
497
+
498
+ The value needs to be a hash with key-value pairs that are understood by
499
+ the used syntax highlighter.
500
+
501
+ Default: {}
502
+ Used by: HTML/Latex converter
503
+ EOF
504
+ val = simple_hash_validator(val, :syntax_highlighter_opts)
505
+ val.keys.each do |k|
506
+ val[k.kind_of?(String) ? str_to_sym(k) : k] = val.delete(k)
387
507
  end
388
508
  val
389
509
  end
390
510
 
391
- define(:line_width, Integer, 72, <<EOF)
392
- Defines the line width to be used when outputting a document
511
+ define(:math_engine, Symbol, :mathjax, <<~EOF)
512
+ Set the math engine
393
513
 
394
- Default: 72
395
- Used by: kramdown converter
396
- EOF
514
+ Specifies the math engine that should be used for converting math
515
+ blocks/spans. If this option is set to +nil+, no math engine is used and
516
+ the math blocks/spans are output as is.
397
517
 
398
- define(:latex_headers, Object, %w{section subsection subsubsection paragraph subparagraph subparagraph}, <<EOF) do |val|
399
- Defines the LaTeX commands for different header levels
518
+ Options for the selected math engine can be set with the
519
+ math_engine_opts configuration option.
400
520
 
401
- The commands for the header levels one to six can be specified by
402
- separating them with commas.
521
+ Default: mathjax
522
+ Used by: HTML converter
523
+ EOF
403
524
 
404
- Default: section,subsection,subsubsection,paragraph,subparagraph,subparagraph
405
- Used by: Latex converter
406
- EOF
407
- simple_array_validator(val, :latex_headers, 6)
408
- end
525
+ define(:math_engine_opts, Object, {}, <<~EOF) do |val|
526
+ Set the math engine options
409
527
 
410
- define(:smart_quotes, Object, %w{lsquo rsquo ldquo rdquo}, <<EOF) do |val|
411
- Defines the HTML entity names or code points for smart quote output
528
+ Specifies options for the math engine set via the math_engine
529
+ configuration option.
412
530
 
413
- The entities identified by entity name or code point that should be
414
- used for, in order, a left single quote, a right single quote, a left
415
- double and a right double quote are specified by separating them with
416
- commas.
531
+ The value needs to be a hash with key-value pairs that are understood by
532
+ the used math engine.
417
533
 
418
- Default: lsquo,rsquo,ldquo,rdquo
419
- Used by: HTML/Latex converter
420
- EOF
421
- val = simple_array_validator(val, :smart_quotes, 4)
422
- val.map! {|v| Integer(v) rescue v}
534
+ Default: {}
535
+ Used by: HTML converter
536
+ EOF
537
+ val = simple_hash_validator(val, :math_engine_opts)
538
+ val.keys.each do |k|
539
+ val[k.kind_of?(String) ? str_to_sym(k) : k] = val.delete(k)
540
+ end
423
541
  val
424
542
  end
425
543
 
426
- define(:remove_block_html_tags, Boolean, true, <<EOF)
427
- Remove block HTML tags
544
+ define(:footnote_backlink, String, '&#8617;', <<~EOF)
545
+ Defines the text that should be used for the footnote backlinks
546
+
547
+ The footnote backlink is just text, so any special HTML characters will
548
+ be escaped.
549
+
550
+ If the footnote backlint text is an empty string, no footnote backlinks
551
+ will be generated.
428
552
 
429
- If this option is `true`, the RemoveHtmlTags converter removes
430
- block HTML tags.
553
+ Default: '&8617;'
554
+ Used by: HTML converter
555
+ EOF
431
556
 
432
- Default: true
433
- Used by: RemoveHtmlTags converter
434
- EOF
557
+ define(:footnote_backlink_inline, Boolean, false, <<~EOF)
558
+ Specifies whether the footnote backlink should always be inline
435
559
 
436
- define(:remove_span_html_tags, Boolean, false, <<EOF)
437
- Remove span HTML tags
560
+ With the default of false the footnote backlink is placed at the end of
561
+ the last paragraph if there is one, or an extra paragraph with only the
562
+ footnote backlink is created.
438
563
 
439
- If this option is `true`, the RemoveHtmlTags converter removes
440
- span HTML tags.
564
+ Setting this option to true tries to place the footnote backlink in the
565
+ last, possibly nested paragraph or header. If this fails (e.g. in the
566
+ case of a table), an extra paragraph with only the footnote backlink is
567
+ created.
441
568
 
442
- Default: false
443
- Used by: RemoveHtmlTags converter
444
- EOF
569
+ Default: false
570
+ Used by: HTML converter
571
+ EOF
445
572
 
446
- define(:header_offset, Integer, 0, <<EOF)
447
- Sets the output offset for headers
573
+ define(:footnote_prefix, String, '', <<~EOF)
574
+ Prefix used for footnote IDs
448
575
 
449
- If this option is c (may also be negative) then a header with level n
450
- will be output as a header with level c+n. If c+n is lower than 1,
451
- level 1 will be used. If c+n is greater than 6, level 6 will be used.
576
+ This option can be used to set a prefix for footnote IDs. This is useful
577
+ when rendering multiple documents into the same output file to avoid
578
+ duplicate IDs. The prefix should only contain characters that are valid
579
+ in an ID!
452
580
 
453
- Default: 0
454
- Used by: HTML converter, Kramdown converter, Latex converter
455
- EOF
581
+ Default: ''
582
+ Used by: HTML
583
+ EOF
584
+
585
+ define(:remove_line_breaks_for_cjk, Boolean, false, <<~EOF)
586
+ Specifies whether line breaks should be removed between CJK characters
587
+
588
+ Default: false
589
+ Used by: HTML converter
590
+ EOF
591
+
592
+ define(:forbidden_inline_options, Object, %w[template], <<~EOF) do |val|
593
+ Defines the options that may not be set using the {::options} extension
594
+
595
+ Default: template
596
+ Used by: HTML converter
597
+ EOF
598
+ val.map! {|item| item.kind_of?(String) ? str_to_sym(item) : item }
599
+ simple_array_validator(val, :forbidden_inline_options)
600
+ end
456
601
 
457
602
  end
458
603