kramdown 0.7.0 → 0.8.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 (93) hide show
  1. data/CONTRIBUTERS +4 -0
  2. data/ChangeLog +671 -0
  3. data/README +10 -0
  4. data/Rakefile +40 -23
  5. data/VERSION +1 -1
  6. data/data/kramdown/document.html +1 -1
  7. data/data/kramdown/document.latex +10 -5
  8. data/doc/default.less.css +52 -10
  9. data/doc/default.template +4 -0
  10. data/doc/documentation.page +72 -0
  11. data/doc/index.page +8 -41
  12. data/doc/installation.page +6 -6
  13. data/doc/links.markdown +2 -0
  14. data/doc/quickref.page +6 -2
  15. data/doc/syntax.page +8 -7
  16. data/doc/tests.page +1 -2
  17. data/lib/kramdown.rb +1 -1
  18. data/lib/kramdown/compatibility.rb +1 -1
  19. data/lib/kramdown/converter.rb +8 -3
  20. data/lib/kramdown/converter/base.rb +27 -5
  21. data/lib/kramdown/converter/html.rb +26 -28
  22. data/lib/kramdown/converter/latex.rb +29 -15
  23. data/lib/kramdown/document.rb +15 -8
  24. data/lib/kramdown/error.rb +1 -1
  25. data/lib/kramdown/options.rb +21 -13
  26. data/lib/kramdown/parser.rb +9 -3
  27. data/lib/kramdown/parser/base.rb +95 -0
  28. data/lib/kramdown/parser/html.rb +387 -0
  29. data/lib/kramdown/parser/kramdown.rb +11 -56
  30. data/lib/kramdown/parser/kramdown/attribute_list.rb +1 -1
  31. data/lib/kramdown/parser/kramdown/autolink.rb +1 -1
  32. data/lib/kramdown/parser/kramdown/blank_line.rb +1 -1
  33. data/lib/kramdown/parser/kramdown/blockquote.rb +1 -1
  34. data/lib/kramdown/parser/kramdown/codeblock.rb +1 -1
  35. data/lib/kramdown/parser/kramdown/codespan.rb +1 -1
  36. data/lib/kramdown/parser/kramdown/emphasis.rb +1 -1
  37. data/lib/kramdown/parser/kramdown/eob.rb +1 -1
  38. data/lib/kramdown/parser/kramdown/escaped_chars.rb +1 -1
  39. data/lib/kramdown/parser/kramdown/extension.rb +2 -90
  40. data/lib/kramdown/parser/kramdown/footnote.rb +1 -1
  41. data/lib/kramdown/parser/kramdown/header.rb +1 -1
  42. data/lib/kramdown/parser/kramdown/horizontal_rule.rb +1 -1
  43. data/lib/kramdown/parser/kramdown/html.rb +69 -149
  44. data/lib/kramdown/parser/kramdown/html_entity.rb +4 -4
  45. data/lib/kramdown/parser/kramdown/line_break.rb +1 -1
  46. data/lib/kramdown/parser/kramdown/link.rb +2 -2
  47. data/lib/kramdown/parser/kramdown/list.rb +2 -6
  48. data/lib/kramdown/parser/kramdown/math.rb +3 -3
  49. data/lib/kramdown/parser/kramdown/paragraph.rb +1 -1
  50. data/lib/kramdown/parser/kramdown/smart_quotes.rb +3 -2
  51. data/lib/kramdown/parser/kramdown/table.rb +3 -2
  52. data/lib/kramdown/parser/kramdown/typographic_symbol.rb +7 -3
  53. data/lib/kramdown/version.rb +2 -2
  54. data/man/man1/kramdown.1 +19 -0
  55. data/test/run_tests.rb +1 -0
  56. data/test/test_files.rb +68 -7
  57. data/test/testcases/block/09_html/comment.html +5 -0
  58. data/test/testcases/block/09_html/comment.text +3 -0
  59. data/test/testcases/block/09_html/content_model/tables.html +2 -2
  60. data/test/testcases/block/09_html/html_to_native/code.html +10 -0
  61. data/test/testcases/block/09_html/html_to_native/code.text +9 -0
  62. data/test/testcases/block/09_html/html_to_native/comment.html +7 -0
  63. data/test/testcases/block/09_html/html_to_native/comment.text +8 -0
  64. data/test/testcases/block/09_html/html_to_native/emphasis.html +1 -0
  65. data/test/testcases/block/09_html/html_to_native/emphasis.text +1 -0
  66. data/test/testcases/block/09_html/html_to_native/entity.html +1 -0
  67. data/test/testcases/block/09_html/html_to_native/entity.text +1 -0
  68. data/test/testcases/block/09_html/html_to_native/header.html +6 -0
  69. data/test/testcases/block/09_html/html_to_native/header.options +2 -0
  70. data/test/testcases/block/09_html/html_to_native/header.text +6 -0
  71. data/test/testcases/block/09_html/html_to_native/list_dl.html +8 -0
  72. data/test/testcases/block/09_html/html_to_native/list_dl.text +8 -0
  73. data/test/testcases/block/09_html/html_to_native/list_ol.html +15 -0
  74. data/test/testcases/block/09_html/html_to_native/list_ol.text +17 -0
  75. data/test/testcases/block/09_html/html_to_native/list_ul.html +19 -0
  76. data/test/testcases/block/09_html/html_to_native/list_ul.text +22 -0
  77. data/test/testcases/block/09_html/html_to_native/options +1 -0
  78. data/test/testcases/block/09_html/html_to_native/paragraph.html +3 -0
  79. data/test/testcases/block/09_html/html_to_native/paragraph.text +4 -0
  80. data/test/testcases/block/09_html/html_to_native/table_normal.html +13 -0
  81. data/test/testcases/block/09_html/html_to_native/table_normal.text +12 -0
  82. data/test/testcases/block/09_html/html_to_native/table_simple.html +10 -0
  83. data/test/testcases/block/09_html/html_to_native/table_simple.text +14 -0
  84. data/test/testcases/block/09_html/html_to_native/typography.html +1 -0
  85. data/test/testcases/block/09_html/html_to_native/typography.text +1 -0
  86. data/test/testcases/block/09_html/parse_as_raw.html +3 -5
  87. data/test/testcases/block/09_html/parse_as_raw.text +0 -1
  88. data/test/testcases/span/04_footnote/definitions.latex +18 -0
  89. data/test/testcases/span/04_footnote/footnote_nr.latex +6 -0
  90. data/test/testcases/span/04_footnote/markers.latex +32 -0
  91. data/test/testcases/span/05_html/invalid.html +1 -0
  92. data/test/testcases/span/05_html/invalid.text +1 -0
  93. metadata +52 -5
