kramdown 1.17.0 → 2.0.0.beta1

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 (196) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTERS +4 -2
  3. data/VERSION +1 -1
  4. data/bin/kramdown +13 -14
  5. data/lib/kramdown.rb +2 -2
  6. data/lib/kramdown/converter.rb +6 -7
  7. data/lib/kramdown/converter/base.rb +18 -29
  8. data/lib/kramdown/converter/hash_ast.rb +4 -4
  9. data/lib/kramdown/converter/html.rb +82 -67
  10. data/lib/kramdown/converter/kramdown.rb +83 -78
  11. data/lib/kramdown/converter/latex.rb +53 -47
  12. data/lib/kramdown/converter/man.rb +22 -25
  13. data/lib/kramdown/converter/math_engine/mathjax.rb +10 -10
  14. data/lib/kramdown/converter/remove_html_tags.rb +2 -2
  15. data/lib/kramdown/converter/syntax_highlighter.rb +2 -2
  16. data/lib/kramdown/converter/syntax_highlighter/minted.rb +2 -2
  17. data/lib/kramdown/converter/syntax_highlighter/rouge.rb +5 -5
  18. data/lib/kramdown/converter/toc.rb +5 -5
  19. data/lib/kramdown/document.rb +9 -11
  20. data/lib/kramdown/element.rb +11 -9
  21. data/lib/kramdown/error.rb +2 -2
  22. data/lib/kramdown/options.rb +258 -384
  23. data/lib/kramdown/parser.rb +2 -3
  24. data/lib/kramdown/parser/base.rb +7 -6
  25. data/lib/kramdown/parser/html.rb +103 -95
  26. data/lib/kramdown/parser/kramdown.rb +32 -36
  27. data/lib/kramdown/parser/kramdown/abbreviation.rb +13 -10
  28. data/lib/kramdown/parser/kramdown/autolink.rb +3 -3
  29. data/lib/kramdown/parser/kramdown/blank_line.rb +2 -2
  30. data/lib/kramdown/parser/kramdown/block_boundary.rb +2 -2
  31. data/lib/kramdown/parser/kramdown/blockquote.rb +4 -5
  32. data/lib/kramdown/parser/kramdown/codeblock.rb +4 -5
  33. data/lib/kramdown/parser/kramdown/codespan.rb +5 -5
  34. data/lib/kramdown/parser/kramdown/emphasis.rb +6 -6
  35. data/lib/kramdown/parser/kramdown/eob.rb +2 -2
  36. data/lib/kramdown/parser/kramdown/escaped_chars.rb +2 -2
  37. data/lib/kramdown/parser/kramdown/extensions.rb +31 -26
  38. data/lib/kramdown/parser/kramdown/footnote.rb +7 -6
  39. data/lib/kramdown/parser/kramdown/header.rb +6 -6
  40. data/lib/kramdown/parser/kramdown/horizontal_rule.rb +3 -3
  41. data/lib/kramdown/parser/kramdown/html.rb +31 -26
  42. data/lib/kramdown/parser/kramdown/html_entity.rb +6 -5
  43. data/lib/kramdown/parser/kramdown/line_break.rb +3 -3
  44. data/lib/kramdown/parser/kramdown/link.rb +13 -11
  45. data/lib/kramdown/parser/kramdown/list.rb +38 -40
  46. data/lib/kramdown/parser/kramdown/math.rb +4 -5
  47. data/lib/kramdown/parser/kramdown/paragraph.rb +5 -5
  48. data/lib/kramdown/parser/kramdown/smart_quotes.rb +23 -23
  49. data/lib/kramdown/parser/kramdown/table.rb +18 -17
  50. data/lib/kramdown/parser/kramdown/typographic_symbol.rb +8 -8
  51. data/lib/kramdown/parser/markdown.rb +9 -8
  52. data/lib/kramdown/utils.rb +5 -6
  53. data/lib/kramdown/utils/configurable.rb +7 -6
  54. data/lib/kramdown/utils/entities.rb +286 -289
  55. data/lib/kramdown/utils/html.rb +10 -12
  56. data/lib/kramdown/utils/lru_cache.rb +3 -2
  57. data/lib/kramdown/utils/string_scanner.rb +2 -3
  58. data/lib/kramdown/utils/unidecoder.rb +8 -6
  59. data/lib/kramdown/version.rb +3 -3
  60. data/man/man1/kramdown.1 +3 -107
  61. data/test/run_tests.rb +6 -6
  62. data/test/test_files.rb +122 -298
  63. data/test/test_location.rb +8 -30
  64. data/test/test_string_scanner_kramdown.rb +6 -9
  65. data/test/testcases/block/06_codeblock/highlighting-opts.html +6 -6
  66. data/test/testcases/block/06_codeblock/highlighting.html +5 -6
  67. data/test/testcases/block/06_codeblock/with_lang_in_fenced_block.options +1 -1
  68. data/test/testcases/block/07_horizontal_rule/error.html +2 -2
  69. data/test/testcases/block/09_html/html5_attributes.html +2 -0
  70. data/test/testcases/block/09_html/html5_attributes.text +2 -0
  71. data/test/testcases/block/09_html/html_to_native/typography.html +1 -1
  72. data/test/testcases/block/09_html/simple.html +1 -1
  73. data/test/testcases/block/12_extension/options3.html +7 -6
  74. data/test/testcases/block/12_extension/options3.text +2 -2
  75. data/test/testcases/span/01_link/inline.html +1 -1
  76. data/test/testcases/span/01_link/reference.html +3 -3
  77. data/test/testcases/span/03_codespan/highlighting.html +1 -1
  78. data/test/testcases/span/text_substitutions/entities_as_char.html +1 -1
  79. metadata +5 -234
  80. data/Rakefile +0 -341
  81. data/benchmark/benchmark.rb +0 -43
  82. data/benchmark/benchmark.sh +0 -74
  83. data/benchmark/generate_data.rb +0 -119
  84. data/benchmark/mdbasics.text +0 -306
  85. data/benchmark/mdsyntax.text +0 -888
  86. data/benchmark/testing.sh +0 -12
  87. data/benchmark/timing.sh +0 -10
  88. data/doc/_design.scss +0 -441
  89. data/doc/bg.png +0 -0
  90. data/doc/default.scss +0 -217
  91. data/doc/default.template +0 -62
  92. data/doc/documentation.page +0 -84
  93. data/doc/documentation.template +0 -36
  94. data/doc/index.page +0 -113
  95. data/doc/installation.page +0 -88
  96. data/doc/links.markdown +0 -6
  97. data/doc/metainfo +0 -13
  98. data/doc/news.feed +0 -9
  99. data/doc/news.page +0 -29
  100. data/doc/options.page +0 -49
  101. data/doc/quickref.page +0 -603
  102. data/doc/sidebar.template +0 -22
  103. data/doc/sitemap.sitemap +0 -5
  104. data/doc/syntax.page +0 -1799
  105. data/doc/tests.page +0 -104
  106. data/doc/virtual +0 -14
  107. data/lib/kramdown/converter/math_engine/itex2mml.rb +0 -39
  108. data/lib/kramdown/converter/math_engine/katex.rb +0 -35
  109. data/lib/kramdown/converter/math_engine/mathjaxnode.rb +0 -56
  110. data/lib/kramdown/converter/math_engine/ritex.rb +0 -38
  111. data/lib/kramdown/converter/math_engine/sskatex.rb +0 -97
  112. data/lib/kramdown/converter/pdf.rb +0 -625
  113. data/lib/kramdown/converter/syntax_highlighter/coderay.rb +0 -81
  114. data/lib/kramdown/parser/gfm.rb +0 -188
  115. data/lib/kramdown/utils/ordered_hash.rb +0 -18
  116. data/setup.rb +0 -1585
  117. data/test/testcases/block/07_horizontal_rule/error.html.19 +0 -7
  118. data/test/testcases/block/09_html/html_to_native/typography.html.19 +0 -1
  119. data/test/testcases/block/09_html/simple.html.19 +0 -60
  120. data/test/testcases/block/15_math/itex2mml.html +0 -1
  121. data/test/testcases/block/15_math/itex2mml.options +0 -1
  122. data/test/testcases/block/15_math/itex2mml.text +0 -1
  123. data/test/testcases/block/15_math/katex.html.19 +0 -2
  124. data/test/testcases/block/15_math/katex.options +0 -1
  125. data/test/testcases/block/15_math/katex.text +0 -2
  126. data/test/testcases/block/15_math/mathjaxnode.html.19 +0 -27
  127. data/test/testcases/block/15_math/mathjaxnode.options +0 -1
  128. data/test/testcases/block/15_math/mathjaxnode.text +0 -1
  129. data/test/testcases/block/15_math/mathjaxnode_notexhints.html.19 +0 -23
  130. data/test/testcases/block/15_math/mathjaxnode_notexhints.options +0 -3
  131. data/test/testcases/block/15_math/mathjaxnode_notexhints.text +0 -1
  132. data/test/testcases/block/15_math/mathjaxnode_semantics.html.19 +0 -32
  133. data/test/testcases/block/15_math/mathjaxnode_semantics.options +0 -3
  134. data/test/testcases/block/15_math/mathjaxnode_semantics.text +0 -1
  135. data/test/testcases/block/15_math/ritex.html +0 -1
  136. data/test/testcases/block/15_math/ritex.options +0 -1
  137. data/test/testcases/block/15_math/ritex.text +0 -1
  138. data/test/testcases/block/15_math/sskatex.html.19 +0 -2
  139. data/test/testcases/block/15_math/sskatex.options +0 -1
  140. data/test/testcases/block/15_math/sskatex.text +0 -2
  141. data/test/testcases/span/01_link/inline.html.19 +0 -46
  142. data/test/testcases/span/01_link/reference.html.19 +0 -37
  143. data/test/testcases/span/math/itex2mml.html +0 -1
  144. data/test/testcases/span/math/itex2mml.options +0 -1
  145. data/test/testcases/span/math/itex2mml.text +0 -1
  146. data/test/testcases/span/math/katex.html.19 +0 -1
  147. data/test/testcases/span/math/katex.options +0 -1
  148. data/test/testcases/span/math/katex.text +0 -1
  149. data/test/testcases/span/math/mathjaxnode.html.19 +0 -27
  150. data/test/testcases/span/math/mathjaxnode.options +0 -1
  151. data/test/testcases/span/math/mathjaxnode.text +0 -1
  152. data/test/testcases/span/math/ritex.html +0 -1
  153. data/test/testcases/span/math/ritex.options +0 -1
  154. data/test/testcases/span/math/ritex.text +0 -1
  155. data/test/testcases/span/math/sskatex.html.19 +0 -1
  156. data/test/testcases/span/math/sskatex.options +0 -1
  157. data/test/testcases/span/math/sskatex.text +0 -1
  158. data/test/testcases/span/text_substitutions/entities_as_char.html.19 +0 -1
  159. data/test/testcases_gfm/atx_header.html +0 -3
  160. data/test/testcases_gfm/atx_header.text +0 -3
  161. data/test/testcases_gfm/backticks_disable_highlighting.html +0 -2
  162. data/test/testcases_gfm/backticks_disable_highlighting.options +0 -1
  163. data/test/testcases_gfm/backticks_disable_highlighting.text +0 -3
  164. data/test/testcases_gfm/backticks_syntax.html +0 -20
  165. data/test/testcases_gfm/backticks_syntax.text +0 -19
  166. data/test/testcases_gfm/codeblock_fenced.html +0 -20
  167. data/test/testcases_gfm/codeblock_fenced.options +0 -1
  168. data/test/testcases_gfm/codeblock_fenced.text +0 -21
  169. data/test/testcases_gfm/hard_line_breaks.html +0 -3
  170. data/test/testcases_gfm/hard_line_breaks.text +0 -3
  171. data/test/testcases_gfm/hard_line_breaks_off.html +0 -2
  172. data/test/testcases_gfm/hard_line_breaks_off.options +0 -1
  173. data/test/testcases_gfm/hard_line_breaks_off.text +0 -2
  174. data/test/testcases_gfm/header_ids.html +0 -27
  175. data/test/testcases_gfm/header_ids.html.19 +0 -27
  176. data/test/testcases_gfm/header_ids.options +0 -1
  177. data/test/testcases_gfm/header_ids.text +0 -27
  178. data/test/testcases_gfm/header_ids_with_prefix.html +0 -3
  179. data/test/testcases_gfm/header_ids_with_prefix.options +0 -2
  180. data/test/testcases_gfm/header_ids_with_prefix.text +0 -3
  181. data/test/testcases_gfm/no_typographic.html +0 -3
  182. data/test/testcases_gfm/no_typographic.html.19 +0 -3
  183. data/test/testcases_gfm/no_typographic.options +0 -1
  184. data/test/testcases_gfm/no_typographic.text +0 -3
  185. data/test/testcases_gfm/paragraph_end-disabled.html +0 -31
  186. data/test/testcases_gfm/paragraph_end-disabled.options +0 -1
  187. data/test/testcases_gfm/paragraph_end-disabled.text +0 -27
  188. data/test/testcases_gfm/paragraph_end.html +0 -38
  189. data/test/testcases_gfm/paragraph_end.text +0 -27
  190. data/test/testcases_gfm/strikethrough.html +0 -27
  191. data/test/testcases_gfm/strikethrough.html.19 +0 -27
  192. data/test/testcases_gfm/strikethrough.text +0 -27
  193. data/test/testcases_gfm/task_list.html +0 -40
  194. data/test/testcases_gfm/task_list.text +0 -26
  195. data/test/testcases_gfm/two_para_hard_line_breaks.html +0 -4
  196. data/test/testcases_gfm/two_para_hard_line_breaks.text +0 -4
