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
  #++
@@ -22,9 +22,11 @@ module Kramdown
22
22
  start_line_number = @src.current_line_number
23
23
  @src.pos += @src.matched_size
24
24
 
25
- el = Element.new(:footnote_def, nil, nil, :location => start_line_number)
25
+ el = Element.new(:footnote_def, nil, nil, location: start_line_number)
26
26
  parse_blocks(el, @src[2].gsub(INDENT, ''))
27
- warning("Duplicate footnote name '#{@src[1]}' on line #{start_line_number} - overwriting") if @footnotes[@src[1]]
27
+ if @footnotes[@src[1]]
28
+ warning("Duplicate footnote name '#{@src[1]}' on line #{start_line_number} - overwriting")
29
+ end
28
30
  @tree.children << new_block_el(:eob, :footnote_def)
29
31
  (@footnotes[@src[1]] = {})[:content] = el
30
32
  @footnotes[@src[1]][:eob] = @tree.children.last
@@ -32,7 +34,6 @@ module Kramdown
32
34
  end
33
35
  define_parser(:footnote_definition, FOOTNOTE_DEFINITION_START)
34
36
 
35
-
36
37
  FOOTNOTE_MARKER_START = /\[\^(#{ALD_ID_NAME})\]/
37
38
 
38
39
  # Parse the footnote marker at the current location.
@@ -49,7 +50,7 @@ module Kramdown
49
50
  end
50
51
  fn_def[:marker] ||= []
51
52
  fn_def[:marker].push(Element.new(:footnote, fn_def[:content], fn_def[:attr],
52
- fn_def[:options].merge(:name => @src[1], :location => start_line_number)))
53
+ fn_def[:options].merge(name: @src[1], location: start_line_number)))
53
54
  @tree.children << fn_def[:marker].last
54
55
  else
55
56
  warning("Footnote definition for '#{@src[1]}' not found on line #{start_line_number}")
@@ -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,7 +17,7 @@ module Kramdown
17
17
 
18
18
  # Parse the Setext header at the current location.
19
19
  def parse_setext_header
20
- return false if !after_block_boundary?
20
+ return false unless after_block_boundary?
21
21
  text, id = parse_header_contents
22
22
  return false if text.empty?
23
23
  add_header(@src["level"] == '-' ? 2 : 1, text, id)
@@ -25,12 +25,11 @@ module Kramdown
25
25
  end
26
26
  define_parser(:setext_header, SETEXT_HEADER_START)
27
27
 