@@ -2,3 +2,5 @@
2
2
  [PHP Markdown Extra]: http://michelf.com/projects/php-markdown/extra/
3
3
  [Pandoc]: http://johnmacfarlane.net/pandoc/
4
4
  [jsMath]: http://www.math.union.edu/~dpvc/jsMath/
5
+ [BlueCloth]: http://deveiate.org/projects/BlueCloth
6
+ [RedCloth]: http://redcloth.org/
@@ -2,7 +2,11 @@
2
2
  title: Quick Reference
3
3
  in_menu: true
4
4
  sort_info: 9
5
- ---
5
+ --- name:sidebar
6
+ <h1>Contents</h1>
7
+
8
+ {menu: {used_nodes: fragments, min_levels: 4, max_levels: 6}}
9
+ --- name:content
6
10
  # Quick Reference
7
11
 
8
12
  Below are examples of all available structural elements that can be used in a kramdown text. Since
@@ -22,7 +26,7 @@ appears in the browser. This looks like this:
22
26
  <div class="kdexample">
23
27
  <pre class="kdexample-before"><code>kramdown example code</code></pre>
24
28
  <pre class="kdexample-after-source"><code>Example code converted to HTML</code></pre>
25
- <div class="kdexample-after-live">
29
+ <div class="kdexample-after-live" style="clear:none">
26
30
  Live browser view of example code
27
31
  </div>
28
32
  </div>
@@ -2,15 +2,16 @@
2
2
  title: Syntax
3
3
  in_menu: true
4
4
  sort_info: 10
5
- ---
6
- This is version **<%= ::Kramdown::VERSION %>** of the syntax documentation.
7
-
8
- Table of Contents:
5
+ --- name:sidebar
6
+ <h1>Contents</h1>
9
7
 
