kramdown 0.8.0 → 0.9.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 (69) hide show
  1. data/CONTRIBUTERS +2 -1
  2. data/ChangeLog +454 -0
  3. data/README +1 -1
  4. data/VERSION +1 -1
  5. data/doc/{default.less.css → default.scss.css} +12 -9
  6. data/doc/documentation.page +1 -1
  7. data/doc/index.page +37 -3
  8. data/doc/syntax.page +10 -7
  9. data/lib/kramdown/converter.rb +1 -0
  10. data/lib/kramdown/converter/html.rb +61 -67
  11. data/lib/kramdown/converter/kramdown.rb +398 -0
  12. data/lib/kramdown/converter/latex.rb +274 -276
  13. data/lib/kramdown/document.rb +2 -0
  14. data/lib/kramdown/options.rb +16 -15
  15. data/lib/kramdown/parser/base.rb +0 -1
  16. data/lib/kramdown/parser/html.rb +122 -27
  17. data/lib/kramdown/parser/kramdown.rb +2 -0
  18. data/lib/kramdown/parser/kramdown/attribute_list.rb +2 -0
  19. data/lib/kramdown/parser/kramdown/extension.rb +2 -1
  20. data/lib/kramdown/parser/kramdown/html.rb +2 -2
  21. data/lib/kramdown/parser/kramdown/html_entity.rb +1 -1
  22. data/lib/kramdown/parser/kramdown/link.rb +5 -2
  23. data/lib/kramdown/parser/kramdown/list.rb +13 -9
  24. data/lib/kramdown/parser/kramdown/math.rb +1 -1
  25. data/lib/kramdown/parser/kramdown/typographic_symbol.rb +4 -4
  26. data/lib/kramdown/utils.rb +36 -0
  27. data/lib/kramdown/utils/entities.rb +338 -0
  28. data/lib/kramdown/utils/html.rb +72 -0
  29. data/lib/kramdown/version.rb +1 -1
  30. data/man/man1/kramdown.1 +20 -17
  31. data/test/run_tests.rb +1 -1
  32. data/test/test_files.rb +60 -3
  33. data/test/testcases/block/06_codeblock/whitespace.html +2 -2
  34. data/test/testcases/block/07_horizontal_rule/error.html.19 +7 -0
  35. data/test/testcases/block/09_html/html_to_native/code.html +1 -1
  36. data/test/testcases/block/09_html/html_to_native/code.text +1 -1
  37. data/test/testcases/block/09_html/html_to_native/table_simple.html +38 -2
  38. data/test/testcases/block/09_html/html_to_native/table_simple.text +42 -0
  39. data/test/testcases/block/09_html/html_to_native/typography.html.19 +1 -0
  40. data/test/testcases/block/09_html/simple.html.19 +62 -0
  41. data/test/testcases/block/11_ial/simple.html +3 -2
  42. data/test/testcases/block/12_extension/comment.html +3 -2
  43. data/test/testcases/block/12_extension/options.html +0 -3
  44. data/test/testcases/block/12_extension/options.text +0 -6
  45. data/test/testcases/block/13_definition_list/item_ial.html +14 -0
  46. data/test/testcases/block/13_definition_list/item_ial.text +8 -0
  47. data/test/testcases/block/16_toc/no_toc_depth.html +33 -0
  48. data/test/testcases/block/16_toc/no_toc_depth.options +1 -0
  49. data/test/testcases/block/16_toc/no_toc_depth.text +16 -0
  50. data/test/testcases/block/16_toc/toc_depth_2.html +24 -0
  51. data/test/testcases/block/16_toc/toc_depth_2.options +1 -0
  52. data/test/testcases/block/16_toc/toc_depth_2.text +16 -0
  53. data/test/testcases/span/01_link/empty.html +2 -0
  54. data/test/testcases/span/01_link/empty.text +2 -0
  55. data/test/testcases/span/01_link/imagelinks.html +2 -0
  56. data/test/testcases/span/01_link/imagelinks.text +2 -0
  57. data/test/testcases/span/01_link/inline.html.19 +40 -0
  58. data/test/testcases/span/01_link/reference.html.19 +32 -0
  59. data/test/testcases/span/extension/comment.html +3 -3
  60. data/test/testcases/span/text_substitutions/entities.html.19 +4 -0
  61. data/test/testcases/span/text_substitutions/entities_numeric.html +1 -0
  62. data/test/testcases/span/text_substitutions/entities_numeric.html.19 +1 -0
  63. data/test/testcases/span/text_substitutions/entities_numeric.options +1 -0
  64. data/test/testcases/span/text_substitutions/entities_numeric.text +1 -0
  65. data/test/testcases/span/text_substitutions/typography.html.19 +18 -0
  66. metadata +30 -10
  67. data/test/testcases/block/09_html/filtered_html.html +0 -1
  68. data/test/testcases/block/09_html/filtered_html.options +0 -1
  69. data/test/testcases/block/09_html/filtered_html.text +0 -1