@@ -1,7 +1,7 @@
1
- # -*- coding: utf-8 -*-
1
+ # -*- coding: utf-8; frozen_string_literal: true -*-
2
2
  #
3
3
  #--
4
- # Copyright (C) 2009-2016 Thomas Leitner <t_leitner@gmx.at>
4
+ # Copyright (C) 2009-2019 Thomas Leitner <t_leitner@gmx.at>
5
5
  #
6
6
  # This file is part of kramdown which is licensed under the MIT.
7
7
  #++
@@ -17,14 +17,14 @@ module Kramdown
17
17
  # man-pages(7) for information regarding the output.
18
18
  class Man < Base
19
19
 
20
- def convert(el, opts = {:indent => 0, :result => ''}) #:nodoc:
20
+ def convert(el, opts = {indent: 0, result: +''}) #:nodoc:
21
21
  send("convert_#{el.type}", el, opts)
22
22
  end
23
23
 
24
24
  private
25
25
 
26
26
  def inner(el, opts, use = :all)
27
- arr = el.children.reject {|e| e.type == :blank}
27
+ arr = el.children.reject {|e| e.type == :blank }
28
28
  arr.each_with_index do |inner_el, index|
29
29
  next if use == :rest && index == 0
30
30
  break if use == :first && index > 0
@@ -39,15 +39,15 @@ module Kramdown
39
39
 
40
40
  def convert_root(el, opts)
41
41
  @title_done = false
42
- opts[:result] = ".\\\" generated by kramdown\n"
42
+ opts[:result] = +".\\\" generated by kramdown\n"
43
43
  inner(el, opts)
44
44
  opts[:result]
45
45
  end
46
46
 
47
47
  def convert_blank(*)
48
48
  end
49
- alias :convert_hr :convert_blank
50
- alias :convert_xml_pi :convert_blank
49
+ alias convert_hr convert_blank
50
+ alias convert_xml_pi convert_blank
51
51
 
52
52
  def convert_p(el, opts)