10
- {menu: {used_nodes: fragments, min_levels: 3}}
8
+ {menu: {used_nodes: fragments, min_levels: 4, max_levels: 6}}
9
+ --- name:content
11
10
 
12
11
  # kramdown Syntax
13
12
 
13
+ This is version **<%= ::Kramdown::VERSION %>** of the syntax documentation.
14
+
14
15
  The kramdown syntax is based on the Markdown syntax and has been enhanced with features that are
15
16
  found in other Markdown implementations like [Maruku], [PHP Markdown Extra] and [Pandoc]. However,
16
17
  it strives to provide a strict syntax with definite rules and therefore isn't completely compatible
@@ -867,13 +868,13 @@ Parse as raw HTML block
867
868
  Parse as block level elements
868
869
  :
869
870
  applet button blockquote colgroup dd div dl fieldset form iframe li
870
- map noscript object ol table tbody td th thead tfoot tr ul
871
+ map noscript object ol table tbody thead tfoot tr td ul
871
872
 
872
873
  Parse as span level elements
873
874
  :
874
875
  a abbr acronym address b bdo big cite caption code del dfn dt em
875
876
  h1 h2 h3 h4 h5 h6 i ins kbd label legend optgroup p pre q rb rbc
876
- rp rt rtc ruby samp select small span strong sub sup tt var
877
+ rp rt rtc ruby samp select small span strong sub sup th tt var
877
878
 
878
879
  > Remember that all span level HTML tags like `a` or `b` do not start a HTML block! However, the
879
880
  > above lists also include span level HTML tags in the case the `markdown` attribute is used on a
@@ -23,7 +23,6 @@ If you believe you have found a bug in the implementation, please follow these s
23
23
  fashion, please open a bug report and attach two files: one with the text and one with the HTML
24
24
  conversion you think is correct.
25
25
 
26
- ^
27
26
 
28
27
  # Benchmark
29
28
 
@@ -31,7 +30,7 @@ kramdown comes with a small benchmark to test how fast it is in regard to four o
31
30
  implementations: Maruku, BlueFeather, BlueCloth and RDiscount. The first two are written using only
32
31
  Ruby, the latter two use the C discount library for the actual hard work (which makes them really
33
32
  fast but they do not provide additional syntax elements). As one can see below, kramdown is
34
- currently (December 2009) ~5x faster than Maruku, ~10x faster than BlueFeather but ~30x slower than
33
+ currently (June 2010) ~4x faster than Maruku, ~9x faster than BlueFeather but ~30x slower than
35
34
  BlueCloth and rdiscount:
36
35
 
37
36
  <pre><code>
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
3
  #--
4
- # Copyright (C) 2009 Thomas Leitner <t_leitner@gmx.at>
4
+ # Copyright (C) 2009-2010 Thomas Leitner <t_leitner@gmx.at>
5
5
  #
6
6
  # This file is part of kramdown.
7
7
  #
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
3
  #--
4
- # Copyright (C) 2009 Thomas Leitner <t_leitner@gmx.at>
4
+ # Copyright (C) 2009-2010 Thomas Leitner <t_leitner@gmx.at>
5
5
  #
6
6
  # This file is part of kramdown.
7
7
  #
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
3
  #--
4
- # Copyright (C) 2009 Thomas Leitner <t_leitner@gmx.at>
4
+ # Copyright (C) 2009-2010 Thomas Leitner <t_leitner@gmx.at>
5
5
  #
6
6
  # This file is part of kramdown.
7
7
  #
@@ -22,9 +22,14 @@
22
22
 
23
23
  module Kramdown
24
24
 
25
+ # == Converter Module
26
+ #
25
27
  # This module contains all available converters, i.e. classes that take a document and convert the
26
- # document tree to a string in a specific format, for example, HTML. These converters use the Base
27
- # class for common functionality - see its API documentation for how to create a converter class.
28
+ # document tree to a specific output format, normally a string. For example, the Html module
29
+ # converts the document tree into HTML.
30
+ #
31
+ # Converters use the Base class for common functionality (like applying a template to the output)-
32
+ # see its API documentation for how to create a converter class.
28
33
  module Converter
29
34
 
30
35
  autoload :Base, 'kramdown/converter/base'
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
3
  #--
4
- # Copyright (C) 2009 Thomas Leitner <t_leitner@gmx.at>
4
+ # Copyright (C) 2009-2010 Thomas Leitner <t_leitner@gmx.at>
5
5
  #