28
-
29
28
  ATX_HEADER_START = /^(?<level>\#{1,6})[\t ]*(?<contents>[^ \t].*)\n/
30
29
 
31
30
  # Parse the Atx header at the current location.
32
31
  def parse_atx_header
33
- return false if !after_block_boundary?
32
+ return false unless after_block_boundary?
34
33
  text, id = parse_header_contents
35
34
  text.sub!(/[\t ]#+\z/, '') && text.rstrip!
36
35
  return false if text.empty?
@@ -59,11 +58,12 @@ module Kramdown
59
58
  def add_header(level, text, id)
60
59
  start_line_number = @src.current_line_number
61
60
  @src.pos += @src.matched_size
62
- el = new_block_el(:header, nil, nil, :level => level, :raw_text => text, :location => start_line_number)
61
+ el = new_block_el(:header, nil, nil, level: level, raw_text: text, location: start_line_number)
63
62
  add_text(text, el)
64
63
  el.attr['id'] = id if id
65
64
  @tree.children << el
66
65
  end
66
+
67
67
  end
68
68
  end
69
69
  end
@@ -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,7 +17,7 @@ module Kramdown
17
17
  def parse_horizontal_rule
18
18
  start_line_number = @src.current_line_number
19
19
  @src.pos += @src.matched_size
20
- @tree.children << new_block_el(:hr, nil, nil, :location => start_line_number)
20
+ @tree.children << new_block_el(:hr, nil, nil, location: start_line_number)
21
21
  true
22
22
  end
23
23
  define_parser(:horizontal_rule, HR_START)
@@ -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
  #++
@@ -33,7 +33,7 @@ module Kramdown
33
33
  else
34
34
  :raw
35
35
  end
36
- if val = HTML_MARKDOWN_ATTR_MAP[el.attr.delete('markdown')]
36
+ if (val = HTML_MARKDOWN_ATTR_MAP[el.attr.delete('markdown')])
37
37
  content_model = (val == :default ? HTML_CONTENT_MODEL[el.value] : val)
38
38
  end
39
39
 
@@ -43,7 +43,7 @@ module Kramdown
43
43
 
44
44
  if !closed && handle_body
45
45
  if content_model == :block
46
- if !parse_blocks(el)
46
+ unless parse_blocks(el)
47
47
  warning("Found no end tag for '#{el.value}' (line #{el.options[:location]}) - auto-closing it")
48
48
  end
49
49
  elsif content_model == :span
@@ -59,31 +59,32 @@ module Kramdown
59
59
  else
60
60
  parse_raw_html(el, &method(:handle_kramdown_html_tag))
61
61
  end
62
- @src.scan(TRAILING_WHITESPACE) unless (@tree.type == :html_element && @tree.options[:content_model] == :raw)
62
+ unless @tree.type == :html_element && @tree.options[:content_model] == :raw
63
+ @src.scan(TRAILING_WHITESPACE)
64
+ end
63
65
  end
64
66
  end
65
67
 
66
-
67
68
  HTML_BLOCK_START = /^#{OPT_SPACE}<(#{REXML::Parsers::BaseParser::UNAME_STR}|\?|!--|\/)/
68
69
 
69
70
  # Parse the HTML at the current position as block-level HTML.
70
71
  def parse_block_html
71
72
  line = @src.current_line_number
72
- if result = @src.scan(HTML_COMMENT_RE)
73
- @tree.children << Element.new(:xml_comment, result, nil, :category => :block, :location => line)
73
+ if (result = @src.scan(HTML_COMMENT_RE))
74
+ @tree.children << Element.new(:xml_comment, result, nil, category: :block, location: line)
74
75
  @src.scan(TRAILING_WHITESPACE)
75
76
  true
76
- elsif result = @src.scan(HTML_INSTRUCTION_RE)
77
- @tree.children << Element.new(:xml_pi, result, nil, :category => :block, :location => line)
77
+ elsif (result = @src.scan(HTML_INSTRUCTION_RE))
78
+ @tree.children << Element.new(:xml_pi, result, nil, category: :block, location: line)
78
79
  @src.scan(TRAILING_WHITESPACE)
79
80
  true
80
81
  else
81
- if result = @src.check(/^#{OPT_SPACE}#{HTML_TAG_RE}/) && !HTML_SPAN_ELEMENTS.include?(@src[1].downcase)
82
+ if @src.check(/^#{OPT_SPACE}#{HTML_TAG_RE}/) && !HTML_SPAN_ELEMENTS.include?(@src[1].downcase)
82
83
  @src.pos += @src.matched_size
83
84
  handle_html_start_tag(line, &method(:handle_kramdown_html_tag))
84
85
  Kramdown::Parser::Html::ElementConverter.convert(@root, @tree.children.last) if @options[:html_to_native]
85
86
  true
86
- elsif result = @src.check(/^#{OPT_SPACE}#{HTML_TAG_CLOSE_RE}/) && !HTML_SPAN_ELEMENTS.include?(@src[1].downcase)
87
+ elsif @src.check(/^#{OPT_SPACE}#{HTML_TAG_CLOSE_RE}/) && !HTML_SPAN_ELEMENTS.include?(@src[1].downcase)
87
88
  name = @src[1].downcase
88
89
 
89
90
  if @tree.type == :html_element && @tree.value == name
@@ -99,20 +100,19 @@ module Kramdown
99
100
  end
100
101
  define_parser(:block_html, HTML_BLOCK_START)
101
102
 
102
-
103
103
  HTML_SPAN_START = /<(#{REXML::Parsers::BaseParser::UNAME_STR}|\?|!--|\/)/
104
104
 
105
105
  # Parse the HTML at the current position as span-level HTML.
106
106
  def parse_span_html
107
107
  line = @src.current_line_number
108
- if result = @src.scan(HTML_COMMENT_RE)
109
- @tree.children << Element.new(:xml_comment, result, nil, :category => :span, :location => line)
110
- elsif result = @src.scan(HTML_INSTRUCTION_RE)
111
- @tree.children << Element.new(:xml_pi, result, nil, :category => :span, :location => line)
112
- elsif result = @src.scan(HTML_TAG_CLOSE_RE)
108
+ if (result = @src.scan(HTML_COMMENT_RE))
109
+ @tree.children << Element.new(:xml_comment, result, nil, category: :span, location: line)
110
+ elsif (result = @src.scan(HTML_INSTRUCTION_RE))
111
+ @tree.children << Element.new(:xml_pi, result, nil, category: :span, location: line)
112
+ elsif (result = @src.scan(HTML_TAG_CLOSE_RE))
113
113
  warning("Found invalidly used HTML closing tag for '#{@src[1]}' on line #{line}")
114
114
  add_text(result)
115
- elsif result = @src.scan(HTML_TAG_RE)
115
+ elsif (result = @src.scan(HTML_TAG_RE))
116
116
  tag_name = @src[1]
117
117
  tag_name.downcase! if HTML_ELEMENT[tag_name.downcase]
118
118
  if HTML_BLOCK_ELEMENTS.include?(tag_name)
@@ -122,12 +122,17 @@ module Kramdown
122
122
  end
123
123
 
124
124
  attrs = parse_html_attributes(@src[2], line, HTML_ELEMENT[tag_name])
125
- attrs.each {|name, value| value.gsub!(/\n+/, ' ')}
126
-
127
- do_parsing = (HTML_CONTENT_MODEL[tag_name] == :raw || @tree.options[:content_model] == :raw ? false : @options[:parse_span_html])
128
- if val = HTML_MARKDOWN_ATTR_MAP[attrs.delete('markdown')]
125
+ attrs.each_value {|value| value.gsub!(/\n+/, ' ') unless value.empty? }
126
+
127
+ do_parsing = if HTML_CONTENT_MODEL[tag_name] == :raw || @tree.options[:content_model] == :raw
128
+ false
129
+ else
130
+ @options[:parse_span_html]
131
+ end
132
+ if (val = HTML_MARKDOWN_ATTR_MAP[attrs.delete('markdown')])
129
133
  if val == :block
130
- warning("Cannot use block-level parsing in span-level HTML tag (line #{line}) - using default mode")
134
+ warning("Cannot use block-level parsing in span-level HTML tag (line #{line}) " \
135
+ "- using default mode")
131
136
  elsif val == :span
132
137
  do_parsing = true
133
138
  elsif val == :default
@@ -137,8 +142,8 @@ module Kramdown
137
142
  end
138
143
  end
139
144
 
140
- el = Element.new(:html_element, tag_name, attrs, :category => :span, :location => line,
141
- :content_model => (do_parsing ? :span : :raw), :is_closed => !!@src[4])
145
+ el = Element.new(:html_element, tag_name, attrs, category: :span, location: line,
146
+ content_model: (do_parsing ? :span : :raw), is_closed: !!@src[4])
142
147
  @tree.children << el
143
148
  stop_re = /<\/#{Regexp.escape(tag_name)}\s*>/
144
149
  stop_re = Regexp.new(stop_re.source, Regexp::IGNORECASE) if HTML_ELEMENT[tag_name]
@@ -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,11 +18,12 @@ module Kramdown
18
18
  start_line_number = @src.current_line_number
19
19
  @src.pos += @src.matched_size
20
20
  begin
21
- @tree.children << Element.new(:entity, ::Kramdown::Utils::Entities.entity(@src[1] || (@src[2] && @src[2].to_i) || @src[3].hex),
22
- nil, :original => @src.matched, :location => start_line_number)
21
+ value = ::Kramdown::Utils::Entities.entity(@src[1] || (@src[2]&.to_i) || @src[3].hex)
22
+ @tree.children << Element.new(:entity, value,
23
+ nil, original: @src.matched, location: start_line_number)
23
24
  rescue ::Kramdown::Error
24
25
  @tree.children << Element.new(:entity, ::Kramdown::Utils::Entities.entity('amp'),
25
- nil, :location => start_line_number)
26
+ nil, location: start_line_number)
26
27
  add_text(@src.matched[1..-1])
27
28
  end
28
29
  end
@@ -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
  #++
@@ -15,7 +15,7 @@ module Kramdown
15
15
 
16
16
  # Parse the line break at the current location.
17
17
  def parse_line_break
18
- @tree.children << Element.new(:br, nil, nil, :location => @src.current_line_number)
18
+ @tree.children << Element.new(:br, nil, nil, location: @src.current_line_number)
19
19
  @src.pos += @src.matched_size
20
20
  end
21
21
  define_parser(:line_break, LINE_BREAK, '( |\\\\)(?=\n)')
@@ -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
  #++
@@ -25,14 +25,15 @@ module Kramdown
25
25
  return false if @src[3].to_s =~ /[ \t]+["']/
26
26
  @src.pos += @src.matched_size
27
27
  link_id, link_url, link_title = normalize_link_id(@src[1]), @src[2] || @src[3], @src[5]
28
- warning("Duplicate link ID '#{link_id}' on line #{@src.current_line_number} - overwriting") if @link_defs[link_id]
28
+ if @link_defs[link_id]
29
+ warning("Duplicate link ID '#{link_id}' on line #{@src.current_line_number} - overwriting")
30
+ end
29
31
  @tree.children << new_block_el(:eob, :link_def)
30
32
  @link_defs[link_id] = [link_url, link_title, @tree.children.last]
31
33
  true
32
34
  end
33
35
  define_parser(:link_definition, LINK_DEFINITION_START)
34
36
 
35
-
36
37
  # This helper methods adds the approriate attributes to the element +el+ of type +a+ or +img+
37
38
  # and the element itself to the @tree.
38
39
  def add_link(el, href, title, alt_text = nil, ial = nil)
@@ -66,16 +67,17 @@ module Kramdown
66
67
  link_type = (result =~ /^!/ ? :img : :a)
67
68
 
68
69
  # no nested links allowed
69
- if link_type == :a && (@tree.type == :img || @tree.type == :a || @stack.any? {|t,s| t && (t.type == :img || t.type == :a)})
70
+ if link_type == :a && (@tree.type == :img || @tree.type == :a ||
71
+ @stack.any? {|t, _| t && (t.type == :img || t.type == :a) })
70
72
  add_text(result)
71
73
  return
72
74
  end
73
- el = Element.new(link_type, nil, nil, :location => start_line_number)
75
+ el = Element.new(link_type, nil, nil, location: start_line_number)
74
76
 
75
77
  count = 1
76
78
  found = parse_spans(el, LINK_BRACKET_STOP_RE) do
77
- count = count + (@src[1] ? -1 : 1)
78
- count - el.children.select {|c| c.type == :img}.size == 0
79
+ count += (@src[1] ? -1 : 1)
80
+ count - el.children.select {|c| c.type == :img }.size == 0
79
81
  end
80
82
  unless found
81
83
  @src.revert_pos(saved_pos)
@@ -89,7 +91,7 @@ module Kramdown
89
91
  if @src.scan(LINK_INLINE_ID_RE) || !@src.check(/\(/)
90
92
  emit_warning = !@src[1]
91
93
  link_id = normalize_link_id(@src[1] || alt_text)
92
- if @link_defs.has_key?(link_id)
94
+ if @link_defs.key?(link_id)
93
95
  add_link(el, @link_defs[link_id][0], @link_defs[link_id][1], alt_text,
94
96
  @link_defs[link_id][2] && @link_defs[link_id][2].options[:ial])
95
97
  else
@@ -110,9 +112,9 @@ module Kramdown
110
112
  return
111
113
  end
112
114
  else
113
- link_url = ''
115
+ link_url = +''
114
116
  nr_of_brackets = 0
115
- while temp = @src.scan_until(LINK_PAREN_STOP_RE)
117
+ while (temp = @src.scan_until(LINK_PAREN_STOP_RE))
116
118
  link_url << temp
117
119
  if @src[2]
118
120
  nr_of_brackets -= 1
@@ -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
  #++
@@ -35,7 +35,7 @@ module Kramdown
35
35
  else
36
36
  while content =~ /^ *\t/
37
37
  temp = content.scan(/^ */).first.length + indentation
38
- content.sub!(/^( *)(\t+)/) {$1 << " "*(4 - (temp % 4) + ($2.length - 1)*4)}
38
+ content.sub!(/^( *)(\t+)/) { $1 << " " * (4 - (temp % 4) + ($2.length - 1) * 4) }
39
39
  end
40
40
  indentation += content[/^ */].length
41
41
  end
@@ -44,7 +44,6 @@ module Kramdown
44
44
  [content, indentation, *PARSE_FIRST_LIST_LINE_REGEXP_CACHE[indentation]]
45
45
  end
46
46
 
47
-
48
47
  LIST_START_UL = /^(#{OPT_SPACE}[+*-])([\t| ].*?\n)/
49
48
  LIST_START_OL = /^(#{OPT_SPACE}\d+\.)([\t| ].*?\n)/
50
49
  LIST_START = /#{LIST_START_UL}|#{LIST_START_OL}/
@@ -53,14 +52,14 @@ module Kramdown
53
52
  def parse_list
54
53
  start_line_number = @src.current_line_number
55
54
  type, list_start_re = (@src.check(LIST_START_UL) ? [:ul, LIST_START_UL] : [:ol, LIST_START_OL])
56
- list = new_block_el(type, nil, nil, :location => start_line_number)
55
+ list = new_block_el(type, nil, nil, location: start_line_number)
57
56
 
58
57
  item = nil
59
58
  content_re, lazy_re, indent_re = nil
60
59
  eob_found = false
61
60
  nested_list_found = false
62
61
  last_is_blank = false
63
- while !@src.eos?
62
+ until @src.eos?
64
63
  start_line_number = @src.current_line_number
65
64
  if last_is_blank && @src.check(HR_START)
66
65
  break
@@ -68,17 +67,21 @@ module Kramdown
68
67
  eob_found = true
69
68
  break
70
69
  elsif @src.scan(list_start_re)
71
- item = Element.new(:li, nil, nil, :location => start_line_number)
72
- item.value, indentation, content_re, lazy_re, indent_re = parse_first_list_line(@src[1].length, @src[2])
70
+ item = Element.new(:li, nil, nil, location: start_line_number)
71
+ item.value, indentation, content_re, lazy_re, indent_re =
72
+ parse_first_list_line(@src[1].length, @src[2])
73
73
  list.children << item
74
74
 
75
- item.value.sub!(self.class::LIST_ITEM_IAL) do |match|
75
+ item.value.sub!(self.class::LIST_ITEM_IAL) do |_match|
76
76
  parse_attribute_list($1, item.options[:ial] ||= {})
77
77
  ''
78
78
  end
79
79
 
80
- list_start_re = (type == :ul ? /^( {0,#{[3, indentation - 1].min}}[+*-])([\t| ].*?\n)/ :
81
- /^( {0,#{[3, indentation - 1].min}}\d+\.)([\t| ].*?\n)/)
80
+ list_start_re = if type == :ul
81
+ /^( {0,#{[3, indentation - 1].min}}[+*-])([\t| ].*?\n)/
82
+ else
83
+ /^( {0,#{[3, indentation - 1].min}}\d+\.)([\t| ].*?\n)/
84
+ end
82
85
  nested_list_found = (item.value =~ LIST_START)
83
86
  last_is_blank = false
84
87
  item.value = [item.value]
@@ -86,14 +89,14 @@ module Kramdown
86
89
  result.sub!(/^(\t+)/) { " " * 4 * $1.length }
87
90
  indentation_found = result.sub!(indent_re, '')
88
91
  if !nested_list_found && indentation_found && result =~ LIST_START
89
- item.value << ''
92
+ item.value << +''
90
93
  nested_list_found = true
91
94
  elsif nested_list_found && !indentation_found && result =~ LIST_START
92
95
  result = " " * (indentation + 4) << result
93
96
  end
94
97
  item.value.last << result
95
98
  last_is_blank = false
96
- elsif result = @src.scan(BLANK_LINE)
99
+ elsif (result = @src.scan(BLANK_LINE))
97
100
  nested_list_found = true
98
101
  last_is_blank = true
99
102
  item.value.last << result
@@ -106,7 +109,7 @@ module Kramdown
106
109
 
107
110
  last = nil
108
111
  list.children.each do |it|
109
- temp = Element.new(:temp, nil, nil, :location => it.options[:location])
112
+ temp = Element.new(:temp, nil, nil, location: it.options[:location])
110
113
 
111
114
  env = save_env
112
115
  location = it.options[:location]
@@ -119,7 +122,7 @@ module Kramdown
119
122
 
120
123
  it.children = temp.children
121
124
  it.value = nil
122
- next if it.children.size == 0
125
+ next if it.children.empty?
123
126
 
124
127
  # Handle the case where an EOB marker is inserted by a block IAL for the first paragraph
125
128
  it.children.delete_at(1) if it.children.first.type == :p &&
@@ -129,16 +132,12 @@ module Kramdown
129
132
  (it.children.length < 2 || it.children[1].type != :blank ||
130
133
  (it == list.children.last && it.children.length == 2 && !eob_found)) &&
131
134
  (list.children.last != it || list.children.size == 1 ||
132
- list.children[0..-2].any? {|cit| !cit.children.first || cit.children.first.type != :p || cit.children.first.options[:transparent]})
135
+ list.children[0..-2].any? {|cit| !cit.children.first || cit.children.first.type != :p || cit.children.first.options[:transparent] })
133
136
  it.children.first.children.first.value << "\n" if it.children.size > 1 && it.children[1].type != :blank
134
137
  it.children.first.options[:transparent] = true
135
138
  end
136
139
 
137
- if it.children.last.type == :blank
138
- last = it.children.pop
139
- else
140
- last = nil
141
- end
140
+ last = (it.children.last.type == :blank ? it.children.pop : nil)
142
141
  end
143
142
 
144
143
  @tree.children << last if !last.nil? && !eob_found
@@ -147,14 +146,14 @@ module Kramdown
147
146
  end
148
147
  define_parser(:list, LIST_START)
149
148
 
150
-
151
149
  DEFINITION_LIST_START = /^(#{OPT_SPACE}:)([\t| ].*?\n)/
152
150
 
153
151
  # Parse the ordered or unordered list at the current location.
154
152
  def parse_definition_list
155
153
  children = @tree.children
156
- if !children.last || (children.length == 1 && children.last.type != :p ) ||
157
- (children.length >= 2 && children[-1].type != :p && (children[-1].type != :blank || children[-1].value != "\n" || children[-2].type != :p))
154
+ if !children.last || (children.length == 1 && children.last.type != :p) ||
155
+ (children.length >= 2 && children[-1].type != :p &&
156
+ (children[-1].type != :blank || children[-1].value != "\n" || children[-2].type != :p))
158
157
  return false
159
158
  end
160
159
 
@@ -165,9 +164,10 @@ module Kramdown
165
164
  para = @tree.children.pop
166
165
  first_as_para = true
167
166
  end
168
- deflist.options[:location] = para.options[:location] # take location from preceding para which is the first definition term
167
+ # take location from preceding para which is the first definition term
168
+ deflist.options[:location] = para.options[:location]
169
169
  para.children.first.value.split(/\n/).each do |term|
170
- el = Element.new(:dt, nil, nil, :location => @src.current_line_number)
170
+ el = Element.new(:dt, nil, nil, location: @src.current_line_number)
171
171
  term.sub!(self.class::LIST_ITEM_IAL) do
172
172
  parse_attribute_list($1, el.options[:ial] ||= {})
173
173
  ''
@@ -182,15 +182,16 @@ module Kramdown
182
182
  content_re, lazy_re, indent_re = nil
183
183
  def_start_re = DEFINITION_LIST_START
184
184
  last_is_blank = false
185
- while !@src.eos?
185
+ until @src.eos?
186
186
  start_line_number = @src.current_line_number
187
187
  if @src.scan(def_start_re)
188
- item = Element.new(:dd, nil, nil, :location => start_line_number)
188
+ item = Element.new(:dd, nil, nil, location: start_line_number)
189
189
  item.options[:first_as_para] = first_as_para
190
- item.value, indentation, content_re, lazy_re, indent_re = parse_first_list_line(@src[1].length, @src[2])
190
+ item.value, indentation, content_re, lazy_re, indent_re =
191
+ parse_first_list_line(@src[1].length, @src[2])
191
192
  deflist.children << item
192
193
 
193
- item.value.sub!(self.class::LIST_ITEM_IAL) do |match|
194
+ item.value.sub!(self.class::LIST_ITEM_IAL) do |_match|
194
195
  parse_attribute_list($1, item.options[:ial] ||= {})
195
196
  ''
196
197
  end
@@ -201,12 +202,12 @@ module Kramdown
201
202
  elsif @src.check(EOB_MARKER)
202
203
  break
203
204
  elsif (result = @src.scan(content_re)) || (!last_is_blank && (result = @src.scan(lazy_re)))
204
- result.sub!(/^(\t+)/) { " "*($1 ? 4*$1.length : 0) }
205
+ result.sub!(/^(\t+)/) { " " * ($1 ? 4 * $1.length : 0) }
205
206
  result.sub!(indent_re, '')
206
207
  item.value << result
207
208
  first_as_para = false
208
209
  last_is_blank = false
209
- elsif result = @src.scan(BLANK_LINE)
210
+ elsif (result = @src.scan(BLANK_LINE))
210
211
  first_as_para = true
211
212
  item.value << result
212
213
  last_is_blank = true
@@ -221,13 +222,9 @@ module Kramdown
221
222
 
222
223
  parse_blocks(it, it.value)
223
224
  it.value = nil
224
- next if it.children.size == 0
225
+ next if it.children.empty?
225
226
 
226
- if it.children.last.type == :blank
227
- last = it.children.pop
228
- else
229
- last = nil
230
- end
227
+ last = (it.children.last.type == :blank ? it.children.pop : nil)
231
228
 
232
229
  if it.children.first && it.children.first.type == :p && !it.options.delete(:first_as_para)
233
230
  it.children.first.children.first.value << "\n" if it.children.size > 1
@@ -237,14 +234,15 @@ module Kramdown
237
234
 
238
235
  if @tree.children.length >= 1 && @tree.children.last.type == :dl
239
236
  @tree.children[-1].children.concat(deflist.children)
240
- elsif @tree.children.length >= 2 && @tree.children[-1].type == :blank && @tree.children[-2].type == :dl
237
+ elsif @tree.children.length >= 2 && @tree.children[-1].type == :blank &&
238
+ @tree.children[-2].type == :dl
241
239
  @tree.children.pop
242
240
  @tree.children[-1].children.concat(deflist.children)
243
241
  else
244
242
  @tree.children << deflist
245
243
  end
246
244
 
247
- @tree.children << last if !last.nil?
245
+ @tree.children << last if last
248
246
 
249
247
  true
250
248
  end