53
53
  if (opts[:index] != 0 && opts[:prev].type != :header) ||
@@ -104,8 +104,8 @@ module Kramdown
104
104
  inner(el, opts)
105
105
  opts[:result] << macro("PD") if compact
106
106
  end
107
- alias :convert_dl :convert_ul
108
- alias :convert_ol :convert_ul
107
+ alias convert_dl convert_ul
108
+ alias convert_ol convert_ul
109
109
 
110
110
  def convert_li(el, opts)
111
111
  sym = (opts[:parent].type == :ul ? '\(bu' : "#{opts[:index] + 1}.")
@@ -134,19 +134,19 @@ module Kramdown
134
134
  opts[:result] << macro("sp") if opts[:next] && opts[:next].type == :dd
135
135
  end
136
136
 
137
- TABLE_CELL_ALIGNMENT = {:left => 'l', :center => 'c', :right => 'r', :default => 'l'}
137
+ TABLE_CELL_ALIGNMENT = {left: 'l', center: 'c', right: 'r', default: 'l'}
138
138
 
139
139
  def convert_table(el, opts)
140
- opts[:alignment] = el.options[:alignment].map {|a| TABLE_CELL_ALIGNMENT[a]}
140
+ opts[:alignment] = el.options[:alignment].map {|a| TABLE_CELL_ALIGNMENT[a] }
141
141
  table_options = ["box"]
142
142
  table_options << "center" if el.attr['class'] =~ /\bcenter\b/
143
- opts[:result] << macro("TS") << "#{table_options.join(" ")} ;\n"
143
+ opts[:result] << macro("TS") << "#{table_options.join(' ')} ;\n"
144
144
  inner(el, opts)
145
145
  opts[:result] << macro("TE") << macro("sp")
146
146
  end
147
147
 
148
148
  def convert_thead(el, opts)
149
- opts[:result] << opts[:alignment].map {|a| "#{a}b"}.join(' ') << " .\n"
149
+ opts[:result] << opts[:alignment].map {|a| "#{a}b" }.join(' ') << " .\n"
150
150
  inner(el, opts)
151
151
  opts[:result] << "=\n"
152
152
  end
@@ -169,7 +169,7 @@ module Kramdown
169
169
 
170
170
  def convert_td(el, opts)
171
171
  result = opts[:result]
172
- opts[:result] = ''
172
+ opts[:result] = +''
173
173
  inner(el, opts)
174
174
  if opts[:result] =~ /\n/
175
175
  warning("Table cells using links are not supported")
@@ -186,8 +186,7 @@ module Kramdown
186
186
  def convert_xml_comment(el, opts)
187
187
  newline(opts[:result]) << ".\"#{escape(el.value, true).rstrip.gsub(/\n/, "\n.\"")}\n"
188
188
  end
189
- alias :convert_comment :convert_xml_comment
190
-
189
+ alias convert_comment convert_xml_comment
191
190
 
192
191
  def convert_a(el, opts)
193
192
  if el.children.size == 1 && el.children[0].type == :text &&
@@ -203,7 +202,7 @@ module Kramdown
203
202
  end
204
203
  end
205
204
 
206
- def convert_img(el, opts)
205
+ def convert_img(_el, _opts)
207
206
  warning("Images are not supported")
208
207
  end
209
208
 
@@ -223,7 +222,7 @@ module Kramdown
223
222
  opts[:result] << "\\fB#{escape(el.value)}\\fP"
224
223
  end
225
224
 
226
- def convert_br(el, opts)
225
+ def convert_br(_el, opts)
227
226
  newline(opts[:result]) << macro("br")
228
227
  end
229
228
 
@@ -247,11 +246,9 @@ module Kramdown
247
246
  warning("Raw content is not supported")
248
247
  end
249
248
 
250
-
251
-
252
249
  def convert_text(el, opts)
253
250
  text = escape(el.value)
254
- text.lstrip! if opts[:result][-1] == ?\n
251
+ text.lstrip! if opts[:result][-1] == "\n"
255
252
  opts[:result] << text
256
253
  end
257
254
 
@@ -264,8 +261,8 @@ module Kramdown
264
261
  end
265
262
 
266
263
  TYPOGRAPHIC_SYMS_MAP = {
267
- :mdash => '\(em', :ndash => '\(em', :hellip => '\.\.\.',
268
- :laquo_space => '\[Fo]', :raquo_space => '\[Fc]', :laquo => '\[Fo]', :raquo => '\[Fc]'
264
+ mdash: '\(em', ndash: '\(em', hellip: '\.\.\.',
265
+ laquo_space: '\[Fo]', raquo_space: '\[Fc]', laquo: '\[Fo]', raquo: '\[Fc]'
269
266
  }
270
267
 
271
268
  def convert_typographic_sym(el, opts)
@@ -277,7 +274,7 @@ module Kramdown
277
274
  end
278
275
 
279
276
  def newline(text)
280
- text << "\n" unless text[-1] == ?\n
277
+ text << "\n" unless text[-1] == "\n"
281
278
  text
282
279
  end
283
280
 
@@ -289,7 +286,7 @@ module Kramdown
289
286
  text = (preserve_whitespace ? text.dup : text.gsub(/\s+/, ' '))
290
287
  text.gsub!('\\', "\\e")
291
288
  text.gsub!(/^\./, '\\\\&.')