6
6
  # This file is part of kramdown.
7
7
  #
@@ -26,7 +26,26 @@ module Kramdown
26
26
 
27
27
  module Converter
28
28
 
29
- # This class servers as base class for all converters.
29
+ # == Base class for converters
30
+ #
31
+ # This class serves as base class for all converters. It provides methods that can/should be
32
+ # used by all converters (like #generate_id) as well as common functionality that is
33
+ # automatically applied to the result (for example, embedding the output into a template).
34
+ #
35
+ # == Implementing a converter
36
+ #
37
+ # Implementing a new converter is rather easy: just create a new sub class from this class and
38
+ # put it in the Kramdown::Converter module (the latter is only needed if auto-detection should
39
+ # work properly). Then you need to implement the #convert(tree) method which takes a document
40
+ # tree and should return the converted output.
41
+ #
42
+ # The document instance is automatically set as @doc in Base#initialize. Furthermore, the
43
+ # document instance provides a hash called `conversion_infos` that is also automatically cleared
44
+ # and can be used to store information about the conversion process.
45
+ #
46
+ # The actual transformation of the document tree can be done in any way. However, writing one
47
+ # method per tree element type is a straight forward way to do it - this is how the Html and
48
+ # Latex converters do the transformation.
30
49
  class Base
31
50
 
32
51
  # Initialize the converter with the given Kramdown document +doc+.
@@ -50,13 +69,16 @@ module Kramdown
50
69
  # Apply the template specified in the +doc+ options, using +body+ as the body string.
51
70
  def self.apply_template(doc, body)
52
71
  erb = ERB.new(get_template(doc.options[:template]))
53
- erb.result(binding)
72
+ obj = Object.new
73
+ obj.instance_variable_set(:@doc, doc)
74
+ obj.instance_variable_set(:@body, body)
75
+ erb.result(obj.instance_eval{binding})
54
76
  end
55
77
 
56
78
  # Return the template specified by +template+.
57
79
  def self.get_template(template)
58
80
  format_ext = '.' + self.name.split(/::/).last.downcase
59
- shipped = File.join(Kramdown.data_dir, template + format_ext)
81
+ shipped = File.join(::Kramdown.data_dir, template + format_ext)
60
82
  if File.exist?(template)
61
83
  File.read(template)
62
84
  elsif File.exist?(template + format_ext)
@@ -69,7 +91,7 @@ module Kramdown
69
91
  end
70
92
 
71
93
 
72
- # Generate an alpha-numeric ID from the the string +str+.
94
+ # Generate an unique alpha-numeric ID from the the string +str+ for use as header ID.
73
95
  def generate_id(str)
74
96
  gen_id = str.gsub(/[^a-zA-Z0-9 -]/, '').gsub(/^[^a-zA-Z]*/, '').gsub(' ', '-').downcase
75
97
  gen_id = 'section' if gen_id.length == 0
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
3
  #--
4
- # Copyright (C) 2009 Thomas Leitner <t_leitner@gmx.at>
4
+ # Copyright (C) 2009-2010 Thomas Leitner <t_leitner@gmx.at>
5
5
  #
6
6
  # This file is part of kramdown.
7
7
  #
@@ -82,7 +82,7 @@ module Kramdown
82
82
  end
83
83
 
84
84
  def convert_codeblock(el, indent, opts)
85
- if el.options[:attr] && el.options[:attr]['lang'] && HIGHLIGHTING_AVAILABLE
85
+ if el.value && el.options[:attr] && el.options[:attr]['lang'] && HIGHLIGHTING_AVAILABLE
86
86
  el = Marshal.load(Marshal.dump(el)) # so that the original is not changed