@@ -23,6 +23,6 @@
23
23
  module Kramdown
24
24
 
25
25
  # The kramdown version.
26
- VERSION = '0.8.0'
26
+ VERSION = '0.9.0'
27
27
 
28
28
  end
data/man/man1/kramdown.1 CHANGED
@@ -133,23 +133,6 @@ Default: 1
133
133
  Used by: HTML converter
134
134
 
135
135
 
136
- .TP
137
- .B \-\-filter_html ARG
138
-
139
- NOTE: This option is deprecated and will be removed in a future release!
140
-
141
- An array of HTML tags that should be filtered from the output
142
-
143
- The value can either be specified as array or as a space separated
144
- string (which will be converted to an array). All HTML tags that are
145
- listed in the array will be filtered from the output, i.e. only their
146
- contents is used. This applies only to HTML tags found in the initial
147
- document.
148
-
149
- Default: []
150
- Used by: HTML converter
151
-
152
-
153
136
  .TP
154
137
  .B \-\-coderay_wrap ARG
155
138
 
@@ -212,6 +195,26 @@ Default: style
212
195
  Used by: HTML converter
213
196
 
214
197
 
198
+ .TP
199
+ .B \-\-[no\-]numeric_entities
200
+
201
+ Defines whether entities are output using names or numeric values
202
+
203
+ Default: false
204
+ Used by: HTML converter, kramdown converter
205
+
206
+
207
+ .TP
208
+ .B \-\-toc_depth ARG
209
+
210
+ Defines the maximum level of headers which will be used to generate the table of
211
+ contents. For instance, with a value of 2, toc entries will be generated for h1
212
+ and h2 headers but not for h3, h4, etc. A value of 0 uses all header levels.
213
+
214
+ Default: 0
215
+ Used by: HTML/Latex converter
216
+
217
+
215
218
  .SH SEE ALSO
216
219
  The kramdown website, http://kramdown.rubyforge.org/ for more information, especially on the support
217
220
  input syntax.
data/test/run_tests.rb CHANGED
@@ -45,7 +45,7 @@ Dir[arg].each {|f| fwidth = [fwidth, f.length + 10].max }.each do |file|
45
45
  html_file = file.sub('.text', '.html')
46
46
  opts_file = file.sub('.text', '.options')
47
47
  opts_file = File.join(File.dirname(file), 'options') if !File.exist?(opts_file)
48
- options = File.exist?(opts_file) ? YAML::load(File.read(opts_file)) : {:auto_ids => false, :filter_html => [], :footnote_nr => 1}
48
+ options = File.exist?(opts_file) ? YAML::load(File.read(opts_file)) : {:auto_ids => false, :footnote_nr => 1}
49
49
  doc = Kramdown::Document.new(File.read(file), options)
50
50
  begin
51
51
  assert_equal(File.read(html_file), doc.to_html)
data/test/test_files.rb CHANGED
@@ -25,6 +25,8 @@ require 'kramdown'
25
25
  require 'yaml'
26
26
  require 'tmpdir'
27
27
 