292
- text.gsub!(/[.'-]/) {|m| "\\#{m}"}
289
+ text.gsub!(/[.'-]/) {|m| "\\#{m}" }
293
290
  text
294
291
  end
295
292
 
@@ -1,7 +1,7 @@
1
- # -*- coding: utf-8 -*-
1
+ # -*- coding: utf-8; frozen_string_literal: true -*-
2
2
  #
3
3
  #--
4
- # Copyright (C) 2009-2016 Thomas Leitner <t_leitner@gmx.at>
4
+ # Copyright (C) 2009-2019 Thomas Leitner <t_leitner@gmx.at>
5
5
  #
6
6
  # This file is part of kramdown which is licensed under the MIT.
7
7
  #++
@@ -17,17 +17,17 @@ module Kramdown::Converter::MathEngine
17
17
 
18
18
  def self.call(converter, el, opts)
19
19
  type = el.options[:category]
20
- text = (el.value =~ /<|&/ ? "% <![CDATA[\n#{el.value} %]]>" : el.value)
20
+ text = (el.value =~ /<|&/ ? "% <![CDATA[\n#{el.value} %]]>" : el.value).dup
21
21
  text.gsub!(/<\/?script>?/, '')
22
22
 
23
- preview = preview_string(converter, el, opts)
23
+ preview = preview_string(converter, el, opts).dup
24
24
 
25
- attr = {:type => "math/tex#{type == :block ? '; mode=display' : ''}"}
26
- if type == :block
27
- preview << converter.format_as_block_html('script', attr, text, opts[:indent])
28
- else
29
- preview << converter.format_as_span_html('script', attr, text)
30
- end
25
+ attr = {type: "math/tex#{type == :block ? '; mode=display' : ''}"}
26
+ preview << if type == :block
27
+ converter.format_as_block_html('script', attr, text, opts[:indent])
28
+ else
29
+ converter.format_as_span_html('script', attr, text)
30
+ end
31
31
  end
32
32
 
33
33
  def self.preview_string(converter, el, opts)
@@ -1,7 +1,7 @@
1
- # -*- coding: utf-8 -*-
1
+ # -*- coding: utf-8; frozen_string_literal: true -*-
2
2
  #
3
3
  #--
4
- # Copyright (C) 2009-2016 Thomas Leitner <t_leitner@gmx.at>
4
+ # Copyright (C) 2009-2019 Thomas Leitner <t_leitner@gmx.at>
5
5
  #
6
6
  # This file is part of kramdown which is licensed under the MIT.
7
7
  #++
@@ -1,7 +1,7 @@
1
- # -*- coding: utf-8 -*-
1
+ # -*- coding: utf-8; frozen_string_literal: true -*-
2
2
  #
3
3
  #--
4
- # Copyright (C) 2009-2016 Thomas Leitner <t_leitner@gmx.at>
4
+ # Copyright (C) 2009-2019 Thomas Leitner <t_leitner@gmx.at>
5
5
  #
6
6
  # This file is part of kramdown which is licensed under the MIT.
7
7
  #++
@@ -1,7 +1,7 @@
1
- # -*- coding: utf-8 -*-
1
+ # -*- coding: utf-8; frozen_string_literal: true -*-
2
2
  #
3
3
  #--
4
- # Copyright (C) 2009-2016 Thomas Leitner <t_leitner@gmx.at>
4
+ # Copyright (C) 2009-2019 Thomas Leitner <t_leitner@gmx.at>
5
5
  #
6
6
  # This file is part of kramdown which is licensed under the MIT.
7
7
  #++
@@ -1,7 +1,7 @@
1
- # -*- coding: utf-8 -*-
1
+ # -*- coding: utf-8; frozen_string_literal: true -*-
2
2
  #
3
3
  #--
4
- # Copyright (C) 2009-2016 Thomas Leitner <t_leitner@gmx.at>
4
+ # Copyright (C) 2009-2019 Thomas Leitner <t_leitner@gmx.at>
5
5
  #
6
6
  # This file is part of kramdown which is licensed under the MIT.
7
7
  #++
@@ -18,14 +18,14 @@ module Kramdown::Converter::SyntaxHighlighter
18
18
  # Highlighting via Rouge is available if this constant is +true+.
19
19
  AVAILABLE = true
20
20
  rescue LoadError, SyntaxError
21
- AVAILABLE = false # :nodoc:
21
+ AVAILABLE = false # :nodoc:
22
22
  end
23
23
 
24
24
  def self.call(converter, text, lang, type, call_opts)
25
25
  opts = options(converter, type)
26
26
  call_opts[:default_lang] = opts[:default_lang]
27
27
  lexer = ::Rouge::Lexer.find_fancy(lang || opts[:default_lang], text)
28
- return nil if opts[:disable] || !lexer
28
+ return nil if opts[:disable] || !lexer || lexer.tag == "plaintext"
29
29
  opts[:css_class] ||= 'highlight' # For backward compatibility when using Rouge 2.0
30
30
  formatter = formatter_class(opts).new(opts)
31
31
  formatter.format(lexer.lex(text))
@@ -50,7 +50,7 @@ module Kramdown::Converter::SyntaxHighlighter
50
50
  end
51
51
  end
52
52
 
53
- cache[:span] = opts.merge(span_opts).update(:wrap => false)
53
+ cache[:span] = opts.merge(span_opts).update(wrap: false)
54
54
  cache[:block] = opts.merge(block_opts)
55
55
  end
56
56
 
@@ -1,7 +1,7 @@
1
- # -*- coding: utf-8 -*-
1
+ # -*- coding: utf-8; frozen_string_literal: true -*-
2
2
  #
3
3
  #--
4
- # Copyright (C) 2009-2016 Thomas Leitner <t_leitner@gmx.at>
4
+ # Copyright (C) 2009-2019 Thomas Leitner <t_leitner@gmx.at>
5
5
  #
6
6
  # This file is part of kramdown which is licensed under the MIT.
7
7
  #++
@@ -37,7 +37,7 @@ module Kramdown
37
37
  attr['id'] = generate_id(el.options[:raw_text]) if @options[:auto_ids] && !attr['id']
38
38
  add_to_toc(el, attr['id']) if attr['id']
39
39
  else
40
- el.children.each {|child| convert(child)}
40
+ el.children.each {|child| convert(child) }
41
41
  end
42
42
  @toc
43
43
  end
@@ -45,10 +45,10 @@ module Kramdown
45
45
  private
46
46
 
47
47
  def add_to_toc(el, id)
48
- toc_element = Element.new(:toc, el, :id => id)
48
+ toc_element = Element.new(:toc, el, id: id)
49
49
 
50
50
  success = false
51
- while !success
51
+ until success
52
52
  if @stack.empty?
53
53
  @toc.children << toc_element
54
54
  @stack << toc_element
@@ -1,7 +1,7 @@
1
- # -*- coding: utf-8 -*-
1
+ # -*- coding: utf-8; frozen_string_literal: true -*-
2
2
  #
3
3
  #--
4
- # Copyright (C) 2009-2016 Thomas Leitner <t_leitner@gmx.at>
4
+ # Copyright (C) 2009-2019 Thomas Leitner <t_leitner@gmx.at>
5
5
  #
6
6
  # This file is part of kramdown which is licensed under the MIT.
7
7
  #++
@@ -47,16 +47,15 @@ module Kramdown
47
47
 
48
48
  # Return the data directory for kramdown.
49
49
  def self.data_dir
50
- unless defined?(@@data_dir)
50
+ unless defined?(@data_dir)
51
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")) if !File.exist?(@@data_dir)
54
- raise "kramdown data directory not found! This is a bug, please report it!" unless File.directory?(@@data_dir)
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
55
  end
56
- @@data_dir
56
+ @data_dir
57
57
  end
58
58
 
59
-
60
59
  # The main interface to kramdown.
61
60
  #
62
61
  # This class provides a one-stop-shop for using kramdown to convert text into various output
@@ -84,7 +83,6 @@ module Kramdown
84
83
  # ::new) and the conversion phase.
85
84
  attr_reader :warnings
86
85
 
87
-
88
86
  # Create a new Kramdown document from the string +source+ and use the provided +options+. The
89
87
  # options that can be used are defined in the Options module.
90
88
  #
@@ -103,7 +101,8 @@ module Kramdown
103
101
  if Parser.const_defined?(parser)
104
102
  @root, @warnings = Parser.const_get(parser).parse(source, @options)
105
103
  else
106
- raise Kramdown::Error.new("kramdown has no parser to handle the specified input format: #{@options[:input]}")
104
+ raise Kramdown::Error, "kramdown has no parser to handle the specified " \
105
+ "input format: #{@options[:input]}"
107
106
  end
108
107
  end
109
108
 
@@ -138,4 +137,3 @@ module Kramdown
138
137
  end
139
138
 
140
139
  end
141
-
@@ -1,7 +1,7 @@
1
- # -*- coding: utf-8 -*-
1
+ # -*- coding: utf-8; frozen_string_literal: true -*-
2
2
  #
3
3
  #--
4
- # Copyright (C) 2009-2016 Thomas Leitner <t_leitner@gmx.at>
4
+ # Copyright (C) 2009-2019 Thomas Leitner <t_leitner@gmx.at>
5
5
  #
6
6
  # This file is part of kramdown which is licensed under the MIT.
7
7
  #++
@@ -482,17 +482,16 @@ module Kramdown
482
482
  # The child elements of this element.
483
483
  attr_accessor :children
484
484
 
485
-
486
485
  # Create a new Element object of type +type+. The optional parameters +value+, +attr+ and
487
486
  # +options+ can also be set in this constructor for convenience.
488
487
  def initialize(type, value = nil, attr = nil, options = nil)
489
- @type, @value, @attr, @options = type, value, (Utils::OrderedHash.new.merge!(attr) if attr), options
488
+ @type, @value, @attr, @options = type, value, attr, options
490
489
  @children = []
491
490
  end
492
491
 
493
- # The attributes of the element. Uses an Utils::OrderedHash to retain the insertion order.
492
+ # The attributes of the element.
494
493
  def attr
495
- @attr ||= Utils::OrderedHash.new
494
+ @attr ||= {}
496
495
  end
497
496
 
498
497
  # The options hash for the element. It is used for storing arbitray options.
@@ -501,13 +500,16 @@ module Kramdown
501
500
  end
502
501
 
503
502
  def inspect #:nodoc:
504
- "<kd:#{@type}#{@value.nil? ? '' : ' ' + @value.inspect} #{@attr.inspect}#{options.empty? ? '' : ' ' + @options.inspect}#{@children.empty? ? '' : ' ' + @children.inspect}>"
503
+ "<kd:#{@type}#{@value.nil? ? '' : ' ' + @value.inspect} " \
504
+ "#{@attr.inspect}#{options.empty? ? '' : ' ' + @options.inspect} " \
505
+ "#{@children.empty? ? '' : ' ' + @children.inspect}>"
505
506
  end
506
507
 
507
508
  CATEGORY = {} # :nodoc:
508
- [:blank, :p, :header, :blockquote, :codeblock, :ul, :ol, :li, :dl, :dt, :dd, :table, :td, :hr].each {|b| CATEGORY[b] = :block}
509
+ [:blank, :p, :header, :blockquote, :codeblock, :ul, :ol, :li, :dl, :dt, :dd,
510
+ :table, :td, :hr].each {|b| CATEGORY[b] = :block }
509
511
  [:text, :a, :br, :img, :codespan, :footnote, :em, :strong, :entity, :typographic_sym,
510
- :smart_quote, :abbreviation].each {|b| CATEGORY[b] = :span}
512
+ :smart_quote, :abbreviation].each {|b| CATEGORY[b] = :span }
511
513
 
512
514
  # Return the category of +el+ which can be :block, :span or +nil+.
513
515
  #
@@ -1,7 +1,7 @@
1
- # -*- coding: utf-8 -*-
1
+ # -*- coding: utf-8; frozen_string_literal: true -*-
2
2
  #
3
3
  #--
4
- # Copyright (C) 2009-2016 Thomas Leitner <t_leitner@gmx.at>
4
+ # Copyright (C) 2009-2019 Thomas Leitner <t_leitner@gmx.at>
5
5
  #
6
6
  # This file is part of kramdown which is licensed under the MIT.
7
7
  #++
@@ -1,7 +1,7 @@
1
- # -*- coding: utf-8 -*-
1
+ # -*- coding: utf-8; frozen_string_literal: true -*-
2
2
  #
3
3
  #--
4
- # Copyright (C) 2009-2016 Thomas Leitner <t_leitner@gmx.at>
4
+ # Copyright (C) 2009-2019 Thomas Leitner <t_leitner@gmx.at>
5
5
  #
6
6
  # This file is part of kramdown which is licensed under the MIT.
7
7
  #++
@@ -49,8 +49,8 @@ module Kramdown
49
49
  # a value given as string and as the opaque type.
50
50
  def self.define(name, type, default, desc, &block)
51
51
  name = name.to_sym
52
- raise ArgumentError, "Option name #{name} is already used" if @options.has_key?(name)
53
- raise ArgumentError, "Invalid option type #{type} specified" if !ALLOWED_TYPES.include?(type)
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)
54
54
  raise ArgumentError, "Invalid type for default value" if !(type === default) && !default.nil?
55
55
  raise ArgumentError, "Missing validator block" if type == Object && block.nil?
56
56
  @options[name] = Definition.new(name, type, default, desc, block)
@@ -63,13 +63,13 @@ module Kramdown
63
63
 
64
64
  # Return +true+ if an option called +name+ is defined.
65
65
  def self.defined?(name)
66
- @options.has_key?(name.to_sym)
66
+ @options.key?(name.to_sym)
67
67
  end
68
68
 
69
69
  # Return a Hash with the default values for all options.
70
70
  def self.defaults
71
71
  temp = {}
72
- @options.each {|n, o| temp[o.name] = o.default}
72
+ @options.each {|_n, o| temp[o.name] = o.default }
73
73
  temp
74
74
  end
75
75
 
@@ -77,9 +77,9 @@ module Kramdown
77
77
  # names are considered and their value is run through the #parse method.
78
78
  def self.merge(hash)
79
79
  temp = defaults
80
- hash.each do |k,v|
80
+ hash.each do |k, v|
81
81
  k = k.to_sym
82
- @options.has_key?(k) ? temp[k] = parse(k, v) : temp[k] = v
82
+ temp[k] = @options.key?(k) ? parse(k, v) : v
83
83
  end
84
84
  temp
85
85
  end
@@ -91,8 +91,8 @@ module Kramdown
91
91
  # String and then to the correct type.
92
92
  def self.parse(name, data)
93
93
  name = name.to_sym
94
- raise ArgumentError, "No option named #{name} defined" if !@options.has_key?(name)
95
- if !(@options[name].type === data)
94
+ raise ArgumentError, "No option named #{name} defined" unless @options.key?(name)
95
+ unless @options[name].type === data
96
96
  data = data.to_s
97
97
  data = if @options[name].type == String
98
98
  data
@@ -117,7 +117,7 @@ module Kramdown
117
117
  # - An empty value or a value equal to "nil" results in +nil+.
118
118
  def self.str_to_sym(data)
119
119
  data = data.strip
120
- data = data[1..-1] if data[0] == ?:
120
+ data = data[1..-1] if data[0] == ':'
121
121
  (data.empty? || data == 'nil' ? nil : data.to_sym)
122
122
  end
123
123
 
@@ -154,12 +154,12 @@ module Kramdown
154
154
  def self.simple_hash_validator(val, name)
155
155
  if String === val
156
156
  begin
157
- val = YAML.load(val)
157
+ val = YAML.safe_load(val)
158
158
  rescue RuntimeError, ArgumentError, SyntaxError
159
159
  raise Kramdown::Error, "Invalid YAML value for option #{name}"
160
160
  end
161
161
  end
162
- raise Kramdown::Error, "Invalid type #{val.class} for option #{name}" if !(Hash === val)
162
+ raise Kramdown::Error, "Invalid type #{val.class} for option #{name}" unless Hash === val
163
163
  val
164
164
  end
165
165
 
@@ -170,134 +170,134 @@ module Kramdown
170
170
  # parsers/converters.
171
171
  # ----------------------------
172
172
 
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.
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.
176
176
 
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.
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.
182
182
 
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.
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.
191
191
 
192
- kramdown provides a default template named 'document' for each converter.
192
+ kramdown provides a default template named 'document' for each converter.
193
193
 
194
- Default: ''
195
- Used by: all converters
196
- EOF
194
+ Default: ''
195
+ Used by: all converters
196
+ EOF
197
197
 
198
- define(:auto_ids, Boolean, true, <<EOF)
199
- Use automatic header ID generation
198
+ define(:auto_ids, Boolean, true, <<~EOF)
199
+ Use automatic header ID generation
200
200
 
201
- If this option is `true`, ID values for all headers are automatically
202
- 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.
203
203
 
204
- Default: true
205
- Used by: HTML/Latex converter
206
- EOF
204
+ Default: true
205
+ Used by: HTML/Latex converter
206
+ EOF
207
207
 
208
- define(:auto_id_stripping, Boolean, false, <<EOF)
209
- Strip all formatting from header text for automatic ID generation
208
+ define(:auto_id_stripping, Boolean, false, <<~EOF)
209
+ Strip all formatting from header text for automatic ID generation
210
210
 
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).
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).
214
214
 