87
87
  opts = {:wrap => @doc.options[:coderay_wrap], :line_numbers => @doc.options[:coderay_line_numbers],
88
88
  :line_number_start => @doc.options[:coderay_line_number_start], :tab_width => @doc.options[:coderay_tab_width],
@@ -90,7 +90,7 @@ module Kramdown
90
90
  result = CodeRay.scan(el.value, el.options[:attr].delete('lang').to_sym).html(opts).chomp + "\n"
91
91
  "#{' '*indent}<div#{options_for_element(el)}>#{result}#{' '*indent}</div>\n"
92
92
  else
93
- result = escape_html(el.value)
93
+ result = (el.value ? escape_html(el.value) : inner(el, indent, opts))
94
94
  if el.options[:attr] && el.options[:attr].has_key?('class') && el.options[:attr]['class'] =~ /\bshow-whitespaces\b/
95
95
  result.gsub!(/(?:(^[ \t]+)|([ \t]+$)|([ \t]+))/) do |m|
96
96
  suffix = ($1 ? '-l' : ($2 ? '-r' : ''))
@@ -125,7 +125,7 @@ module Kramdown
125
125
 
126
126
  def convert_ul(el, indent, opts)
127
127
  if !@toc_code && (el.options[:ial][:refs].include?('toc') rescue nil) && (el.type == :ul || el.type == :ol)
128
- @toc_code = [el.type, (0..128).to_a.map{|a| rand(36).to_s(36)}.join]
128
+ @toc_code = [el.type, el.options[:attr], (0..128).to_a.map{|a| rand(36).to_s(36)}.join]
129
129
  @toc_code.last
130
130
  else
131
131
  "#{' '*indent}<#{el.type}#{options_for_element(el)}>\n#{inner(el, indent, opts)}#{' '*indent}</#{el.type}>\n"
@@ -137,10 +137,10 @@ module Kramdown
137
137
  def convert_li(el, indent, opts)
138
138
  output = ' '*indent << "<#{el.type}" << options_for_element(el) << ">"
139
139
  res = inner(el, indent, opts)
140
- if el.options[:first_is_block]
141
- output << "\n" << res << ' '*indent
142
- else
140
+ if el.children.empty? || el.children.first.options[:category] != :block
143
141
  output << res << (res =~ /\n\Z/ ? ' '*indent : '')
142
+ else
143
+ output << "\n" << res << ' '*indent
144
144
  end
145
145
  output << "</#{el.type}>\n"
146
146
  end
@@ -155,12 +155,13 @@ module Kramdown
155
155
  def convert_html_element(el, indent, opts)
156
156
  res = inner(el, indent, opts)
157
157
  if @doc.options[:filter_html].include?(el.value)
158
- res.chomp + (el.options[:type] == :block ? "\n" : '')
159
- elsif el.options[:type] == :span
158
+ warn("The filter_html option is deprecated and will be removed in the next release")
159
+ res.chomp + (el.options[:category] == :block ? "\n" : '')
160
+ elsif el.options[:category] == :span
160
161
  "<#{el.value}#{options_for_element(el)}" << (!res.empty? ? ">#{res}</#{el.value}>" : " />")
161
162
  else
162
163
  output = ''
163
- output << ' '*indent if el.options[:parse_type] != :raw && !el.options[:parent_is_raw]
164
+ output << ' '*indent if !el.options[:parent_is_raw]
164
165
  output << "<#{el.value}#{options_for_element(el)}"
165
166
  if !res.empty? && el.options[:parse_type] != :block
166
167
  output << ">#{res}</#{el.value}>"
@@ -171,19 +172,20 @@ module Kramdown
171
172
  else
172
173
  output << " />"
173
174
  end
174
- output << "\n" if el.options[:outer_element] || (el.options[:parse_type] != :raw && !el.options[:parent_is_raw])
175
+ output << "\n" if el.options[:outer_element] || !el.options[:parent_is_raw]
175
176
  output
176
177
  end
177
178
  end
178
179
 
179
- def convert_html_text(el, indent, opts)
180
- escape_html(el.value, :text)
181
- end
182
-
183
180
  def convert_xml_comment(el, indent, opts)
184
- el.value + (el.options[:type] == :block ? "\n" : '')
181
+ if el.options[:category] == :block && !el.options[:parent_is_raw]
182
+ ' '*indent + el.value + "\n"
183
+ else
184
+ el.value
185
+ end
185
186
  end
186
187
  alias :convert_xml_pi :convert_xml_comment
188
+ alias :convert_html_doctype :convert_xml_comment
187
189
 
188
190
  def convert_table(el, indent, opts)
189
191
  if el.options[:alignment].all? {|a| a == :default}
@@ -197,11 +199,6 @@ module Kramdown
197
199
  end
198
200
 
199
201
  def convert_thead(el, indent, opts)
200
- opts[:cell_type] = case el.type
201
- when :thead then 'th'
202
- when :tbody, :tfoot then 'td'
203
- else opts[:cell_type]
204
- end
205
202
  "#{' '*indent}<#{el.type}#{options_for_element(el)}>\n#{inner(el, indent, opts)}#{' '*indent}</#{el.type}>\n"
206
203
  end
207
204
  alias :convert_tbody :convert_thead
@@ -210,8 +207,9 @@ module Kramdown
210
207
 
211
208
  def convert_td(el, indent, opts)
212
209
  res = inner(el, indent, opts)
213
- "#{' '*indent}<#{opts[:cell_type]}#{options_for_element(el)}>#{res.empty? ? "&nbsp;" : res}</#{opts[:cell_type]}>\n"
210
+ "#{' '*indent}<#{el.type}#{options_for_element(el)}>#{res.empty? ? "&nbsp;" : res}</#{el.type}>\n"
214
211
  end
212
+ alias :convert_th :convert_td
215
213
 
216
214
  def convert_br(el, indent, opts)
217
215
  "<br />"
@@ -235,7 +233,7 @@ module Kramdown
235
233
  end
236
234
 
237
235
  def convert_codespan(el, indent, opts)
238
- "<code#{options_for_element(el)}>#{escape_html(el.value)}</code>"
236
+ "<code#{options_for_element(el)}>#{el.value ? escape_html(el.value) : inner(el, indent, opts)}</code>"
239
237
  end
240
238
 
241
239
  def convert_footnote(el, indent, opts)
@@ -259,7 +257,7 @@ module Kramdown
259
257
  end
260
258
 
261
259
  TYPOGRAPHIC_SYMS = {
262
- :mdash => '&mdash;', :ndash => '&ndash;', :ellipsis => '&hellip;',
260
+ :mdash => '&mdash;', :ndash => '&ndash;', :hellip => '&hellip;',
263
261
  :laquo_space => '&laquo;&nbsp;', :raquo_space => '&nbsp;&raquo;',
264
262
  :laquo => '&laquo;', :raquo => '&raquo;'
265
263
  }
@@ -277,7 +275,7 @@ module Kramdown
277
275
  el.options[:attr]['class'] ||= ''
278
276
  el.options[:attr]['class'] += (el.options[:attr]['class'].empty? ? '' : ' ') + 'math'
279
277
  type = 'span'
280
- type = 'div' if el.options[:type] == :block
278
+ type = 'div' if el.options[:category] == :block
281
279
  "<#{type}#{options_for_element(el)}>#{escape_html(el.value, :text)}</#{type}>#{type == 'div' ? "\n" : ''}"
282
280
  end
283
281
 
@@ -291,7 +289,7 @@ module Kramdown
291
289
  result = inner(el, indent, opts)
292
290
  result << footnote_content
293
291
  if @toc_code
294
- toc_tree = generate_toc_tree(@toc, @toc_code.first)
292
+ toc_tree = generate_toc_tree(@toc, @toc_code[0], @toc_code[1] || {})
295
293
  text = if toc_tree.children.size > 0
296
294
  convert(toc_tree, 0)
297
295
  else
@@ -302,8 +300,8 @@ module Kramdown
302
300
  result
303
301
  end
304
302
 
305
- def generate_toc_tree(toc, type)
306
- sections = Element.new(type, nil, {:attr => {:id => 'markdown-toc'}})
303
+ def generate_toc_tree(toc, type, attr)
304
+ sections = Element.new(type, nil, {:attr => {'id' => 'markdown-toc'}.merge(attr)})
307
305
  stack = []
308
306
  toc.each do |level, id, children|
309
307
  li = Element.new(:li, nil, {:level => level})
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
3
  #--
4
- # Copyright (C) 2009 Thomas Leitner <t_leitner@gmx.at>
4
+ # Copyright (C) 2009-2010 Thomas Leitner <t_leitner@gmx.at>
5
5
  #
6
6
  # This file is part of kramdown.
7
7
  #
@@ -73,6 +73,10 @@ module Kramdown
73
73
  end
74
74
 
75
75
  def convert_codeblock(el, opts)
76
+ if !el.value
77
+ @doc.warnings << "Cannot convert codeblock with entity references"
78
+ return ''
79
+ end
76
80
  show_whitespace = el.options[:attr] && el.options[:attr]['class'].to_s =~ /\bshow-whitespaces\b/
77
81
  lang = el.options[:attr] && el.options[:attr]['lang']
78
82
  if show_whitespace || lang
@@ -142,20 +146,25 @@ module Kramdown
142
146
  end
143
147
 
144
148
  def convert_html_element(el, opts)
145
- @doc.warnings << "Can't convert HTML element"
146
- ''
149
+ if el.value == 'i'
150
+ "\\emph{#{inner(el, opts)}}"
151
+ elsif el.value == 'b'
152
+ "\\emph{#{inner(el, opts)}}"
153
+ else
154
+ @doc.warnings << "Can't convert HTML element"
155
+ ''
156
+ end
147
157
  end
148
158
 
149
- def convert_html_text(el, opts)
150
- @doc.warnings << "Can't convert HTML text"
151
- ''
159
+ def convert_xml_comment(el, opts)
160
+ el.value.split(/\n/).map {|l| "% #{l}"}.join("\n") + "\n"
152
161
  end
153
162
 
154
- def convert_xml_comment(el, opts)
155
- @doc.warnings << "Can't convert XML comment/PI"
163
+ def convert_xml_pi(el, opts)
164
+ @doc.warnings << "Can't convert XML PI/HTML document type"
156
165
  ''
157
166
  end
158
- alias :convert_xml_pi :convert_xml_comment
167
+ alias :convert_html_doctype :convert_xml_pi
159
168
 
160
169
  TABLE_ALIGNMENT_CHAR = {:default => 'l', :left => 'l', :center => 'c', :right => 'r'}
161
170
 
@@ -183,6 +192,7 @@ module Kramdown
183
192
  def convert_td(el, opts)
184
193
  inner(el, opts)
185
194
  end
195
+ alias :convert_th :convert_td
186
196
 
187
197
  def convert_br(el, opts)
188
198
  "\\newline\n"
@@ -201,18 +211,22 @@ module Kramdown
201
211
  if el.options[:attr]['src'] =~ /^(https?|ftps?):\/\//
202
212
  @doc.warnings << "Cannot include non-local image"
203
213
  ''
204
- else
214
+ elsif !el.options[:attr]['src'].empty?
205
215
  @doc.conversion_infos[:packages] << 'graphicx'
206
216
  "\\includegraphics{#{el.options[:attr]['src']}}"
217
+ else
218
+ @doc.warnings << "Cannot include image with empty path"
219
+ ''
207
220
  end
208
221
  end
209
222
 
210
223
  def convert_codespan(el, opts)
211
- "{\\tt #{escape(el.value)}}"
224
+ "{\\tt #{el.value ? escape(el.value) : inner(el, opts)}}"
212
225
  end
213
226
 
214
227
  def convert_footnote(el, opts)
215
- "\\footnote{#{inner(@doc.parse_infos[:footnotes][el.options[:name]])}}"
228
+ @doc.conversion_infos[:packages] << 'fancyvrb'
229
+ "\\footnote{#{inner(@doc.parse_infos[:footnotes][el.options[:name]][:content], opts)}}"
216
230
  end
217
231
 
218
232
  def convert_raw(el, opts)
@@ -491,7 +505,7 @@ EOF
491
505
  end
492
506
 
493
507
  TYPOGRAPHIC_SYMS = {
494
- :mdash => '---', :ndash => '--', :ellipsis => '\ldots{}',
508
+ :mdash => '---', :ndash => '--', :hellip => '\ldots{}',
495
509
  :laquo_space => '\guillemotleft{}~', :raquo_space => '~\guillemotright{}',
496
510
  :laquo => '\guillemotleft{}', :raquo => '\guillemotright{}'
497
511
  }
@@ -506,7 +520,7 @@ EOF
506
520
 
507
521
  def convert_math(el, opts)
508
522
  @doc.conversion_infos[:packages] += %w[amssymb amsmath amsthm amsfonts]
509
- if el.options[:type] == :block
523
+ if el.options[:category] == :block
510
524
  if el.value =~ /\A\s*\\begin\{/
511
525
  el.value
512
526
  else
@@ -517,7 +531,7 @@ EOF
517
531
  end
518
532
  end
519
533
 
520
- def convert_abbreviation(el, indent, opts)
534
+ def convert_abbreviation(el, opts)
521
535
  el.value
522
536
  end
523
537