kramdown 0.13.2 → 0.13.3

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 (39) hide show
  1. data/CONTRIBUTERS +1 -1
  2. data/ChangeLog +196 -0
  3. data/Rakefile +5 -3
  4. data/VERSION +1 -1
  5. data/data/kramdown/document.latex +1 -1
  6. data/doc/default.scss.css +7 -1
  7. data/doc/index.page +1 -1
  8. data/doc/quickref.page +29 -8
  9. data/doc/tests.page +1 -1
  10. data/lib/kramdown/converter/base.rb +5 -5
  11. data/lib/kramdown/converter/html.rb +14 -15
  12. data/lib/kramdown/converter/kramdown.rb +5 -3
  13. data/lib/kramdown/converter/latex.rb +16 -16
  14. data/lib/kramdown/document.rb +47 -50
  15. data/lib/kramdown/parser/base.rb +8 -8
  16. data/lib/kramdown/parser/html.rb +56 -36
  17. data/lib/kramdown/parser/kramdown.rb +5 -5
  18. data/lib/kramdown/parser/kramdown/extensions.rb +2 -2
  19. data/lib/kramdown/parser/kramdown/link.rb +1 -1
  20. data/lib/kramdown/parser/kramdown/table.rb +3 -3
  21. data/lib/kramdown/utils/html.rb +6 -7
  22. data/lib/kramdown/utils/ordered_hash.rb +17 -0
  23. data/lib/kramdown/version.rb +1 -1
  24. data/test/test_files.rb +35 -0
  25. data/test/testcases/block/09_html/content_model/tables.html +8 -8
  26. data/test/testcases/block/09_html/content_model/tables.text +1 -1
  27. data/test/testcases/block/09_html/html_and_headers.html +5 -0
  28. data/test/testcases/block/09_html/html_and_headers.text +6 -0
  29. data/test/testcases/block/09_html/html_to_native/emphasis.html +2 -1
  30. data/test/testcases/block/09_html/html_to_native/table_normal.html +10 -12
  31. data/test/testcases/block/09_html/html_to_native/table_simple.html +11 -11
  32. data/test/testcases/block/14_table/header.html +9 -16
  33. data/test/testcases/block/14_table/simple.html +19 -0
  34. data/test/testcases/block/14_table/simple.html.19 +19 -0
  35. data/test/testcases/block/14_table/simple.text +6 -0
  36. data/test/testcases/block/14_table/table_with_footnote.html +25 -0
  37. data/test/testcases/block/14_table/table_with_footnote.latex +11 -0
  38. data/test/testcases/block/14_table/table_with_footnote.text +6 -0
  39. metadata +8 -3
@@ -85,7 +85,7 @@ module Kramdown
85
85
  @footnotes = {}
86
86
 
87
87
  @block_parsers = [:blank_line, :codeblock, :codeblock_fenced, :blockquote, :atx_header,
88
- :setext_header, :horizontal_rule, :list, :definition_list, :block_html,
88
+ :horizontal_rule, :list, :definition_list, :block_html, :setext_header,
89
89
  :table, :footnote_definition, :link_definition, :abbrev_definition,
90
90
  :block_extensions, :block_math, :eob_marker, :paragraph]
