kramdown 1.5.0 → 1.6.0

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

Potentially problematic release.


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

Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTERS +3 -1
  3. data/README.md +6 -6
  4. data/Rakefile +3 -3
  5. data/VERSION +1 -1
  6. data/bin/kramdown +1 -1
  7. data/doc/default.template +2 -2
  8. data/doc/index.page +21 -7
  9. data/doc/options.page +42 -3
  10. data/doc/sidebar.template +0 -7
  11. data/doc/sitemap.sitemap +5 -0
  12. data/doc/syntax.page +31 -3
  13. data/doc/virtual +3 -0
  14. data/lib/kramdown.rb +1 -1
  15. data/lib/kramdown/compatibility.rb +1 -1
  16. data/lib/kramdown/converter.rb +1 -1
  17. data/lib/kramdown/converter/base.rb +2 -1
  18. data/lib/kramdown/converter/html.rb +10 -5
  19. data/lib/kramdown/converter/kramdown.rb +13 -7
  20. data/lib/kramdown/converter/latex.rb +2 -1
  21. data/lib/kramdown/converter/math_engine/itex2mml.rb +1 -1
  22. data/lib/kramdown/converter/math_engine/mathjax.rb +18 -3
  23. data/lib/kramdown/converter/math_engine/ritex.rb +1 -1
  24. data/lib/kramdown/converter/pdf.rb +3 -2
  25. data/lib/kramdown/converter/remove_html_tags.rb +3 -1
  26. data/lib/kramdown/converter/syntax_highlighter.rb +53 -0
  27. data/lib/kramdown/converter/syntax_highlighter/coderay.rb +1 -1
  28. data/lib/kramdown/converter/syntax_highlighter/rouge.rb +2 -2
  29. data/lib/kramdown/converter/toc.rb +2 -2
  30. data/lib/kramdown/document.rb +5 -5
  31. data/lib/kramdown/element.rb +4 -1
  32. data/lib/kramdown/error.rb +1 -1
  33. data/lib/kramdown/options.rb +4 -3
  34. data/lib/kramdown/parser.rb +1 -1
  35. data/lib/kramdown/parser/base.rb +8 -4
  36. data/lib/kramdown/parser/gfm.rb +9 -1
  37. data/lib/kramdown/parser/html.rb +18 -3
  38. data/lib/kramdown/parser/kramdown.rb +8 -5
  39. data/lib/kramdown/parser/kramdown/abbreviation.rb +10 -2
  40. data/lib/kramdown/parser/kramdown/autolink.rb +1 -1
  41. data/lib/kramdown/parser/kramdown/blank_line.rb +1 -1
  42. data/lib/kramdown/parser/kramdown/block_boundary.rb +1 -1
  43. data/lib/kramdown/parser/kramdown/blockquote.rb +1 -1
  44. data/lib/kramdown/parser/kramdown/codeblock.rb +1 -1
  45. data/lib/kramdown/parser/kramdown/codespan.rb +1 -1
  46. data/lib/kramdown/parser/kramdown/emphasis.rb +2 -2
  47. data/lib/kramdown/parser/kramdown/eob.rb +1 -1
  48. data/lib/kramdown/parser/kramdown/escaped_chars.rb +1 -1
  49. data/lib/kramdown/parser/kramdown/extensions.rb +8 -7
  50. data/lib/kramdown/parser/kramdown/footnote.rb +11 -4
  51. data/lib/kramdown/parser/kramdown/header.rb +1 -1
  52. data/lib/kramdown/parser/kramdown/horizontal_rule.rb +1 -1
  53. data/lib/kramdown/parser/kramdown/html.rb +7 -4
  54. data/lib/kramdown/parser/kramdown/html_entity.rb +1 -1
  55. data/lib/kramdown/parser/kramdown/line_break.rb +1 -1
  56. data/lib/kramdown/parser/kramdown/link.rb +8 -5
  57. data/lib/kramdown/parser/kramdown/list.rb +12 -7
  58. data/lib/kramdown/parser/kramdown/math.rb +3 -3
  59. data/lib/kramdown/parser/kramdown/paragraph.rb +3 -3
  60. data/lib/kramdown/parser/kramdown/smart_quotes.rb +1 -1
  61. data/lib/kramdown/parser/kramdown/table.rb +1 -1
  62. data/lib/kramdown/parser/kramdown/typographic_symbol.rb +1 -1
  63. data/lib/kramdown/parser/markdown.rb +2 -2
  64. data/lib/kramdown/utils.rb +1 -1
  65. data/lib/kramdown/utils/configurable.rb +1 -1
  66. data/lib/kramdown/utils/entities.rb +1 -1
  67. data/lib/kramdown/utils/html.rb +3 -1
  68. data/lib/kramdown/utils/ordered_hash.rb +1 -1
  69. data/lib/kramdown/utils/string_scanner.rb +8 -0
  70. data/lib/kramdown/utils/unidecoder.rb +1 -1
  71. data/lib/kramdown/version.rb +2 -2
  72. data/man/man1/kramdown.1 +1 -1
  73. data/test/run_tests.rb +1 -1
  74. data/test/test_files.rb +48 -17
  75. data/test/test_location.rb +8 -0
  76. data/test/test_string_scanner_kramdown.rb +8 -0
  77. data/test/testcases/block/04_header/atx_header.html +1 -1
  78. data/test/testcases/block/06_codeblock/highlighting-rouge.html +2 -2
  79. data/test/testcases/block/09_html/html_after_block.html +7 -0
  80. data/test/testcases/block/09_html/html_after_block.text +5 -0
  81. data/test/testcases/block/11_ial/simple.html +3 -1
  82. data/test/testcases/block/11_ial/simple.text +5 -1
  83. data/test/testcases/block/15_math/gh_128.html +1 -1
  84. data/test/testcases/block/15_math/mathjax_preview.html +4 -0
  85. data/test/testcases/block/15_math/mathjax_preview.options +2 -0
  86. data/test/testcases/block/15_math/mathjax_preview.text +5 -0
  87. data/test/testcases/block/15_math/mathjax_preview_simple.html +4 -0
  88. data/test/testcases/block/15_math/mathjax_preview_simple.options +2 -0
  89. data/test/testcases/block/15_math/mathjax_preview_simple.text +5 -0
  90. data/test/testcases/block/15_math/normal.html +1 -1
  91. data/test/testcases/block/16_toc/toc_exclude.html +7 -7
  92. data/test/testcases/block/16_toc/toc_levels.html +4 -4
  93. data/test/testcases/block/16_toc/toc_with_footnotes.html +1 -1
  94. data/test/testcases/span/01_link/empty_title.htmlinput +3 -0
  95. data/test/testcases/span/01_link/empty_title.text +7 -0
  96. data/test/testcases/span/01_link/link_defs_with_ial.html +4 -0
  97. data/test/testcases/span/01_link/link_defs_with_ial.text +16 -0
  98. data/test/testcases/span/02_emphasis/normal.html +2 -0
  99. data/test/testcases/span/02_emphasis/normal.text +2 -0
  100. data/test/testcases/span/04_footnote/markers.text +1 -0
  101. data/test/testcases/span/abbreviations/abbrev.html +3 -1
  102. data/test/testcases/span/abbreviations/abbrev.text +7 -0
  103. data/test/testcases/span/line_breaks/normal.html +2 -2
  104. data/test/testcases/span/line_breaks/normal.latex +2 -2
  105. metadata +20 -6
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
3
  #--