215
- This option will be removed in version 2.0 because this will be the
216
- default then.
215
+ This option will be removed in version 2.0 because this will be the
216
+ default then.
217
217
 
218
- Default: false
219
- Used by: kramdown parser
220
- EOF
218
+ Default: false
219
+ Used by: kramdown parser
220
+ EOF
221
221
 
222
- define(:auto_id_prefix, String, '', <<EOF)
223
- Prefix used for automatically generated header IDs
222
+ define(:auto_id_prefix, String, '', <<~EOF)
223
+ Prefix used for automatically generated header IDs
224
224
 
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!
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!
229
229
 
230
- Default: ''
231
- Used by: HTML/Latex converter
232
- EOF
230
+ Default: ''
231
+ Used by: HTML/Latex converter
232
+ EOF
233
233
 
234
- define(:transliterated_header_ids, Boolean, false, <<EOF)
235
- Transliterate the header text before generating the ID
234
+ define(:transliterated_header_ids, Boolean, false, <<~EOF)
235
+ Transliterate the header text before generating the ID
236
236
 
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.
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.
241
241
 
242
- The stringex library needs to be installed for this feature to work!
242
+ The stringex library needs to be installed for this feature to work!
243
243
 
244
- Default: false
245
- Used by: HTML/Latex converter
246
- EOF
244
+ Default: false
245
+ Used by: HTML/Latex converter
246
+ EOF
247
247
 