28
+ Encoding.default_external = 'utf-8' if RUBY_VERSION >= '1.9'
29
+
28
30
  class TestFiles < Test::Unit::TestCase
29
31
 
30
32
  # Generate test methods for kramdown-to-xxx conversion
@@ -32,11 +34,13 @@ class TestFiles < Test::Unit::TestCase
32
34
  basename = text_file.sub(/\.text$/, '')
33
35
  opts_file = text_file.sub(/\.text$/, '.options')
34
36
  (Dir[basename + ".*"] - [text_file, opts_file]).each do |output_file|
35
- output_format = File.extname(output_file)[1..-1]
37
+ next if (RUBY_VERSION >= '1.9' && File.exist?(output_file + '.19')) ||
38
+ (RUBY_VERSION < '1.9' && output_file =~ /\.19$/)
39
+ output_format = File.extname(output_file.sub(/\.19$/, ''))[1..-1]
36
40
  next if !Kramdown::Converter.const_defined?(output_format[0..0].upcase + output_format[1..-1])
37
41
  define_method('test_' + text_file.tr('.', '_') + "_to_#{output_format}") do
38
42
  opts_file = File.join(File.dirname(text_file), 'options') if !File.exist?(opts_file)
39
- options = File.exist?(opts_file) ? YAML::load(File.read(opts_file)) : {:auto_ids => false, :filter_html => [], :footnote_nr => 1}
43
+ options = File.exist?(opts_file) ? YAML::load(File.read(opts_file)) : {:auto_ids => false, :footnote_nr => 1}
40
44
  doc = Kramdown::Document.new(File.read(text_file), options)
41
45
  assert_equal(File.read(output_file), doc.send("to_#{output_format}"))
42
46
  end
@@ -61,7 +65,8 @@ class TestFiles < Test::Unit::TestCase
61
65
  end
62
66
 
63
67
  def tidy_output(out)
64
- result = IO.popen("tidy -q -raw 2>/dev/null", 'r+') do |io|
68
+ cmd = "tidy -q --doctype omit #{RUBY_VERSION >= '1.9' ? '-utf8' : '-raw'} 2>/dev/null"
69
+ result = IO.popen(cmd, 'r+') do |io|
65
70
  io.write(out)
66
71
  io.close_write
67
72
  io.read
@@ -97,4 +102,56 @@ class TestFiles < Test::Unit::TestCase
97
102
  end
98
103
  end
99
104
 