4
- # Copyright (C) 2009-2014 Thomas Leitner <t_leitner@gmx.at>
4
+ # Copyright (C) 2009-2015 Thomas Leitner <t_leitner@gmx.at>
5
5
  #
6
6
  # This file is part of kramdown which is licensed under the MIT.
7
7
  #++
@@ -20,12 +20,20 @@ module Kramdown
20
20
  abbrev_id, abbrev_text = @src[1], @src[2]
21
21
  abbrev_text.strip!
22
22
  warning("Duplicate abbreviation ID '#{abbrev_id}' on line #{start_line_number} - overwriting") if @root.options[:abbrev_defs][abbrev_id]
23
+ @tree.children << new_block_el(:eob, :abbrev_def)
23
24
  @root.options[:abbrev_defs][abbrev_id] = abbrev_text
24
- @tree.children << Element.new(:eob, :abbrev_def)
25
+ @root.options[:abbrev_attr][abbrev_id] = @tree.children.last
25
26
  true
26
27
  end
27
28
  define_parser(:abbrev_definition, ABBREV_DEFINITION_START)
28
29
 
30
+ # Correct abbreviation attributes.
31
+ def correct_abbreviations_attributes
32
+ @root.options[:abbrev_attr].keys.each do |k|
33
+ @root.options[:abbrev_attr][k] = @root.options[:abbrev_attr][k].attr
34
+ end
35
+ end
36
+
29
37
  # Replace the abbreviation text with elements.