248
- define(:parse_block_html, Boolean, false, <<EOF)
249
- Process kramdown syntax in block HTML tags
248
+ define(:parse_block_html, Boolean, false, <<~EOF)
249
+ Process kramdown syntax in block HTML tags
250
250
 
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.
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.
255
255
 
256
- Default: false
257
- Used by: kramdown parser
258
- EOF
256
+ Default: false
257
+ Used by: kramdown parser
258
+ EOF
259
259
 
260
- define(:parse_span_html, Boolean, true, <<EOF)
261
- Process kramdown syntax in span HTML tags
260
+ define(:parse_span_html, Boolean, true, <<~EOF)
261
+ Process kramdown syntax in span HTML tags
262
262
 
263
- If this option is `true`, the kramdown parser processes the content of
264
- span HTML tags as text containing span-level elements.
263
+ If this option is `true`, the kramdown parser processes the content of
264
+ span HTML tags as text containing span-level elements.
265
265
 
266
- Default: true
267
- Used by: kramdown parser
268
- EOF
266
+ Default: true
267
+ Used by: kramdown parser
268
+ EOF
269
269
 
270
- define(:html_to_native, Boolean, false, <<EOF)
271
- Convert HTML elements to native elements
270
+ define(:html_to_native, Boolean, false, <<~EOF)
271
+ Convert HTML elements to native elements
272
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.
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
278
 
279
- This is useful for converters that cannot deal with HTML elements.
279
+ This is useful for converters that cannot deal with HTML elements.
280
280
 
281
- Default: false
282
- Used by: kramdown parser
283
- EOF
281
+ Default: false
282
+ Used by: kramdown parser
283
+ EOF
284
284
 
285
- define(:link_defs, Object, {}, <<EOF) do |val|
286
- Pre-defines link definitions
285
+ define(:link_defs, Object, {}, <<~EOF) do |val|
286
+ Pre-defines link definitions
287
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.
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
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.
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
294
 
295
- Default: {}
296
- Used by: kramdown parser
297
- EOF
295
+ Default: {}
296
+ Used by: kramdown parser
297
+ EOF
298
298
  val = simple_hash_validator(val, :link_defs)
299
- val.each do |k,v|
300
- if !(Array === v) || v.size > 2 || v.size < 1
299
+ val.each do |_k, v|
300
+ if !(Array === v) || v.size > 2 || v.empty?
301
301
  raise Kramdown::Error, "Invalid structure for hash value of option #{name}"
302
302
  end
303
303
  v << nil if v.size == 1
@@ -305,198 +305,118 @@ EOF
305
305
  val
306
306
  end
307
307
 
308
- define(:footnote_nr, Integer, 1, <<EOF)
309
- The number of the first footnote
308
+ define(:footnote_nr, Integer, 1, <<~EOF)
309
+ The number of the first footnote
310
310
 
311
- This option can be used to specify the number that is used for the first
312
- footnote.
311
+ This option can be used to specify the number that is used for the first
312
+ footnote.
313
313
 
314
- Default: 1
315
- Used by: HTML converter
316
- EOF
314
+ Default: 1
315
+ Used by: HTML converter
316
+ EOF
317
317
 
318
- define(:enable_coderay, Boolean, true, <<EOF)
319
- Use coderay for syntax highlighting
318
+ define(:entity_output, Symbol, :as_char, <<~EOF)
319
+ Defines how entities are output
320
320
 
321
- If this option is `true`, coderay is used by the HTML converter for
322
- 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).
323
326
 
324
- Default: true
325
- Used by: HTML converter
326
- EOF
327
+ Default: :as_char
328
+ Used by: HTML converter, kramdown converter
329
+ EOF
327
330
 
328
- define(:coderay_wrap, Symbol, :div, <<EOF)
329
- Defines how the highlighted code should be wrapped
331
+ define(:toc_levels, Object, (1..6).to_a, <<~EOF) do |val|
332
+ Defines the levels that are used for the table of contents
330
333
 
331
- The possible values are :span, :div or nil.
334
+ The individual levels can be specified by separating them with commas
335
+ (e.g. 1,2,3) or by using the range syntax (e.g. 1..3). Only the
336
+ specified levels are used for the table of contents.
332
337
 
333
- Default: :div
334
- Used by: HTML converter
335
- EOF
336
-
337
- define(:coderay_line_numbers, Symbol, :inline, <<EOF)
338
- Defines how and if line numbers should be shown
339
-
340
- The possible values are :table, :inline or nil. If this option is
341
- nil, no line numbers are shown.
342
-
343
- Default: :inline
344
- Used by: HTML converter
345
- EOF
346
-
347
- define(:coderay_line_number_start, Integer, 1, <<EOF)
348
- The start value for the line numbers
349
-
350
- Default: 1
351
- Used by: HTML converter
352
- EOF
353
-
354
- define(:coderay_tab_width, Integer, 8, <<EOF)
355
- The tab width used in highlighted code
356
-
357
- Used by: HTML converter
358
- EOF
359
-
360
- define(:coderay_bold_every, Object, 10, <<EOF) do |val|
361
- Defines how often a line number should be made bold
362
-
363
- Can either be an integer or false (to turn off bold line numbers
364
- completely).
365
-
366
- Default: 10
367
- Used by: HTML converter
368
- EOF
369
- if val == false || val.to_s == 'false'
370
- false
371
- else
372
- Integer(val.to_s) rescue raise Kramdown::Error, "Invalid value for option 'coderay_bold_every'"
373
- end
374
- end
375
-
376
- define(:coderay_css, Symbol, :style, <<EOF)
377
- Defines how the highlighted code gets styled
378
-
379
- Possible values are :class (CSS classes are applied to the code
380
- elements, one must supply the needed CSS file) or :style (default CSS
381
- styles are directly applied to the code elements).
382
-
383
- Default: style
384
- Used by: HTML converter
385
- EOF
386
-
387
- define(:coderay_default_lang, Symbol, nil, <<EOF)
388
- Sets the default language for highlighting code blocks
389
-
390
- If no language is set for a code block, the default language is used
391
- instead. The value has to be one of the languages supported by coderay
392
- or nil if no default language should be used.
393
-
394
- Default: nil
395
- Used by: HTML converter
396
- EOF
397
-
398
- define(:entity_output, Symbol, :as_char, <<EOF)
399
- Defines how entities are output
400
-
401
- The possible values are :as_input (entities are output in the same
402
- form as found in the input), :numeric (entities are output in numeric
403
- form), :symbolic (entities are output in symbolic form if possible) or
404
- :as_char (entities are output as characters if possible, only available
405
- on Ruby 1.9).
406
-
407
- Default: :as_char
408
- Used by: HTML converter, kramdown converter
409
- EOF
410
-
411
- define(:toc_levels, Object, (1..6).to_a, <<EOF) do |val|
412
- Defines the levels that are used for the table of contents
413
-
414
- The individual levels can be specified by separating them with commas
415
- (e.g. 1,2,3) or by using the range syntax (e.g. 1..3). Only the
416
- specified levels are used for the table of contents.
417
-
418
- Default: 1..6
419
- Used by: HTML/Latex converter
420
- EOF
338
+ Default: 1..6
339
+ Used by: HTML/Latex converter
340
+ EOF
421
341
  case val
422
342
  when String
423
343
  if val =~ /^(\d)\.\.(\d)$/