105
+ # Generate test methods for text->kramdown->html conversion
106
+ `tidy -v 2>&1`
107
+ if $?.exitstatus != 0
108
+ warn("Skipping text->kramdown->html tests because tidy executable is missing")
109
+ else
110
+ EXCLUDE_TEXT_FILES = ['test/testcases/span/05_html/markdown_attr.text', # bc of markdown attr
111
+ 'test/testcases/block/09_html/markdown_attr.text', # bc of markdown attr
112
+ 'test/testcases/span/extension/options.text', # bc of parse_span_html option
113
+ 'test/testcases/block/12_extension/options.text', # bc of options option
114
+ 'test/testcases/block/12_extension/options3.text', # bc of options option
115
+ 'test/testcases/block/09_html/content_model/tables.text', # bc of parse_block_html option
116
+ 'test/testcases/block/09_html/html_to_native/header.text', # bc of auto_ids option that interferes
117
+ 'test/testcases/block/09_html/simple.text', # bc of webgen:block elements
118
+ ]
119
+ Dir[File.dirname(__FILE__) + '/testcases/**/*.text'].each do |text_file|
120
+ next if EXCLUDE_TEXT_FILES.any? {|f| text_file =~ /#{f}$/}
121
+ define_method('test_' + text_file.tr('.', '_') + "_to_kramdown_to_html") do
122
+ html_file = text_file.sub(/\.text$/, '.html')
123
+ html_file += '.19' if RUBY_VERSION >= '1.9' && File.exist?(html_file + '.19')
124
+ opts_file = text_file.sub(/\.text$/, '.options')
125
+ opts_file = File.join(File.dirname(text_file), 'options') if !File.exist?(opts_file)
126
+ options = File.exist?(opts_file) ? YAML::load(File.read(opts_file)) : {:auto_ids => false, :footnote_nr => 1}
127
+ kdtext = Kramdown::Document.new(File.read(text_file), options).to_kramdown
128
+ html = Kramdown::Document.new(kdtext, options).to_html
129
+ assert_equal(tidy_output(File.read(html_file)), tidy_output(html))
130
+ end
131
+ end
132
+ end
133
+
134
+ # Generate test methods for html-to-kramdown-to-html conversion
135
+ `tidy -v 2>&1`
136
+ if $?.exitstatus != 0
137
+ warn("Skipping html-to-kramdown-to-html tests because tidy executable is missing")
138
+ else
139
+ EXCLUDE_HTML_KD_FILES = ['test/testcases/span/extension/options.html', # bc of parse_span_html option
140
+ 'test/testcases/span/05_html/normal.html', # bc of br tag before closing p tag
141
+ 'test/testcases/block/12_extension/nomarkdown.html', # bc of nomarkdown extension
142
+ 'test/testcases/block/09_html/simple.html', # bc of webgen:block elements
143
+ 'test/testcases/block/09_html/markdown_attr.html', # bc of markdown attr
144
+ 'test/testcases/block/09_html/html_to_native/table_simple.html', # bc of invalidly converted simple table
145
+ 'test/testcases/block/06_codeblock/whitespace.html', # bc of entity to char conversion
146
+ ]
147
+ Dir[File.dirname(__FILE__) + '/testcases/**/*.html'].each do |html_file|
148
+ next if EXCLUDE_HTML_KD_FILES.any? {|f| html_file =~ /#{f}$/}
149
+ define_method('test_' + html_file.tr('.', '_') + "_to_kramdown_to_html") do
150
+ kd = Kramdown::Document.new(File.read(html_file), :input => 'html', :auto_ids => false, :footnote_nr => 1).to_kramdown
151
+ doc = Kramdown::Document.new(kd, :auto_ids => false, :footnote_nr => 1)
152
+ assert_equal(tidy_output(File.read(html_file)), tidy_output(doc.to_html))
153
+ end
154
+ end
155
+ end
156
+
100
157
  end
@@ -1,3 +1,3 @@
1
- <pre class="show-whitespaces"><code>This<span class="ws-tab"> </span>is<span class="ws-space">&sdot;</span>some<span class="ws-space-r">&sdot;</span><span class="ws-space-r">&sdot;</span>
2
- <span class="ws-space-l">&sdot;</span><span class="ws-space-l">&sdot;</span><span class="ws-space-l">&sdot;</span><span class="ws-space-l">&sdot;</span>whitespace<span class="ws-space-r">&sdot;</span><span class="ws-space-r">&sdot;</span>
1
+ <pre class="show-whitespaces"><code>This<span class="ws-tab"> </span>is<span class="ws-space">&#8901;</span>some<span class="ws-space-r">&#8901;</span><span class="ws-space-r">&#8901;</span>
2
+ <span class="ws-space-l">&#8901;</span><span class="ws-space-l">&#8901;</span><span class="ws-space-l">&#8901;</span><span class="ws-space-l">&#8901;</span>whitespace<span class="ws-space-r">&#8901;</span><span class="ws-space-r">&#8901;</span>
3
3
  </code></pre>
@@ -0,0 +1,7 @@
1
+ <p>_ * _</p>
2
+
3
+ <p>— * * *</p>
4
+
5
+ <p>_ - *</p>
6
+
7
+ <p>———————————————- test</p>
@@ -6,5 +6,5 @@ This is a <code>simple code</code> span.</p>
6
6
  <pre><code>Some very important &lt; thing
7
7
  </code></pre>
8
8
 
9
- <pre><code>Some code&sdot;&sdot;
9
+ <pre><code>Some code&lt;&lt;
10
10
  </code></pre>
@@ -5,5 +5,5 @@ This is a <code>simple code</code> span.
5
5
 
6
6
  <pre>Some very important <b>&lt;</b> thing</pre>
7
7
 
8
- <pre><code>Some code<span>&sdot;</span>&sdot;
8
+ <pre><code>Some code<span>&lt;</span>&lt;
9
9
  </code></pre>
@@ -1,10 +1,46 @@
1
+ <table class="examples">
2
+ <tbody>
3
+ <tr>
4
+ <td>Usage</td>
5
+ <td>Output</td>
6
+ </tr>
7
+ <tr>
8
+ <td>Some *data*</td>
9
+ <td>Some more</td>
10
+ </tr>
11
+ </tbody>
12
+ </table>
13
+
14
+ <table class="examples">
15
+ <thead>
16
+ <tr>
17
+ <th>Usage</th>
18
+ <th>Output</th>
19
+ </tr>
20
+ </thead>
21
+ <tbody>
22
+ <tr>
23
+ <td>Some *data*</td>
24
+ <td>Some more</td>
25
+ </tr>
26
+ </tbody>
27
+ <tfoot>
28
+ <tr>
29
+ <td>foot</td>
30
+ <td>locker</td>
31
+ </tr>
32
+ </tfoot>
33
+ </table>
34
+
1
35
  <table class="examples">
2
36
  <tr>
3
37
  <th>Usage</th>
4
38
  <th>Output</th>
5
39
  </tr>
6
40
  <tr>
7
- <td>Some *data*</td>
8
- <td>Some more</td>
41
+ <td>
42
+ Some *data* </td>
43
+ <td>
44
+ Some more </td>
9
45
  </tr>
10
46
  </table>
@@ -1,3 +1,45 @@
1
+ <table class="examples">
2
+ <tr>
3
+ <td>Usage</td>
4
+ <td>
5
+ Output
6
+ </td>
7
+ </tr>
8
+ <tr>
9
+ <td>Some *data*</td>
10
+ <td>
11
+ Some more
12
+ </td>
13
+ </tr>
14
+ </table>
15
+
16
+ <table class="examples">
17
+ <thead>
18
+ <tr>
19
+ <th>Usage</th>
20
+ <th>
21
+ Output
22
+ </th>
23
+ </tr>
24
+ </thead>
25
+ <tbody>
26
+ <tr>
27
+ <td>Some *data*</td>
28
+ <td>
29
+ Some more
30
+ </td>
31
+ </tr>
32
+ </tbody>
33
+ <tfoot>
34
+ <tr>
35
+ <td>foot</td>
36
+ <td>
37
+ locker
38
+ </td>
39
+ </tr>
40
+ </tfoot>
41
+ </table>
42
+
1
43
  <table class="examples">
2
44
  <tr>
3
45
  <th>Usage</th>
@@ -0,0 +1 @@
1
+ <p>This is … something “to remember”!</p>
@@ -0,0 +1,62 @@
1
+ <div>
2
+ <p>test</p>
3
+ </div>
4
+
5
+ <p>
6
+ para2
7
+ </p>
8
+
9
+ <div id="test">
10
+ <p>tes</p>
11
+
12
+ <p>test
13
+ weiter
14
+ </p>
15
+ </div>
16
+
17
+ <p>para4</p>
18
+
19
+ <div>
20
+ <div>
21
+ <div>
22
+ <p>foo</p>
23
+ </div>
24
+ <div style="&nbsp;"></div>
25
+ </div>
26
+ <div>
27
+ <p>bar </p>
28
+ </div>
29
+ </div>
30
+
31
+ <p>para5</p>
32
+
33
+ <div>
34
+ <p>id</p>
35
+ </div>
36
+ <p>test</p>
37
+
38
+ <div>
39
+ <p>hallo</p>
40
+ </div>
41
+ <div>
42
+ <p>hallo</p>
43
+ </div>
44
+
45
+ <p>para6</p>
46
+
47
+ <div>
48
+ <div class="clear"></div>
49
+ <p>Another para.</p>
50
+ </div>
51
+
52
+ <webgen:block name="test" />
53
+
54
+ <some:url name:spac="hallo">doit</some:url>
55
+
56
+ <p><em>Test</em></p>
57
+
58
+ <p><em>Test</em></p>
59
+
60
+ <p><em>Test
61
+ </em>
62
+ </p>
@@ -18,8 +18,9 @@
18
18
 
19
19
  <p class="cls">Some paragraph here</p>
20
20
 
21
- <p class="cls">Paragraph
22
- Paragraph</p>
21
+ <p class="cls">Paragraph</p>
22
+ <p>Paragraph</p>
23
23
 
24
24
  <h1 class="class" id="other">Another header</h1>
25
25
 
26
+
@@ -1,5 +1,6 @@
1
- <p>This is a simple paragraph.
2
- And another paragraph</p>
1
+ <p>This is a simple paragraph.</p>
2
+ <!-- This is a comment {:/}which is {:/comment} ignored. -->
3
+ <p>And another paragraph</p>
3
4
 
4
5
  <p>Paragraph
5
6
  Another paragraph</p>
@@ -10,9 +10,6 @@ some <span>*para*</span>
10
10
  <p>some <span><em>para</em></span></p>
11
11
  </div>
12
12
 
13
-
14
- This is some text.
15
-
16
13
  <p>Some text<sup id="fnref:ab"><a href="#fn:ab" rel="footnote">10</a></sup>.</p>
17
14
 
18
15
  <div class="footnotes">
@@ -14,12 +14,6 @@ some <span>*para*</span>
14
14
  some <span>*para*</span>
15
15
  </div>
16
16
 
17
- {::options auto_ids="false" filter_html="p em" /}
18
-
19
- <p>
20
- This is <em>some</em> text.
21
- </p>
22
-
23
17
  {::options footnote_nr="10" /}
24
18
 
25
19
  Some text[^ab].
@@ -0,0 +1,14 @@
1
+ <dl>
2
+ <dt>item</dt>
3
+ <dd class="cls">definition
4
+ continued</dd>
5
+ <dd>another </dd>
6
+ <dd class="class">
7
+ <pre><code>code
8
+ </code></pre>
9
+ </dd>
10
+ <dd class="cls">IAL at last
11
+ <pre><code>code
12
+ </code></pre>
13
+ </dd>
14
+ </dl>
@@ -0,0 +1,8 @@
1
+ item
2
+ : {:.cls} definition
3
+ continued
4
+ : another {:.cls}
5
+ : {:.class}
6
+ code
7
+ : {:.cls} IAL at last
8
+ code
@@ -0,0 +1,33 @@
1
+ <ul id="markdown-toc">
2
+ <li><a href="#header-level-1">Header level 1</a> <ul>
3
+ <li><a href="#header-level-2">Header level 2</a> <ul>
4
+ <li><a href="#header-level-3">Header level 3</a> <ul>
5
+ <li><a href="#header-level-4">Header level 4</a></li>
6
+ </ul>
7
+ </li>
8
+ </ul>
9
+ </li>
10
+ </ul>
11
+ </li>
12
+ <li><a href="#other-header-level-1">Other header level 1</a> <ul>
13
+ <li><a href="#other-header-level-2">Other header level 2</a> <ul>
14
+ <li><a href="#other-header-level-3">Other header level 3</a></li>
15
+ </ul>
16
+ </li>
17
+ </ul>
18
+ </li>
19
+ </ul>
20
+
21
+ <h1 id="header-level-1">Header level 1</h1>
22
+
23
+ <h2 id="header-level-2">Header level 2</h2>
24
+
25
+ <h3 id="header-level-3">Header level 3</h3>
26
+
27
+ <h4 id="header-level-4">Header level 4</h4>
28
+
29
+ <h1 id="other-header-level-1">Other header level 1</h1>
30
+
31
+ <h2 id="other-header-level-2">Other header level 2</h2>
32
+
33
+ <h3 id="other-header-level-3">Other header level 3</h3>