91
91
  @span_parsers = [:emphasis, :codespan, :autolink, :span_html, :footnote_marker, :link, :smart_quotes, :inline_math,
@@ -95,7 +95,7 @@ module Kramdown
95
95
  private_class_method(:new, :allocate)
96
96
 
97
97
 
98
- # The source string provided on initialization is parsed into the <tt>@root</tt> element.
98
+ # The source string provided on initialization is parsed into the @root element.
99
99
  def parse
100
100
  configure_parser
101
101
  parse_blocks(@root, adapt_source(source))
@@ -153,8 +153,8 @@ module Kramdown
153
153
  status
154
154
  end
155
155
 
156
- # Update the tree by parsing all <tt>:raw_text</tt> elements with the span-level parser
157
- # (resets the environment) and by updating the attributes from the IALs.
156
+ # Update the tree by parsing all :+raw_text+ elements with the span-level parser (resets the
157
+ # environment) and by updating the attributes from the IALs.
158
158
  def update_tree(element)
159
159
  last_blank = nil
160
160
  element.children.map! do |child|
@@ -182,7 +182,7 @@ module Kramdown
182
182
  end.flatten!
183
183
  end
184
184
 
185
- # Parse all span-level elements in the source string of <tt>@src</tt> into +el+.
185
+ # Parse all span-level elements in the source string of @src into +el+.
186
186
  #
187
187
  # If the parameter +stop_re+ (a regexp) is used, parsing is immediately stopped if the regexp
188
188
  # matches and if no block is given or if a block is given and it returns +true+.
@@ -57,8 +57,8 @@ module Kramdown
57
57
  end
58
58
  end
59
59
 
60
- # Parse the generic extension at the current point. The parameter +type+ can either be
61
- # <tt>:block</tt> or <tt>:span</tt> depending whether we parse a block or span extension tag.
60
+ # Parse the generic extension at the current point. The parameter +type+ can either be :block
61
+ # or :span depending whether we parse a block or span extension tag.
62
62
  def parse_extension_start_tag(type)
63
63
  orig_pos = @src.pos
64
64
  @src.pos += @src.matched_size
@@ -44,7 +44,7 @@ module Kramdown
44
44
 
45
45
 
46
46
  # This helper methods adds the approriate attributes to the element +el+ of type +a+ or +img+
47
- # and the element itself to the <tt>@tree</tt>.
47
+ # and the element itself to the @tree.
48
48
  def add_link(el, href, title, alt_text = nil)
49
49
  if el.type == :a
50
50
  el.attr['href'] = href
@@ -75,7 +75,7 @@ module Kramdown
75
75
  # parse possible code spans on the line and correctly split the line into cells
76
76
  env = save_env
77
77
  cells = []
78
- (@src[1] + ' ').split(/(<code.*?>.*?<\/code>)/).each_with_index do |str, i|
78
+ @src[1].split(/(<code.*?>.*?<\/code>)/).each_with_index do |str, i|
79
79
  if i % 2 == 1
80
80
  (cells.empty? ? cells : cells.last) << str
81
81
  else
@@ -86,8 +86,8 @@ module Kramdown
86
86
  root.children.each do |c|
87
87
  if c.type == :raw_text
88
88
  # Only on Ruby 1.9: f, *l = c.value.split(/(?<!\\)\|/).map {|t| t.gsub(/\\\|/, '|')}
89
- f, *l = c.value.split(/\\\|/).map {|t| t.split(/\|/)}.inject([]) do |memo, t|
90
- memo.last << "|" << t.shift if memo.size > 0
89
+ f, *l = c.value.split(/\\\|/, -1).map {|t| t.split(/\|/, -1)}.inject([]) do |memo, t|
90
+ memo.last << "|#{t.shift}" if memo.size > 0
91
91
  memo.concat(t)
92
92
  end
93
93
  (cells.empty? ? cells : cells.last) << f
@@ -26,9 +26,9 @@ module Kramdown
26
26
 
27
27
  # Provides convenience methods for HTML related tasks.
28
28
  #
29
- # *Note* that this module has to be mixed into a class that has a <tt>@root</tt> (containing an
30
- # element of type :root) and an <tt>@options</tt> (containing an options hash) instance variable
31
- # so that some of the methods can work correctly.
29
+ # *Note* that this module has to be mixed into a class that has a @root (containing an element
30
+ # of type :root) and an @options (containing an options hash) instance variable so that some of
31
+ # the methods can work correctly.
32
32
  module Html
33
33
 
34
34
  # Convert the entity +e+ to a string. The optional parameter +original+ may contain the
@@ -71,10 +71,9 @@ module Kramdown
71
71
  # :startdoc:
72
72
 
73
73
  # Escape the special HTML characters in the string +str+. The parameter +type+ specifies what
74
- # is escaped: <tt>:all</tt> - all special HTML characters as well as entities, <tt>:text</tt>
75
- # \- all special HTML characters except the quotation mark but no entities and
76
- # <tt>:attribute</tt> - all special HTML characters including the quotation mark but no
77
- # entities.
74
+ # is escaped: :all - all special HTML characters as well as entities, :text - all special HTML
75
+ # characters except the quotation mark but no entities and :attribute - all special HTML
76
+ # characters including the quotation mark but no entities.
78
77
  def escape_html(str, type = :all)
79
78
  str.gsub(ESCAPE_RE_FROM_TYPE[type]) {|m| ESCAPE_MAP[m] || m}
80
79
  end
@@ -51,6 +51,11 @@ module Kramdown
51
51
  @data[key]
52
52
  end
53
53
 
54
+ # Return +true+ if the hash contains the key.
55
+ def has_key?(key)
56
+ @data.has_key?(key)
57
+ end
58
+
54
59
  # Set the value for the +key+ to +val+.
55
60
  def []=(key, val)
56
61
  @order << key if !@data.has_key?(key)
@@ -68,6 +73,18 @@ module Kramdown
68
73
  self
69
74
  end
70
75
 
76
+ def dup #:nodoc:
77
+ new_object = super
78
+ new_object.instance_variable_set(:@data, @data.dup)
79
+ new_object.instance_variable_set(:@order, @order.dup)
80
+ new_object
81
+ end
82
+
83
+ def ==(other) #:nodoc:
84
+ return false unless other.kind_of?(self.class)
85
+ @data == other.instance_variable_get(:@data) && @order == other.instance_variable_get(:@order)
86
+ end
87
+
71
88
  def inspect #:nodoc:
72
89
  "{" + map {|k,v| "#{k.inspect}=>#{v.inspect}"}.join(" ") + "}"
73
90
  end
@@ -23,6 +23,6 @@
23
23
  module Kramdown
24
24
 
25
25
  # The kramdown version.
26
- VERSION = '0.13.2'
26
+ VERSION = '0.13.3'
27
27
 
28
28
  end
data/test/test_files.rb CHANGED
@@ -159,4 +159,39 @@ class TestFiles < Test::Unit::TestCase
159
159
  end
160
160
  end
161
161
 
162
+
163
+
164
+ # Generate test methods for asserting that converters don't modify the document tree.
165
+ Dir[File.dirname(__FILE__) + '/testcases/**/*.text'].each do |text_file|
166
+ basename = text_file.sub(/\.text$/, '')
167
+ opts_file = text_file.sub(/\.text$/, '.options')
168
+ options = File.exist?(opts_file) ? YAML::load(File.read(opts_file)) : {:auto_ids => false, :footnote_nr => 1}
169
+ (Kramdown::Converter.constants.map {|c| c.to_sym} - [:Base]).each do |conv_class|
170
+ define_method("test_whether_#{conv_class}_modifies_tree_with_file_#{text_file.tr('.', '_')}") do
171
+ doc = Kramdown::Document.new(File.read(text_file), options)
172
+ options_before = Marshal.load(Marshal.dump(doc.options))
173
+ tree_before = Marshal.load(Marshal.dump(doc.root))
174
+ Kramdown::Converter.const_get(conv_class).convert(doc.root, doc.options)
175
+ assert_equal(options_before, doc.options)
176
+ assert_tree_not_changed(tree_before, doc.root)
177
+ end
178
+ end
179
+ end
180
+
181
+ def assert_tree_not_changed(old, new)
182
+ assert_equal(old.type, new.type, "type mismatch")
183
+ if old.value.kind_of?(Kramdown::Element)
184
+ assert_tree_not_changed(old.value, new.value)
185
+ else
186
+ assert_equal(old.value, new.value, "value mismatch")
187
+ end
188
+ assert_equal(old.attr, new.attr, "attr mismatch")
189
+ assert_equal(old.options, new.options, "options mismatch")
190
+ assert_equal(old.children.length, new.children.length, "children count mismatch")
191
+
192
+ old.children.each_with_index do |child, index|
193
+ assert_tree_not_changed(child, new.children[index])
194
+ end
195
+ end
196
+
162
197
  end
@@ -1,14 +1,14 @@
1
1
  <table class="examples">
2
- <tr>
3
- <th><em>Usage</em></th>
4
- <th>
2
+ <tr>
3
+ <th><em>Usage</em></th>
4
+ <th>
5
5
  Output
6
6
  </th>
7
- </tr>
8
- <tr>
9
- <td>Some <em>data</em></td>
10
- <td>
7
+ </tr>
8
+ <tr>
9
+ <td>Some <em>data</em></td>
10
+ <td>
11
11
  <h1 id="some-more">Some more</h1>
12
12
  </td>
13
- </tr>
13
+ </tr>
14
14
  </table>
@@ -7,7 +7,7 @@ Output
7
7
  </tr>
8
8
  <tr>
9
9
  <td markdown="span">Some *data*</td>
10
- <td>
10
+ <td markdown="1">
11
11
  # Some more
12
12
  </td>
13
13
  </tr>
@@ -0,0 +1,5 @@
1
+ <h1>header</h1>
2
+
3
+ <div>
4
+ ======
5
+ </div>
@@ -0,0 +1,6 @@
1
+ header
2
+ ======
3
+
4
+ <div>
5
+ ======
6
+ </div>
@@ -2,4 +2,5 @@
2
2
 
3
3
  <p>This is <strong>strong<em>italic</em>, yes!</strong>.</p>
4
4
 
5
- <p>This is <em> not</em> converted, as <em>is </em> this.</p>
5
+ <p>This is <em> not</em> converted, as <em>is
6
+ </em> this.</p>
@@ -1,14 +1,12 @@
1
1
  <table class="examples">
2
- <tr>
3
- <th>Usage</th>
4
- <th>Other</th>
5
- </tr>
6
- <tr>
7
- <td>
8
- Some *data*
9
- </td>
10
- <td>
11
- <p>Some more</p>
12
- </td>
13
- </tr>
2
+ <tr>
3
+ <th>Usage</th>
4
+ <th>Other</th>
5
+ </tr>
6
+ <tr>
7
+ <td>Some *data*</td>
8
+ <td>
9
+ <p>Some more</p>
10
+ </td>
11
+ </tr>
14
12
  </table>
@@ -33,16 +33,16 @@
33
33
  </table>
34
34
 
35
35
  <table class="examples">
36
- <tr>
37
- <th>Usage</th>
38
- <th>Output</th>
39
- </tr>
40
- <tr>
41
- <td>
42
- Some *data*
43
- </td>
44
- <td>
36
+ <tr>
37
+ <th>Usage</th>
38
+ <th>
39
+ Output
40
+ </th>
41
+ </tr>
42
+ <tr>
43
+ <td>Some *data*</td>
44
+ <td>
45
45
  Some more
46
- </td>
47
- </tr>
46
+ </td>
47
+ </tr>
48
48
  </table>
@@ -35,26 +35,21 @@
35
35
  <p>With alignment and superfluous alignment defs</p>
36
36
 
37
37
  <table>
38
- <col />
39
- <col align="left" />
40
- <col align="center" />
41
- <col align="right" />
42
- <col />
43
38
  <thead>
44
39
  <tr>
45
40
  <th>default</th>
46
- <th>left</th>
47
- <th>center</th>
48
- <th>right</th>
41
+ <th style="text-align: left">left</th>
42
+ <th style="text-align: center">center</th>
43
+ <th style="text-align: right">right</th>
49
44
  <th>default</th>
50
45
  </tr>
51
46
  </thead>
52
47
  <tbody>
53
48
  <tr>
54
49
  <td>cell1</td>
55
- <td>cell2</td>
56
- <td>cell3</td>
57
- <td>cell4</td>
50
+ <td style="text-align: left">cell2</td>
51
+ <td style="text-align: center">cell3</td>
52
+ <td style="text-align: right">cell4</td>
58
53
  <td>cell5</td>
59
54
  </tr>
60
55
  </tbody>
@@ -80,23 +75,21 @@
80
75
  <p>Multiple bodies</p>
81
76
 
82
77
  <table>
83
- <col align="center" />
84
- <col />
85
78
  <thead>
86
79
  <tr>
87
- <th>cell1</th>
80
+ <th style="text-align: center">cell1</th>
88
81
  <th>cell2</th>
89
82
  </tr>
90
83
  </thead>
91
84
  <tbody>
92
85
  <tr>
93
- <td>cell3</td>
86
+ <td style="text-align: center">cell3</td>
94
87
  <td>cell4</td>
95
88
  </tr>
96
89
  </tbody>
97
90
  <tbody>
98
91
  <tr>
99
- <td>cell5</td>
92
+ <td style="text-align: center">cell5</td>
100
93
  <td>cell6</td>
101
94
  </tr>
102
95
  </tbody>
@@ -79,6 +79,25 @@
79
79
  </tbody>
80
80
  </table>
81
81
 
82
+ <p>Special cases regarding codespan syntax</p>
83
+
84
+ <table>
85
+ <tbody>
86
+ <tr>
87
+ <td>a</td>
88
+ <td><code>b</code></td>
89
+ </tr>
90
+ </tbody>
91
+ </table>
92
+
93
+ <table>
94
+ <tbody>
95
+ <tr>
96
+ <td><code>a</code></td>
97
+ </tr>
98
+ </tbody>
99
+ </table>
100
+
82
101
  <table class="cls">
83
102
  <tbody>
84
103
  <tr>
@@ -79,6 +79,25 @@
79
79
  </tbody>
80
80
  </table>
81
81
 
82
+ <p>Special cases regarding codespan syntax</p>
83
+
84
+ <table>
85
+ <tbody>
86
+ <tr>
87
+ <td>a</td>
88
+ <td><code>b</code></td>
89
+ </tr>
90
+ </tbody>
91
+ </table>
92
+
93
+ <table>
94
+ <tbody>
95
+ <tr>
96
+ <td><code>a</code></td>
97
+ </tr>
98
+ </tbody>
99
+ </table>
100
+
82
101
  <table class="cls">
83
102
  <tbody>
84
103
  <tr>
@@ -20,6 +20,12 @@ Table with code elements
20
20
  | This is a <code>span | with</code> a pipe.
21
21
  | Some <em>span | </em> here | a <code>span | with</code> a | pipe.
22
22
 
23
+ Special cases regarding codespan syntax
24
+
25
+ |a|`b`
26
+
27
+ |`a`
28
+
23
29
  {:.cls}
24
30
  | table | with | ial
25
31
 
@@ -0,0 +1,25 @@
1
+ <table>
2
+ <tbody>
3
+ <tr>
4
+ <td>this is <sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup></td>
5
+ <td>a table</td>
6
+ </tr>
7
+ <tr>
8
+ <td>with a</td>
9
+ <td>footnote</td>
10
+ </tr>
11
+ </tbody>
12
+ </table>
13
+
14
+ <div class="footnotes">
15
+ <ol>
16
+ <li id="fn:1">
17
+ <p>Something</p>
18
+
19
+ <blockquote>
20
+ <p>special here</p>
21
+ </blockquote>
22
+ <p><a href="#fnref:1" rev="footnote">&#8617;</a></p>
23
+ </li>
24
+ </ol>
25
+ </div>