424
344
  val = Range.new($1.to_i, $2.to_i).to_a
425
345
  elsif val =~ /^\d(?:,\d)*$/
426
- val = val.split(/,/).map {|s| s.to_i}.uniq
346
+ val = val.split(/,/).map(&:to_i).uniq
427
347
  else
428
348
  raise Kramdown::Error, "Invalid syntax for option toc_levels"
429
349
  end
430
350
  when Array, Range
431
- val = val.map {|s| s.to_i}.uniq
351
+ val = val.map(&:to_i).uniq
432
352
  else
433
353
  raise Kramdown::Error, "Invalid type #{val.class} for option toc_levels"
434
354
  end
435
- if val.any? {|i| !(1..6).include?(i)}
355
+ if val.any? {|i| !(1..6).cover?(i) }
436
356
  raise Kramdown::Error, "Level numbers for option toc_levels have to be integers from 1 to 6"
437
357
  end
438
358
  val
439
359
  end
440
360
 
441
- define(:line_width, Integer, 72, <<EOF)
442
- Defines the line width to be used when outputting a document
361
+ define(:line_width, Integer, 72, <<~EOF)
362
+ Defines the line width to be used when outputting a document
443
363
 
444
- Default: 72
445
- Used by: kramdown converter
446
- EOF
364
+ Default: 72
365
+ Used by: kramdown converter
366
+ EOF
447
367
 
448
- define(:latex_headers, Object, %w{section subsection subsubsection paragraph subparagraph subparagraph}, <<EOF) do |val|
449
- Defines the LaTeX commands for different header levels
368
+ define(:latex_headers, Object, %w[section subsection subsubsection paragraph subparagraph subparagraph], <<~EOF) do |val|
369
+ Defines the LaTeX commands for different header levels
450
370
 
451
- The commands for the header levels one to six can be specified by
452
- separating them with commas.
371
+ The commands for the header levels one to six can be specified by
372
+ separating them with commas.
453
373
 
454
- Default: section,subsection,subsubsection,paragraph,subparagraph,subparagraph
455
- Used by: Latex converter
456
- EOF
374
+ Default: section,subsection,subsubsection,paragraph,subparagraph,subparagraph
375
+ Used by: Latex converter
376
+ EOF
457
377
  simple_array_validator(val, :latex_headers, 6)
458
378
  end
459
379
 
460
- define(:smart_quotes, Object, %w{lsquo rsquo ldquo rdquo}, <<EOF) do |val|
461
- Defines the HTML entity names or code points for smart quote output
380
+ define(:smart_quotes, Object, %w[lsquo rsquo ldquo rdquo], <<~EOF) do |val|
381
+ Defines the HTML entity names or code points for smart quote output
462
382
 
463
- The entities identified by entity name or code point that should be
464
- used for, in order, a left single quote, a right single quote, a left
465
- double and a right double quote are specified by separating them with
466
- commas.
383
+ The entities identified by entity name or code point that should be
384
+ used for, in order, a left single quote, a right single quote, a left
385
+ double and a right double quote are specified by separating them with
386
+ commas.
467
387
 
468
- Default: lsquo,rsquo,ldquo,rdquo
469
- Used by: HTML/Latex converter
470
- EOF
388
+ Default: lsquo,rsquo,ldquo,rdquo
389
+ Used by: HTML/Latex converter
390
+ EOF
471
391
  val = simple_array_validator(val, :smart_quotes, 4)
472
- val.map! {|v| Integer(v) rescue v}
392
+ val.map! {|v| Integer(v) rescue v }
473
393
  val
474
394
  end
475
395
 
476
- define(:typographic_symbols, Object, {}, <<EOF) do |val|
477
- Defines a mapping from typographical symbol to output characters
396
+ define(:typographic_symbols, Object, {}, <<~EOF) do |val|
397
+ Defines a mapping from typographical symbol to output characters
478
398
 
479
- Typographical symbols are normally output using their equivalent Unicode
480
- codepoint. However, sometimes one wants to change the output, mostly to
481
- fallback to a sequence of ASCII characters.
399
+ Typographical symbols are normally output using their equivalent Unicode
400
+ codepoint. However, sometimes one wants to change the output, mostly to
401
+ fallback to a sequence of ASCII characters.
482
402
 
483
- This option allows this by specifying a mapping from typographical
484
- symbol to its output string. For example, the mapping {hellip: ...} would
485
- output the standard ASCII representation of an ellipsis.
403
+ This option allows this by specifying a mapping from typographical
404
+ symbol to its output string. For example, the mapping {hellip: ...} would
405
+ output the standard ASCII representation of an ellipsis.
486
406
 
487
- The available typographical symbol names are:
407
+ The available typographical symbol names are:
488
408
 
489
- * hellip: ellipsis
490
- * mdash: em-dash
491
- * ndash: en-dash
492
- * laquo: left guillemet
493
- * raquo: right guillemet
494
- * laquo_space: left guillemet followed by a space
495
- * raquo_space: right guillemet preceeded by a space
409
+ * hellip: ellipsis
410
+ * mdash: em-dash
411
+ * ndash: en-dash
412
+ * laquo: left guillemet
413
+ * raquo: right guillemet
414
+ * laquo_space: left guillemet followed by a space
415
+ * raquo_space: right guillemet preceeded by a space
496
416
 
497
- Default: {}
498
- Used by: HTML/Latex converter
499
- EOF
417
+ Default: {}
418
+ Used by: HTML/Latex converter
419
+ EOF
500
420
  val = simple_hash_validator(val, :typographic_symbols)
501
421
  val.keys.each do |k|
502
422
  val[k.kind_of?(String) ? str_to_sym(k) : k] = val.delete(k).to_s
@@ -504,73 +424,63 @@ EOF
504
424
  val
505
425
  end
506
426
 
507
- define(:remove_block_html_tags, Boolean, true, <<EOF)
508
- Remove block HTML tags
427
+ define(:remove_block_html_tags, Boolean, true, <<~EOF)
428
+ Remove block HTML tags
509
429
 
510
- If this option is `true`, the RemoveHtmlTags converter removes
511
- block HTML tags.
430
+ If this option is `true`, the RemoveHtmlTags converter removes
431
+ block HTML tags.
512
432
 
513
- Default: true
514
- Used by: RemoveHtmlTags converter
515
- EOF
433
+ Default: true
434
+ Used by: RemoveHtmlTags converter
435
+ EOF
516
436
 
517
- define(:remove_span_html_tags, Boolean, false, <<EOF)
518
- Remove span HTML tags
437
+ define(:remove_span_html_tags, Boolean, false, <<~EOF)
438
+ Remove span HTML tags
519
439
 
520
- If this option is `true`, the RemoveHtmlTags converter removes
521
- span HTML tags.
440
+ If this option is `true`, the RemoveHtmlTags converter removes
441
+ span HTML tags.
522
442
 
523
- Default: false
524
- Used by: RemoveHtmlTags converter
525
- EOF
443
+ Default: false
444
+ Used by: RemoveHtmlTags converter
445
+ EOF
526
446
 
527
- define(:header_offset, Integer, 0, <<EOF)
528
- Sets the output offset for headers
447
+ define(:header_offset, Integer, 0, <<~EOF)
448
+ Sets the output offset for headers
529
449
 
530
- If this option is c (may also be negative) then a header with level n
531
- will be output as a header with level c+n. If c+n is lower than 1,
532
- level 1 will be used. If c+n is greater than 6, level 6 will be used.
450
+ If this option is c (may also be negative) then a header with level n
451
+ will be output as a header with level c+n. If c+n is lower than 1,
452
+ level 1 will be used. If c+n is greater than 6, level 6 will be used.
533
453
 
534
- Default: 0
535
- Used by: HTML converter, Kramdown converter, Latex converter
536
- EOF
454
+ Default: 0
455
+ Used by: HTML converter, Kramdown converter, Latex converter
456
+ EOF
537
457
 