30
38
  def replace_abbreviations(el, regexps = nil)
31
39
  return if @root.options[:abbrev_defs].empty?
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
3
  #--
4
- # Copyright (C) 2009-2014 Thomas Leitner <t_leitner@gmx.at>
4
+ # Copyright (C) 2009-2015 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
1
  # -*- coding: utf-8 -*-
2
2
  #
3
3
  #--
4
- # Copyright (C) 2009-2014 Thomas Leitner <t_leitner@gmx.at>
4
+ # Copyright (C) 2009-2015 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
1
  # -*- coding: utf-8 -*-
2
2
  #
3
3
  #--
4
- # Copyright (C) 2009-2014 Thomas Leitner <t_leitner@gmx.at>
4
+ # Copyright (C) 2009-2015 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
1
  # -*- coding: utf-8 -*-
2
2
  #
3
3
  #--
4
- # Copyright (C) 2009-2014 Thomas Leitner <t_leitner@gmx.at>
4
+ # Copyright (C) 2009-2015 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
1
  # -*- coding: utf-8 -*-
2
2
  #
3
3
  #--
4
- # Copyright (C) 2009-2014 Thomas Leitner <t_leitner@gmx.at>
4
+ # Copyright (C) 2009-2015 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
1
  # -*- coding: utf-8 -*-
2
2
  #
3
3
  #--
4
- # Copyright (C) 2009-2014 Thomas Leitner <t_leitner@gmx.at>
4
+ # Copyright (C) 2009-2015 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
1
  # -*- coding: utf-8 -*-
2
2
  #
3
3
  #--
4
- # Copyright (C) 2009-2014 Thomas Leitner <t_leitner@gmx.at>
4
+ # Copyright (C) 2009-2015 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,7 +22,7 @@ module Kramdown
22
22
  element = (result.length == 2 ? :strong : :em)
23
23
  type = result[0..0]
24
24
 
25
- if (type == '_' && @src.pre_match =~ /[[:alnum:]]\z/ && @src.check(/[[:alnum:]]/)) || @src.check(/\s/) ||
25
+ if (type == '_' && @src.pre_match =~ /[[:alnum:]]\z/) || @src.check(/\s/) ||
26
26
  @tree.type == element || @stack.any? {|el, _| el.type == element}
27
27
  add_text(result)
28
28
  return
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
3
  #--
4
- # Copyright (C) 2009-2014 Thomas Leitner <t_leitner@gmx.at>
4
+ # Copyright (C) 2009-2015 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
1
  # -*- coding: utf-8 -*-
2
2
  #
3
3
  #--
4
- # Copyright (C) 2009-2014 Thomas Leitner <t_leitner@gmx.at>
4
+ # Copyright (C) 2009-2015 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
1
  # -*- coding: utf-8 -*-
2
2
  #
3
3
  #--
4
- # Copyright (C) 2009-2014 Thomas Leitner <t_leitner@gmx.at>
4
+ # Copyright (C) 2009-2015 Thomas Leitner <t_leitner@gmx.at>
5
5
  #
6
6
  # This file is part of kramdown which is licensed under the MIT.
7
7
  #++
@@ -117,7 +117,7 @@ module Kramdown
117
117
  end.each do |k,v|
118
118
  warning("Unknown kramdown option '#{k}'")
119
119
  end
120
- @tree.children << Element.new(:eob, :extension) if type == :block
120
+ @tree.children << new_block_el(:eob, :extension) if type == :block
121
121
  true