538
- define(:hard_wrap, Boolean, true, <<EOF)
539
- Interprets line breaks literally
458
+ define(:syntax_highlighter, Symbol, :rouge, <<~EOF)
459
+ Set the syntax highlighter
540
460
 
541
- Insert HTML `<br />` tags inside paragraphs where the original Markdown
542
- document had newlines (by default, Markdown ignores these newlines).
461
+ Specifies the syntax highlighter that should be used for highlighting
462
+ code blocks and spans. If this option is set to +nil+, no syntax
463
+ highlighting is done.
543
464
 
544
- Default: true
545
- Used by: GFM parser
546
- EOF
465
+ Options for the syntax highlighter can be set with the
466
+ syntax_highlighter_opts configuration option.
547
467
 
548
- define(:syntax_highlighter, Symbol, :coderay, <<EOF)
549
- Set the syntax highlighter
468
+ Default: rouge
469
+ Used by: HTML/Latex converter
470
+ EOF
550
471
 
551
- Specifies the syntax highlighter that should be used for highlighting
552
- code blocks and spans. If this option is set to +nil+, no syntax
553
- highlighting is done.
472
+ define(:syntax_highlighter_opts, Object, {}, <<~EOF) do |val|
473
+ Set the syntax highlighter options
554
474
 
555
- Options for the syntax highlighter can be set with the
556
- syntax_highlighter_opts configuration option.
475
+ Specifies options for the syntax highlighter set via the
476
+ syntax_highlighter configuration option.
557
477
 
558
- Default: coderay
559
- Used by: HTML/Latex converter
560
- EOF
478
+ The value needs to be a hash with key-value pairs that are understood by
479
+ the used syntax highlighter.
561
480
 
562
- define(:syntax_highlighter_opts, Object, {}, <<EOF) do |val|
563
- Set the syntax highlighter options
564
-
565
- Specifies options for the syntax highlighter set via the
566
- syntax_highlighter configuration option.
567
-
568
- The value needs to be a hash with key-value pairs that are understood by
569
- the used syntax highlighter.
570
-
571
- Default: {}
572
- Used by: HTML/Latex converter
573
- EOF
481
+ Default: {}
482
+ Used by: HTML/Latex converter
483
+ EOF
574
484
  val = simple_hash_validator(val, :syntax_highlighter_opts)
575
485
  val.keys.each do |k|
576
486
  val[k.kind_of?(String) ? str_to_sym(k) : k] = val.delete(k)
@@ -578,32 +488,32 @@ EOF
578
488
  val
579
489
  end
580
490
 
581
- define(:math_engine, Symbol, :mathjax, <<EOF)
582
- Set the math engine
491
+ define(:math_engine, Symbol, :mathjax, <<~EOF)
492
+ Set the math engine
583
493
 
584
- Specifies the math engine that should be used for converting math
585
- blocks/spans. If this option is set to +nil+, no math engine is used and
586
- the math blocks/spans are output as is.
494
+ Specifies the math engine that should be used for converting math
495
+ blocks/spans. If this option is set to +nil+, no math engine is used and
496
+ the math blocks/spans are output as is.
587
497
 
588
- Options for the selected math engine can be set with the
589
- math_engine_opts configuration option.
498
+ Options for the selected math engine can be set with the
499
+ math_engine_opts configuration option.
590
500
 
591
- Default: mathjax
592
- Used by: HTML converter
593
- EOF
501
+ Default: mathjax
502
+ Used by: HTML converter
503
+ EOF
594
504
 
595
- define(:math_engine_opts, Object, {}, <<EOF) do |val|
596
- Set the math engine options
505
+ define(:math_engine_opts, Object, {}, <<~EOF) do |val|
506
+ Set the math engine options
597
507
 
598
- Specifies options for the math engine set via the math_engine
599
- configuration option.
508
+ Specifies options for the math engine set via the math_engine
509
+ configuration option.
600
510
 
601
- The value needs to be a hash with key-value pairs that are understood by
602
- the used math engine.
511
+ The value needs to be a hash with key-value pairs that are understood by
512
+ the used math engine.
603
513
 
604
- Default: {}
605
- Used by: HTML converter
606
- EOF
514
+ Default: {}
515
+ Used by: HTML converter
516
+ EOF
607
517
  val = simple_hash_validator(val, :math_engine_opts)
608
518
  val.keys.each do |k|
609
519
  val[k.kind_of?(String) ? str_to_sym(k) : k] = val.delete(k)
@@ -611,70 +521,34 @@ EOF
611
521
  val
612
522
  end
613
523
 
614
- define(:footnote_backlink, String, '&#8617;', <<EOF)
615
- Defines the text that should be used for the footnote backlinks
616
-
617
- The footnote backlink is just text, so any special HTML characters will
618
- be escaped.
619
-
620
- If the footnote backlint text is an empty string, no footnote backlinks
621
- will be generated.
524
+ define(:footnote_backlink, String, '&#8617;', <<~EOF)
525
+ Defines the text that should be used for the footnote backlinks
622
526
 
623
- Default: '&8617;'
624
- Used by: HTML converter
625
- EOF
527
+ The footnote backlink is just text, so any special HTML characters will
528
+ be escaped.
626
529
 
627
- define(:footnote_backlink_inline, Boolean, false, <<EOF)
628
- Specifies whether the footnote backlink should always be inline
530
+ If the footnote backlint text is an empty string, no footnote backlinks
531
+ will be generated.
629
532
 
630
- With the default of false the footnote backlink is placed at the end of
631
- the last paragraph if there is one, or an extra paragraph with only the
632
- footnote backlink is created.
533
+ Default: '&8617;'
534
+ Used by: HTML converter
535
+ EOF
633
536
 
634
- Setting this option to true tries to place the footnote backlink in the
635
- last, possibly nested paragraph or header. If this fails (e.g. in the
636
- case of a table), an extra paragraph with only the footnote backlink is
637
- created.
537
+ define(:footnote_backlink_inline, Boolean, false, <<~EOF)
538
+ Specifies whether the footnote backlink should always be inline
638
539
 
639
- Default: false
640
- Used by: HTML converter
641
- EOF
540
+ With the default of false the footnote backlink is placed at the end of
541
+ the last paragraph if there is one, or an extra paragraph with only the
542
+ footnote backlink is created.
642
543
 
643
- define(:gfm_quirks, Object, [:paragraph_end], <<EOF) do |val|
644
- Enables a set of GFM specific quirks
544
+ Setting this option to true tries to place the footnote backlink in the
545
+ last, possibly nested paragraph or header. If this fails (e.g. in the
546
+ case of a table), an extra paragraph with only the footnote backlink is
547
+ created.
645
548
 
646
- The way how GFM is transformed on Github often differs from the way
647
- kramdown does things. Many of these differences are negligible but
648
- others are not.
649
-
650
- This option allows one to enable/disable certain GFM quirks, i.e. ways
651
- in which GFM parsing differs from kramdown parsing.
652
-
653
- The value has to be a list of quirk names that should be enabled,
654
- separated by commas. Possible names are:
655
-
656
- * paragraph_end
657
-
658
- Disables the kramdown restriction that at least one blank line has to
659
- be used after a paragraph before a new block element can be started.
660
-
661
- Note that if this quirk is used, lazy line wrapping does not fully
662
- work anymore!
663
-
664
- * no_auto_typographic
665
-
666
- Disables automatic conversion of some characters into their
667
- corresponding typographic symbols (like `--` to em-dash etc).
668
- This helps to achieve results closer to what GitHub Flavored
669
- Markdown produces.
670
-
671
- Default: paragraph_end
672
- Used by: GFM parser
673
- EOF
674
- val = simple_array_validator(val, :gfm_quirks)
675
- val.map! {|v| str_to_sym(v.to_s)}
676
- val
677
- end
549
+ Default: false
550
+ Used by: HTML converter
551
+ EOF
678
552
 
679
553
  end
680
554