122
122
  else
123
123
  false
@@ -129,7 +129,7 @@ module Kramdown
129
129
  ALD_ANY_CHARS = /\\\}|[^\}]/
130
130
  ALD_ID_NAME = /\w#{ALD_ID_CHARS}*/
131
131
  ALD_TYPE_KEY_VALUE_PAIR = /(#{ALD_ID_NAME})=("|')((?:\\\}|\\\2|[^\}\2])*?)\2/
132
- ALD_TYPE_CLASS_NAME = /\.(#{ALD_ID_NAME})/
132
+ ALD_TYPE_CLASS_NAME = /\.(-?#{ALD_ID_NAME})/
133
133
  ALD_TYPE_ID_NAME = /#([A-Za-z][\w:-]*)/
134
134
  ALD_TYPE_ID_OR_CLASS = /#{ALD_TYPE_ID_NAME}|#{ALD_TYPE_CLASS_NAME}/
135
135
  ALD_TYPE_ID_OR_CLASS_MULTI = /((?:#{ALD_TYPE_ID_NAME}|#{ALD_TYPE_CLASS_NAME})+)/
@@ -152,16 +152,17 @@ module Kramdown
152
152
  def parse_block_extensions
153
153
  if @src.scan(ALD_START)
154
154
  parse_attribute_list(@src[2], @alds[@src[1]] ||= Utils::OrderedHash.new)
155
- @tree.children << Element.new(:eob, :ald)
155
+ @tree.children << new_block_el(:eob, :ald)
156
156
  true
157
157
  elsif @src.check(EXT_BLOCK_START)
158
158
  parse_extension_start_tag(:block)
159
159
  elsif @src.scan(IAL_BLOCK_START)
160
- if @tree.children.last && @tree.children.last.type != :blank && @tree.children.last.type != :eob
160
+ if @tree.children.last && @tree.children.last.type != :blank &&
161
+ (@tree.children.last.type != :eob || [:link_def, :abbrev_def, :footnote_def].include?(@tree.children.last.value))
161
162
  parse_attribute_list(@src[1], @tree.children.last.options[:ial] ||= Utils::OrderedHash.new)
162
- @tree.children << Element.new(:eob, :ial) unless @src.check(IAL_BLOCK_START)
163
+ @tree.children << new_block_el(:eob, :ial) unless @src.check(IAL_BLOCK_START)
163
164
  else
164
- parse_attribute_list(@src[1], @block_ial = Utils::OrderedHash.new)
165
+ parse_attribute_list(@src[1], @block_ial ||= Utils::OrderedHash.new)
165
166
  end
166
167
  true
167
168
  else
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
3
  #--
4
- # Copyright (C) 2009-2014 Thomas Leitner <t_leitner@gmx.at>
4
+ # Copyright (C) 2009-2015 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,8 +25,9 @@ module Kramdown
25
25
  el = Element.new(:footnote_def, nil, nil, :location => start_line_number)
26
26
  parse_blocks(el, @src[2].gsub(INDENT, ''))
27
27
  warning("Duplicate footnote name '#{@src[1]}' on line #{start_line_number} - overwriting") if @footnotes[@src[1]]
28
+ @tree.children << new_block_el(:eob, :footnote_def)
28
29
  (@footnotes[@src[1]] = {})[:content] = el
29
- @tree.children << Element.new(:eob, :footnote_def)
30
+ @footnotes[@src[1]][:eob] = @tree.children.last
30
31
  true
31
32
  end
32
33
  define_parser(:footnote_definition, FOOTNOTE_DEFINITION_START)
@@ -40,9 +41,15 @@ module Kramdown
40
41
  @src.pos += @src.matched_size
41
42
  fn_def = @footnotes[@src[1]]
42
43
  if fn_def
44
+ if fn_def[:eob]
45
+ update_attr_with_ial(fn_def[:eob].attr, fn_def[:eob].options[:ial] || {})
46
+ fn_def[:attr] = fn_def[:eob].attr
47
+ fn_def[:options] = fn_def[:eob].options
48
+ fn_def.delete(:eob)
49
+ end
43
50
  fn_def[:marker] ||= []
44
- fn_def[:marker].push(Element.new(:footnote, fn_def[:content], nil, :name => @src[1], :location => start_line_number))
45
- fn_def[:stack] = [@stack.map {|s| s.first}, @tree, fn_def[:marker]].flatten.compact
51
+ 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)))
46
53
  @tree.children << fn_def[:marker].last
47
54
  else
48
55
  warning("Footnote definition for '#{@src[1]}' not found on line #{start_line_number}")
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
3
  #--
4
- # Copyright (C) 2009-2014 Thomas Leitner <t_leitner@gmx.at>
4
+ # Copyright (C) 2009-2015 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
1
  # -*- coding: utf-8 -*-
2
2
  #
3
3
  #--
4
- # Copyright (C) 2009-2014 Thomas Leitner <t_leitner@gmx.at>
4
+ # Copyright (C) 2009-2015 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
1
  # -*- coding: utf-8 -*-
2
2
  #
3
3
  #--
4
- # Copyright (C) 2009-2014 Thomas Leitner <t_leitner@gmx.at>
4
+ # Copyright (C) 2009-2015 Thomas Leitner <t_leitner@gmx.at>
5
5
  #
6
6
  # This file is part of kramdown which is licensed under the MIT.
7
7
  #++
@@ -23,7 +23,10 @@ module Kramdown
23
23
  TRAILING_WHITESPACE = /[ \t]*\n/
24
24
 
25
25
  def handle_kramdown_html_tag(el, closed, handle_body)
26
- el.options[:ial] = @block_ial if @block_ial
26
+ if @block_ial
27
+ el.options[:ial] = @block_ial
28
+ @block_ial = nil
29
+ end
27
30
 
28
31
  content_model = if @tree.type != :html_element || @tree.options[:content_model] != :raw
29
32
  (@options[:parse_block_html] ? HTML_CONTENT_MODEL[el.value] : :raw)
@@ -117,8 +120,8 @@ module Kramdown
117
120
  return
118
121
  end
119
122
 
120
- attrs = Utils::OrderedHash.new
121
- @src[2].scan(HTML_ATTRIBUTE_RE).each {|name,sep,val| attrs[name.downcase] = (val || '').gsub(/\n+/, ' ')}
123
+ attrs = parse_html_attributes(@src[2], line)
124
+ attrs.each {|name, value| value.gsub!(/\n+/, ' ')}
122
125
 
123
126
  do_parsing = (HTML_CONTENT_MODEL[tag_name] == :raw || @tree.options[:content_model] == :raw ? false : @options[:parse_span_html])
124
127
  if val = HTML_MARKDOWN_ATTR_MAP[attrs.delete('markdown')]
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
3
  #--
4
- # Copyright (C) 2009-2014 Thomas Leitner <t_leitner@gmx.at>
4
+ # Copyright (C) 2009-2015 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
1
  # -*- coding: utf-8 -*-
2
2
  #
3
3
  #--
4
- # Copyright (C) 2009-2014 Thomas Leitner <t_leitner@gmx.at>
4
+ # Copyright (C) 2009-2015 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
1
  # -*- coding: utf-8 -*-
2
2
  #
3
3
  #--
4
- # Copyright (C) 2009-2014 Thomas Leitner <t_leitner@gmx.at>
4
+ # Copyright (C) 2009-2015 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,8 +25,8 @@ module Kramdown
25
25
  @src.pos += @src.matched_size
26
26
  link_id, link_url, link_title = normalize_link_id(@src[1]), @src[2] || @src[3], @src[5]
27
27
  warning("Duplicate link ID '#{link_id}' on line #{@src.current_line_number} - overwriting") if @link_defs[link_id]
28
- @link_defs[link_id] = [link_url, link_title]
29
- @tree.children << Element.new(:eob, :link_def)
28
+ @tree.children << new_block_el(:eob, :link_def)
29
+ @link_defs[link_id] = [link_url, link_title, @tree.children.last]
30
30
  true
31
31
  end
32
32
  define_parser(:link_definition, LINK_DEFINITION_START)
@@ -34,7 +34,9 @@ module Kramdown
34
34
 
35
35
  # This helper methods adds the approriate attributes to the element +el+ of type +a+ or +img+
36
36
  # and the element itself to the @tree.
37
- def add_link(el, href, title, alt_text = nil)
37
+ def add_link(el, href, title, alt_text = nil, ial = nil)
38
+ el.options[:ial] = ial
39
+ update_attr_with_ial(el.attr, ial) if ial
38
40
  if el.type == :a
39
41
  el.attr['href'] = href
40
42
  else
@@ -86,7 +88,8 @@ module Kramdown
86
88
  if @src.scan(LINK_INLINE_ID_RE) || !@src.check(/\(/)
87
89
  link_id = normalize_link_id(@src[1] || alt_text)
88
90
  if @link_defs.has_key?(link_id)
89
- add_link(el, @link_defs[link_id].first, @link_defs[link_id].last, alt_text)
91
+ add_link(el, @link_defs[link_id][0], @link_defs[link_id][1], alt_text,
92
+ @link_defs[link_id][2] && @link_defs[link_id][2].options[:ial])
90
93
  else
91
94
  warning("No link definition for link ID '#{link_id}' found on line #{start_line_number}")
92
95
  @src.revert_pos(saved_pos)
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
3
  #--
4
- # Copyright (C) 2009-2014 Thomas Leitner <t_leitner@gmx.at>
4
+ # Copyright (C) 2009-2015 Thomas Leitner <t_leitner@gmx.at>
5
5
  #
6
6
  # This file is part of kramdown which is licensed under the MIT.
7
7
  #++
@@ -19,6 +19,14 @@ module Kramdown
19
19
  LIST_ITEM_IAL = /^\s*(?:\{:(?!(?:#{ALD_ID_NAME})?:|\/)(#{ALD_ANY_CHARS}+)\})\s*/
20
20
  LIST_ITEM_IAL_CHECK = /^#{LIST_ITEM_IAL}?\s*\n/
21
21
 
22
+ PARSE_FIRST_LIST_LINE_REGEXP_CACHE = Hash.new do |h, indentation|
23
+ indent_re = /^ {#{indentation}}/
24
+ content_re = /^(?:(?:\t| {4}){#{indentation / 4}} {#{indentation % 4}}|(?:\t| {4}){#{indentation / 4 + 1}}).*\S.*\n/
25
+ lazy_re = /(?!^ {0,#{[indentation, 3].min}}(?:#{IAL_BLOCK}|#{LAZY_END_HTML_STOP}|#{LAZY_END_HTML_START})).*\S.*\n/
26
+
27
+ h[indentation] = [content_re, lazy_re, indent_re]
28
+ end
29
+
22
30
  # Used for parsing the first line of a list item or a definition, i.e. the line with list item
23
31
  # marker or the definition marker.
24
32
  def parse_first_list_line(indentation, content)
@@ -29,14 +37,11 @@ module Kramdown
29
37
  temp = content.scan(/^ */).first.length + indentation
30
38
  content.sub!(/^( *)(\t+)/) {$1 << " "*(4 - (temp % 4) + ($2.length - 1)*4)}
31
39
  end
32
- indentation += content.scan(/^ */).first.length
40
+ indentation += content[/^ */].length
33
41
  end
34
42
  content.sub!(/^\s*/, '')
35
43
 
36
- indent_re = /^ {#{indentation}}/
37
- content_re = /^(?:(?:\t| {4}){#{indentation / 4}} {#{indentation % 4}}|(?:\t| {4}){#{indentation / 4 + 1}}).*\S.*\n/
38
- lazy_re = /(?!^ {0,#{[indentation, 3].min}}(?:#{IAL_BLOCK}|#{LAZY_END_HTML_STOP}|#{LAZY_END_HTML_START})).*\S.*\n/
39
- [content, indentation, content_re, lazy_re, indent_re]
44
+ [content, indentation, *PARSE_FIRST_LIST_LINE_REGEXP_CACHE[indentation]]
40
45
  end
41
46
 
42
47
 
@@ -78,7 +83,7 @@ module Kramdown
78
83
  last_is_blank = false
79
84
  item.value = [item.value]
80
85
  elsif (result = @src.scan(content_re)) || (!last_is_blank && (result = @src.scan(lazy_re)))
81
- result.sub!(/^(\t+)/) { " "*($1 ? 4*$1.length : 0) }
86
+ result.sub!(/^(\t+)/) { " " * 4 * $1.length }
82
87
  result.sub!(indent_re, '')
83
88
  if !nested_list_found && result =~ LIST_START
84
89
  item.value << ''
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
3
  #--
4
- # Copyright (C) 2009-2014 Thomas Leitner <t_leitner@gmx.at>
4
+ # Copyright (C) 2009-2015 Thomas Leitner <t_leitner@gmx.at>
5
5
  #
6
6
  # This file is part of kramdown which is licensed under the MIT.
7
7
  #++
@@ -27,7 +27,7 @@ module Kramdown
27
27
 
28
28
  saved_pos = @src.save_pos
29
29
  @src.pos += @src.matched_size
30
- data = @src[2]
30
+ data = @src[2].strip
31
31
  if before_block_boundary?
32
32
  @tree.children << new_block_el(:math, data, nil, :category => :block, :location => start_line_number)
33
33
  true
@@ -45,7 +45,7 @@ module Kramdown
45
45
  def parse_inline_math
46
46
  start_line_number = @src.current_line_number
47
47
  @src.pos += @src.matched_size
48
- @tree.children << Element.new(:math, @src[1], nil, :category => :span, :location => start_line_number)
48
+ @tree.children << Element.new(:math, @src[1].strip, nil, :category => :span, :location => start_line_number)
49
49
  end
50
50
  define_parser(:inline_math, INLINE_MATH_START, '\$')
51
51
 
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
3
  #--
4
- # Copyright (C) 2009-2014 Thomas Leitner <t_leitner@gmx.at>
4
+ # Copyright (C) 2009-2015 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,7 +18,7 @@ module Kramdown
18
18
  class Kramdown
19
19
 
20
20
  LAZY_END_HTML_SPAN_ELEMENTS = HTML_SPAN_ELEMENTS + %w{script}
21
- LAZY_END_HTML_START = /<(?>(?!(?:#{LAZY_END_HTML_SPAN_ELEMENTS.join('|')})\b)#{REXML::Parsers::BaseParser::UNAME_STR})\s*(?>\s+#{REXML::Parsers::BaseParser::UNAME_STR}\s*=\s*(["']).*?\1)*\s*\/?>/m
21
+ LAZY_END_HTML_START = /<(?>(?!(?:#{LAZY_END_HTML_SPAN_ELEMENTS.join('|')})\b)#{REXML::Parsers::BaseParser::UNAME_STR})/
22
22
  LAZY_END_HTML_STOP = /<\/(?!(?:#{LAZY_END_HTML_SPAN_ELEMENTS.join('|')})\b)#{REXML::Parsers::BaseParser::UNAME_STR}\s*>/m
23
23
 
24
24
  LAZY_END = /#{BLANK_LINE}|#{IAL_BLOCK_START}|#{EOB_MARKER}|^#{OPT_SPACE}#{LAZY_END_HTML_STOP}|^#{OPT_SPACE}#{LAZY_END_HTML_START}|\Z/
@@ -34,7 +34,7 @@ module Kramdown
34
34
  while !@src.match?(self.class::PARAGRAPH_END)
35
35
  result << @src.scan(PARAGRAPH_MATCH)
36
36
  end
37
- result.chomp!
37
+ result.rstrip!
38
38
  if @tree.children.last && @tree.children.last.type == :p
39
39
  @tree.children.last.children.first.value << "\n" << result
40
40
  else
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
3
  #--
4
- # Copyright (C) 2009-2014 Thomas Leitner <t_leitner@gmx.at>
4
+ # Copyright (C) 2009-2015 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
1
  # -*- coding: utf-8 -*-
2
2
  #
3
3
  #--
4
- # Copyright (C) 2009-2014 Thomas Leitner <t_leitner@gmx.at>
4
+ # Copyright (C) 2009-2015 Thomas Leitner <t_leitner@gmx.at>
5
5
  #
6
6
  # This file is part of kramdown which is licensed under the MIT.
7
7
  #++