rdoc 3.12.2 → 4.0.0.preview2

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

Potentially problematic release.


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

Files changed (200) hide show
  1. checksums.yaml +6 -6
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/.autotest +3 -2
  5. data/DEVELOPERS.rdoc +53 -0
  6. data/History.rdoc +159 -25
  7. data/LEGAL.rdoc +12 -0
  8. data/Manifest.txt +56 -3
  9. data/README.rdoc +87 -19
  10. data/Rakefile +11 -2
  11. data/TODO.rdoc +20 -13
  12. data/bin/rdoc +4 -0
  13. data/lib/gauntlet_rdoc.rb +1 -1
  14. data/lib/rdoc.rb +32 -71
  15. data/lib/rdoc/any_method.rb +75 -21
  16. data/lib/rdoc/attr.rb +49 -10
  17. data/lib/rdoc/class_module.rb +182 -32
  18. data/lib/rdoc/code_object.rb +54 -12
  19. data/lib/rdoc/comment.rb +8 -1
  20. data/lib/rdoc/constant.rb +100 -6
  21. data/lib/rdoc/context.rb +93 -41
  22. data/lib/rdoc/context/section.rb +143 -28
  23. data/lib/rdoc/cross_reference.rb +58 -50
  24. data/lib/rdoc/encoding.rb +34 -29
  25. data/lib/rdoc/erb_partial.rb +18 -0
  26. data/lib/rdoc/extend.rb +117 -0
  27. data/lib/rdoc/generator.rb +11 -6
  28. data/lib/rdoc/generator/darkfish.rb +250 -62
  29. data/lib/rdoc/generator/json_index.rb +20 -12
  30. data/lib/rdoc/generator/markup.rb +10 -12
  31. data/lib/rdoc/generator/ri.rb +7 -60
  32. data/lib/rdoc/generator/template/darkfish/_head.rhtml +7 -7
  33. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +16 -0
  34. data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +1 -1
  35. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +14 -0
  36. data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +1 -1
  37. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +13 -0
  38. data/lib/rdoc/generator/template/darkfish/class.rhtml +15 -1
  39. data/lib/rdoc/generator/template/darkfish/images/arrow_up.png +0 -0
  40. data/lib/rdoc/generator/template/darkfish/index.rhtml +3 -3
  41. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +7 -9
  42. data/lib/rdoc/generator/template/darkfish/page.rhtml +2 -0
  43. data/lib/rdoc/generator/template/darkfish/rdoc.css +31 -0
  44. data/lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml +18 -0
  45. data/lib/rdoc/generator/template/darkfish/servlet_root.rhtml +37 -0
  46. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +3 -3
  47. data/lib/rdoc/include.rb +12 -3
  48. data/lib/rdoc/markdown.kpeg +1186 -0
  49. data/lib/rdoc/markdown.rb +16336 -0
  50. data/lib/rdoc/markdown/entities.rb +2128 -0
  51. data/lib/rdoc/markdown/literals_1_8.kpeg +18 -0
  52. data/lib/rdoc/markdown/literals_1_8.rb +454 -0
  53. data/lib/rdoc/markdown/literals_1_9.kpeg +22 -0
  54. data/lib/rdoc/markdown/literals_1_9.rb +417 -0
  55. data/lib/rdoc/markup.rb +69 -10
  56. data/lib/rdoc/markup/attr_changer.rb +2 -5
  57. data/lib/rdoc/markup/attribute_manager.rb +23 -14
  58. data/lib/rdoc/markup/attributes.rb +70 -0
  59. data/lib/rdoc/markup/block_quote.rb +14 -0
  60. data/lib/rdoc/markup/document.rb +20 -4
  61. data/lib/rdoc/markup/formatter.rb +17 -6
  62. data/lib/rdoc/markup/formatter_test_case.rb +93 -24
  63. data/lib/rdoc/markup/hard_break.rb +31 -0
  64. data/lib/rdoc/markup/heading.rb +1 -1
  65. data/lib/rdoc/markup/indented_paragraph.rb +14 -0
  66. data/lib/rdoc/markup/list.rb +23 -4
  67. data/lib/rdoc/markup/list_item.rb +17 -4
  68. data/lib/rdoc/markup/paragraph.rb +14 -0
  69. data/lib/rdoc/markup/parser.rb +107 -60
  70. data/lib/rdoc/markup/raw.rb +4 -4
  71. data/lib/rdoc/markup/special.rb +3 -3
  72. data/lib/rdoc/markup/to_ansi.rb +7 -1
  73. data/lib/rdoc/markup/to_html.rb +42 -14
  74. data/lib/rdoc/markup/to_html_crossref.rb +10 -9
  75. data/lib/rdoc/markup/to_html_snippet.rb +20 -4
  76. data/lib/rdoc/markup/to_joined_paragraph.rb +68 -0
  77. data/lib/rdoc/markup/to_label.rb +20 -1
  78. data/lib/rdoc/markup/to_markdown.rb +134 -0
  79. data/lib/rdoc/markup/to_rdoc.rb +36 -5
  80. data/lib/rdoc/markup/to_table_of_contents.rb +6 -1
  81. data/lib/rdoc/markup/to_tt_only.rb +11 -2
  82. data/lib/rdoc/markup/verbatim.rb +19 -0
  83. data/lib/rdoc/method_attr.rb +33 -19
  84. data/lib/rdoc/normal_class.rb +26 -7
  85. data/lib/rdoc/normal_module.rb +10 -5
  86. data/lib/rdoc/options.rb +95 -21
  87. data/lib/rdoc/parser.rb +6 -2
  88. data/lib/rdoc/parser/c.rb +212 -97
  89. data/lib/rdoc/parser/markdown.rb +23 -0
  90. data/lib/rdoc/parser/ruby.rb +115 -35
  91. data/lib/rdoc/parser/ruby_tools.rb +8 -3
  92. data/lib/rdoc/rd.rb +8 -4
  93. data/lib/rdoc/rd/block_parser.rb +1 -1
  94. data/lib/rdoc/rd/block_parser.ry +1 -1
  95. data/lib/rdoc/rdoc.rb +45 -21
  96. data/lib/rdoc/ri/driver.rb +322 -76
  97. data/lib/rdoc/ri/paths.rb +90 -31
  98. data/lib/rdoc/ri/store.rb +2 -353
  99. data/lib/rdoc/ruby_lex.rb +5 -21
  100. data/lib/rdoc/ruby_token.rb +2 -3
  101. data/lib/rdoc/rubygems_hook.rb +21 -9
  102. data/lib/rdoc/servlet.rb +302 -0
  103. data/lib/rdoc/stats.rb +28 -20
  104. data/lib/rdoc/store.rb +881 -0
  105. data/lib/rdoc/task.rb +2 -1
  106. data/lib/rdoc/test_case.rb +103 -1
  107. data/lib/rdoc/text.rb +5 -4
  108. data/lib/rdoc/tom_doc.rb +17 -16
  109. data/lib/rdoc/top_level.rb +43 -285
  110. data/test/MarkdownTest_1.0.3/Amps and angle encoding.text +21 -0
  111. data/test/MarkdownTest_1.0.3/Auto links.text +13 -0
  112. data/test/MarkdownTest_1.0.3/Backslash escapes.text +120 -0
  113. data/test/MarkdownTest_1.0.3/Blockquotes with code blocks.text +11 -0
  114. data/test/MarkdownTest_1.0.3/Code Blocks.text +14 -0
  115. data/test/MarkdownTest_1.0.3/Code Spans.text +6 -0
  116. data/test/MarkdownTest_1.0.3/Hard-wrapped paragraphs with list-like lines.text +8 -0
  117. data/test/MarkdownTest_1.0.3/Horizontal rules.text +67 -0
  118. data/test/MarkdownTest_1.0.3/Inline HTML (Advanced).text +15 -0
  119. data/test/MarkdownTest_1.0.3/Inline HTML (Simple).text +69 -0
  120. data/test/MarkdownTest_1.0.3/Inline HTML comments.text +13 -0
  121. data/test/MarkdownTest_1.0.3/Links, inline style.text +12 -0
  122. data/test/MarkdownTest_1.0.3/Links, reference style.text +71 -0
  123. data/test/MarkdownTest_1.0.3/Links, shortcut references.text +20 -0
  124. data/test/MarkdownTest_1.0.3/Literal quotes in titles.text +7 -0
  125. data/test/MarkdownTest_1.0.3/Markdown Documentation - Basics.text +306 -0
  126. data/test/MarkdownTest_1.0.3/Markdown Documentation - Syntax.text +888 -0
  127. data/test/MarkdownTest_1.0.3/Nested blockquotes.text +5 -0
  128. data/test/MarkdownTest_1.0.3/Ordered and unordered lists.text +131 -0
  129. data/test/MarkdownTest_1.0.3/Strong and em together.text +7 -0
  130. data/test/MarkdownTest_1.0.3/Tabs.text +21 -0
  131. data/test/MarkdownTest_1.0.3/Tidyness.text +5 -0
  132. data/test/test_attribute_manager.rb +7 -4
  133. data/test/test_rdoc_any_method.rb +84 -13
  134. data/test/test_rdoc_attr.rb +59 -9
  135. data/test/test_rdoc_class_module.rb +670 -73
  136. data/test/test_rdoc_code_object.rb +21 -1
  137. data/test/test_rdoc_comment.rb +1 -1
  138. data/test/test_rdoc_constant.rb +132 -0
  139. data/test/test_rdoc_context.rb +84 -18
  140. data/test/test_rdoc_context_section.rb +99 -15
  141. data/test/test_rdoc_cross_reference.rb +1 -1
  142. data/test/test_rdoc_encoding.rb +17 -1
  143. data/test/test_rdoc_extend.rb +94 -0
  144. data/test/test_rdoc_generator_darkfish.rb +45 -19
  145. data/test/test_rdoc_generator_json_index.rb +27 -7
  146. data/test/test_rdoc_generator_markup.rb +3 -3
  147. data/test/test_rdoc_generator_ri.rb +11 -9
  148. data/test/test_rdoc_include.rb +12 -0
  149. data/test/test_rdoc_markdown.rb +977 -0
  150. data/test/test_rdoc_markdown_test.rb +1891 -0
  151. data/test/test_rdoc_markup.rb +1 -1
  152. data/test/test_rdoc_markup_attribute_manager.rb +2 -2
  153. data/test/test_rdoc_markup_attributes.rb +39 -0
  154. data/test/test_rdoc_markup_document.rb +16 -1
  155. data/test/test_rdoc_markup_formatter.rb +7 -4
  156. data/test/test_rdoc_markup_hard_break.rb +31 -0
  157. data/test/test_rdoc_markup_indented_paragraph.rb +14 -0
  158. data/test/test_rdoc_markup_paragraph.rb +15 -1
  159. data/test/test_rdoc_markup_parser.rb +152 -89
  160. data/test/test_rdoc_markup_to_ansi.rb +23 -2
  161. data/test/test_rdoc_markup_to_bs.rb +24 -0
  162. data/test/test_rdoc_markup_to_html.rb +50 -19
  163. data/test/test_rdoc_markup_to_html_crossref.rb +23 -5
  164. data/test/test_rdoc_markup_to_html_snippet.rb +49 -8
  165. data/test/test_rdoc_markup_to_joined_paragraph.rb +32 -0
  166. data/test/test_rdoc_markup_to_label.rb +63 -1
  167. data/test/test_rdoc_markup_to_markdown.rb +352 -0
  168. data/test/test_rdoc_markup_to_rdoc.rb +22 -2
  169. data/test/test_rdoc_markup_to_table_of_contents.rb +44 -39
  170. data/test/test_rdoc_markup_to_tt_only.rb +20 -0
  171. data/test/test_rdoc_markup_verbatim.rb +13 -0
  172. data/test/test_rdoc_method_attr.rb +5 -0
  173. data/test/test_rdoc_normal_class.rb +24 -5
  174. data/test/test_rdoc_normal_module.rb +1 -1
  175. data/test/test_rdoc_options.rb +21 -6
  176. data/test/test_rdoc_parser.rb +24 -0
  177. data/test/test_rdoc_parser_c.rb +151 -26
  178. data/test/test_rdoc_parser_markdown.rb +55 -0
  179. data/test/test_rdoc_parser_rd.rb +2 -2
  180. data/test/test_rdoc_parser_ruby.rb +468 -109
  181. data/test/test_rdoc_parser_simple.rb +2 -2
  182. data/test/test_rdoc_rd_block_parser.rb +0 -4
  183. data/test/test_rdoc_rdoc.rb +110 -22
  184. data/test/test_rdoc_ri_driver.rb +415 -80
  185. data/test/test_rdoc_ri_paths.rb +122 -13
  186. data/test/test_rdoc_ruby_lex.rb +5 -61
  187. data/test/test_rdoc_ruby_token.rb +19 -0
  188. data/test/test_rdoc_rubygems_hook.rb +64 -43
  189. data/test/test_rdoc_servlet.rb +429 -0
  190. data/test/test_rdoc_stats.rb +83 -24
  191. data/test/{test_rdoc_ri_store.rb → test_rdoc_store.rb} +395 -22
  192. data/test/test_rdoc_task.rb +2 -2
  193. data/test/test_rdoc_text.rb +37 -11
  194. data/test/test_rdoc_tom_doc.rb +59 -62
  195. data/test/test_rdoc_top_level.rb +71 -113
  196. data/test/xref_test_case.rb +7 -9
  197. metadata +122 -39
  198. metadata.gz.sig +0 -0
  199. data/CVE-2013-0256.rdoc +0 -49
  200. data/lib/rdoc/markup/attribute.rb +0 -51
@@ -13,7 +13,7 @@ class RDoc::Markup::Raw
13
13
 
14
14
  def initialize *parts
15
15
  @parts = []
16
- @parts.push(*parts)
16
+ @parts.concat parts
17
17
  end
18
18
 
19
19
  ##
@@ -38,11 +38,11 @@ class RDoc::Markup::Raw
38
38
  # Appends +other+'s parts
39
39
 
40
40
  def merge other
41
- @parts.push(*other.parts)
41
+ @parts.concat other.parts
42
42
  end
43
43
 
44
44
  def pretty_print q # :nodoc:
45
- self.class.name =~ /.*::(\w{1,4})$/i
45
+ self.class.name =~ /.*::(\w{1,4})/i
46
46
 
47
47
  q.group 2, "[#{$1.downcase}: ", ']' do
48
48
  q.seplist @parts do |part|
@@ -55,7 +55,7 @@ class RDoc::Markup::Raw
55
55
  # Appends +texts+ onto this Paragraph
56
56
 
57
57
  def push *texts
58
- self.parts.push(*texts)
58
+ self.parts.concat texts
59
59
  end
60
60
 
61
61
  ##
@@ -28,12 +28,12 @@ class RDoc::Markup::Special
28
28
  end
29
29
 
30
30
  def inspect # :nodoc:
31
- "#<RDoc::Markup::Special:0x%x @type=%p, name=%p @text=%p>" % [
32
- object_id, @type, RDoc::Markup::Attribute.as_string(type), text.dump]
31
+ "#<RDoc::Markup::Special:0x%x @type=%p, @text=%p>" % [
32
+ object_id, @type, text.dump]
33
33
  end
34
34
 
35
35
  def to_s # :nodoc:
36
- "Special: type=#{type}, name=#{RDoc::Markup::Attribute.as_string type}, text=#{text.dump}"
36
+ "Special: type=#{type} text=#{text.dump}"
37
37
  end
38
38
 
39
39
  end
@@ -56,7 +56,13 @@ class RDoc::Markup::ToAnsi < RDoc::Markup::ToRdoc
56
56
  when :BULLET then
57
57
  '*'
58
58
  when :NOTE, :LABEL then
59
- attributes(list_item.label).strip + ":\n"
59
+ labels = Array(list_item.label).map do |label|
60
+ attributes(label).strip
61
+ end.join "\n"
62
+
63
+ labels << ":\n" unless labels.empty?
64
+
65
+ labels
60
66
  else
61
67
  @list_index.last.to_s + '.'
62
68
  end
@@ -65,7 +65,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
65
65
  ##
66
66
  # Creates a new formatter that will output HTML
67
67
 
68
- def initialize markup = nil
68
+ def initialize options, markup = nil
69
69
  super
70
70
 
71
71
  @code_object = nil
@@ -73,16 +73,23 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
73
73
  @in_list_entry = nil
74
74
  @list = nil
75
75
  @th = nil
76
+ @hard_break = "<br>\n"
76
77
 
77
78
  # external links
78
- @markup.add_special(/((link:|https?:|mailto:|ftp:|irc:|www\.)\S+\w)/,
79
+ @markup.add_special(/(?:link:|https?:|mailto:|ftp:|irc:|www\.)\S+\w/,
79
80
  :HYPERLINK)
80
81
 
81
82
  # internal links
82
83
  @markup.add_special(/rdoc-[a-z]+:\S+/, :RDOCLINK)
83
84
 
84
85
  # and links of the form <text>[<url>]
85
- @markup.add_special(/(((\{.*?\})|\b\S+?)\[\S+?\])/, :TIDYLINK)
86
+ @markup.add_special(/(?:
87
+ \{.*?\} | # multi-word label
88
+ \b[^\s{}]+? # single-word label
89
+ )
90
+
91
+ \[\S+?\] # link target
92
+ /x, :TIDYLINK)
86
93
 
87
94
  init_tags
88
95
  end
@@ -91,6 +98,13 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
91
98
  #
92
99
  # These methods handle special markup added by RDoc::Markup#add_special.
93
100
 
101
+ ##
102
+ # +special+ is a <code><br></code>
103
+
104
+ def handle_special_HARD_BREAK special
105
+ '<br>'
106
+ end
107
+
94
108
  ##
95
109
  # +special+ is a potential link. The following schemes are handled:
96
110
  #
@@ -176,12 +190,26 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
176
190
  @res.join
177
191
  end
178
192
 
193
+ ##
194
+ # Adds +block_quote+ to the output
195
+
196
+ def accept_block_quote block_quote
197
+ @res << "\n<blockquote>"
198
+
199
+ block_quote.parts.each do |part|
200
+ part.accept self
201
+ end
202
+
203
+ @res << "</blockquote>\n"
204
+ end
205
+
179
206
  ##
180
207
  # Adds +paragraph+ to the output
181
208
 
182
- def accept_paragraph(paragraph)
209
+ def accept_paragraph paragraph
183
210
  @res << "\n<p>"
184
- @res << wrap(to_html(paragraph.text))
211
+ text = paragraph.text @hard_break
212
+ @res << wrap(to_html(text))
185
213
  @res << "</p>\n"
186
214
  end
187
215
 
@@ -192,14 +220,12 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
192
220
  text = verbatim.text.rstrip
193
221
 
194
222
  @res << if verbatim.ruby? or parseable? text then
195
- options = RDoc::RDoc.current.options if RDoc::RDoc.current
196
-
197
223
  begin
198
- tokens = RDoc::RubyLex.tokenize text, options
224
+ tokens = RDoc::RubyLex.tokenize text, @options
225
+
226
+ html = RDoc::TokenStream.to_html tokens
199
227
 
200
- "\n<pre class=\"ruby\">" \
201
- "#{RDoc::TokenStream.to_html tokens}" \
202
- "</pre>\n"
228
+ "\n<pre class=\"ruby\">#{html}</pre>\n"
203
229
  rescue RDoc::RubyLex::Error
204
230
  "\n<pre>#{CGI.escapeHTML text}</pre>\n"
205
231
  end
@@ -288,7 +314,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
288
314
  # :section: Utilities
289
315
 
290
316
  ##
291
- # CGI escapes +text+
317
+ # CGI-escapes +text+
292
318
 
293
319
  def convert_string(text)
294
320
  CGI.escapeHTML text
@@ -355,7 +381,9 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
355
381
  when :BULLET, :LALPHA, :NUMBER, :UALPHA then
356
382
  "<li>"
357
383
  when :LABEL, :NOTE then
358
- "<dt>#{to_html list_item.label}\n<dd>"
384
+ Array(list_item.label).map do |label|
385
+ "<dt>#{to_html label}\n"
386
+ end.join << "<dd>"
359
387
  else
360
388
  raise RDoc::Error, "Invalid list type: #{list_type.inspect}"
361
389
  end
@@ -379,7 +407,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
379
407
  # Returns true if Ripper is available it can create a sexp from +text+
380
408
 
381
409
  def parseable? text
382
- text =~ /\b(def|class|module|require)\b|=>|\{\s?\||do \|/ and
410
+ text =~ /\b(def|class|module|require) |=>|\{\s?\||do \|/ and
383
411
  text !~ /<%|%>/
384
412
  end
385
413
 
@@ -28,21 +28,20 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
28
28
  # references are removed unless +show_hash+ is true. Only method names
29
29
  # preceded by '#' or '::' are linked, unless +hyperlink_all+ is true.
30
30
 
31
- def initialize(from_path, context, show_hash, hyperlink_all = false,
32
- markup = nil)
31
+ def initialize(options, from_path, context, markup = nil)
33
32
  raise ArgumentError, 'from_path cannot be nil' if from_path.nil?
34
- super markup
35
33
 
36
- crossref_re = hyperlink_all ? ALL_CROSSREF_REGEXP : CROSSREF_REGEXP
34
+ super options, markup
37
35
 
38
- @cross_reference = RDoc::CrossReference.new context
36
+ @context = context
37
+ @from_path = from_path
38
+ @hyperlink_all = @options.hyperlink_all
39
+ @show_hash = @options.show_hash
39
40
 
41
+ crossref_re = @hyperlink_all ? ALL_CROSSREF_REGEXP : CROSSREF_REGEXP
40
42
  @markup.add_special crossref_re, :CROSSREF
41
43
 
42
- @context = context
43
- @from_path = from_path
44
- @hyperlink_all = hyperlink_all
45
- @show_hash = show_hash
44
+ @cross_reference = RDoc::CrossReference.new @context
46
45
  end
47
46
 
48
47
  ##
@@ -71,6 +70,8 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
71
70
  def handle_special_CROSSREF(special)
72
71
  name = special.text
73
72
 
73
+ return name if name =~ /@[\w-]+\.[\w-]/ # labels that look like emails
74
+
74
75
  unless @hyperlink_all then
75
76
  # This ensures that words entirely consisting of lowercase letters will
76
77
  # not have cross-references generated (to suppress lots of erroneous
@@ -33,8 +33,8 @@ class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
33
33
  # next word boundary after the given number of +characters+ or +paragraphs+
34
34
  # of text have been encountered.
35
35
 
36
- def initialize characters = 100, paragraphs = 3, markup = nil
37
- super markup
36
+ def initialize options, characters = 100, paragraphs = 3, markup = nil
37
+ super options, markup
38
38
 
39
39
  @character_limit = characters
40
40
  @paragraph_limit = paragraphs
@@ -68,7 +68,9 @@ class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
68
68
  def accept_paragraph paragraph
69
69
  para = @in_list_entry.last || "<p>"
70
70
 
71
- @res << "#{para}#{wrap to_html paragraph.text}\n"
71
+ text = paragraph.text @hard_break
72
+
73
+ @res << "#{para}#{wrap to_html text}\n"
72
74
 
73
75
  add_paragraph
74
76
  end
@@ -126,6 +128,14 @@ class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
126
128
  special.text.sub(/\A\\/, '')
127
129
  end
128
130
 
131
+ ##
132
+ # +special+ is a <code><br></code>
133
+
134
+ def handle_special_HARD_BREAK special
135
+ @characters -= 4
136
+ '<br>'
137
+ end
138
+
129
139
  ##
130
140
  # Lists are paragraphs, but notes and labels have a separator
131
141
 
@@ -136,7 +146,13 @@ class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
136
146
  when :BULLET, :LALPHA, :NUMBER, :UALPHA then
137
147
  "<p>"
138
148
  when :LABEL, :NOTE then
139
- start = "<p>#{to_html list_item.label} &mdash; "
149
+ labels = Array(list_item.label).map do |label|
150
+ to_html label
151
+ end.join ', '
152
+
153
+ labels << " &mdash; " unless labels.empty?
154
+
155
+ start = "<p>#{labels}"
140
156
  @characters += 1 # try to include the label
141
157
  start
142
158
  else
@@ -0,0 +1,68 @@
1
+ ##
2
+ # Joins the parts of an RDoc::Markup::Paragraph into a single String.
3
+ #
4
+ # This allows for easier maintenance and testing of Markdown support.
5
+ #
6
+ # This formatter only works on Paragraph instances. Attempting to process
7
+ # other markup syntax items will not work.
8
+
9
+ class RDoc::Markup::ToJoinedParagraph < RDoc::Markup::Formatter
10
+
11
+ def initialize # :nodoc:
12
+ super nil
13
+ end
14
+
15
+ def start_accepting
16
+ end
17
+
18
+ def end_accepting
19
+ end
20
+
21
+ def accept_paragraph paragraph
22
+ parts = []
23
+ string = false
24
+
25
+ paragraph.parts.each do |part|
26
+ if String === part then
27
+ if string then
28
+ string << part
29
+ else
30
+ parts << part
31
+ string = part
32
+ end
33
+ else
34
+ parts << part
35
+ string = false
36
+ end
37
+ end
38
+
39
+ parts = parts.map do |part|
40
+ if String === part then
41
+ part.rstrip
42
+ else
43
+ part
44
+ end
45
+ end
46
+
47
+ # TODO use Enumerable#chunk when ruby 1.8 support is dropped
48
+ #parts = paragraph.parts.chunk do |part|
49
+ # String === part
50
+ #end.map do |string, chunk|
51
+ # string ? chunk.join.rstrip : chunk
52
+ #end.flatten
53
+
54
+ paragraph.parts.replace parts
55
+ end
56
+
57
+ alias accept_block_quote ignore
58
+ alias accept_heading ignore
59
+ alias accept_list_end ignore
60
+ alias accept_list_item_end ignore
61
+ alias accept_list_item_start ignore
62
+ alias accept_list_start ignore
63
+ alias accept_raw ignore
64
+ alias accept_rule ignore
65
+ alias accept_verbatim ignore
66
+
67
+ end
68
+
@@ -7,11 +7,13 @@ require 'cgi'
7
7
 
8
8
  class RDoc::Markup::ToLabel < RDoc::Markup::Formatter
9
9
 
10
+ attr_reader :res # :nodoc:
11
+
10
12
  ##
11
13
  # Creates a new formatter that will output HTML-safe labels
12
14
 
13
15
  def initialize markup = nil
14
- super
16
+ super nil, markup
15
17
 
16
18
  @markup.add_special RDoc::CrossReference::CROSSREF_REGEXP, :CROSSREF
17
19
  @markup.add_special(/(((\{.*?\})|\b\S+?)\[\S+?\])/, :TIDYLINK)
@@ -19,6 +21,8 @@ class RDoc::Markup::ToLabel < RDoc::Markup::Formatter
19
21
  add_tag :BOLD, '', ''
20
22
  add_tag :TT, '', ''
21
23
  add_tag :EM, '', ''
24
+
25
+ @res = []
22
26
  end
23
27
 
24
28
  ##
@@ -51,5 +55,20 @@ class RDoc::Markup::ToLabel < RDoc::Markup::Formatter
51
55
  $1
52
56
  end
53
57
 
58
+ alias accept_blank_line ignore
59
+ alias accept_block_quote ignore
60
+ alias accept_heading ignore
61
+ alias accept_list_end ignore
62
+ alias accept_list_item_end ignore
63
+ alias accept_list_item_start ignore
64
+ alias accept_list_start ignore
65
+ alias accept_paragraph ignore
66
+ alias accept_raw ignore
67
+ alias accept_rule ignore
68
+ alias accept_verbatim ignore
69
+ alias end_accepting ignore
70
+ alias handle_special_HARD_BREAK ignore
71
+ alias start_accepting ignore
72
+
54
73
  end
55
74
 
@@ -0,0 +1,134 @@
1
+ # :markup: markdown
2
+
3
+ ##
4
+ # Outputs parsed markup as Markdown
5
+
6
+ class RDoc::Markup::ToMarkdown < RDoc::Markup::ToRdoc
7
+
8
+ ##
9
+ # Creates a new formatter that will output Markdown format text
10
+
11
+ def initialize markup = nil
12
+ super
13
+
14
+ @headings[1] = ['# ', '']
15
+ @headings[2] = ['## ', '']
16
+ @headings[3] = ['### ', '']
17
+ @headings[4] = ['#### ', '']
18
+ @headings[5] = ['##### ', '']
19
+ @headings[6] = ['###### ', '']
20
+
21
+ @hard_break = " \n"
22
+ end
23
+
24
+ ##
25
+ # Maps attributes to HTML sequences
26
+
27
+ def init_tags
28
+ add_tag :BOLD, '**', '**'
29
+ add_tag :EM, '*', '*'
30
+ add_tag :TT, '`', '`'
31
+ end
32
+
33
+ ##
34
+ # Adds a newline to the output
35
+
36
+ def handle_special_HARD_BREAK special
37
+ " \n"
38
+ end
39
+
40
+ ##
41
+ # Finishes consumption of `list`
42
+
43
+ def accept_list_end list
44
+ @res << "\n"
45
+
46
+ super
47
+ end
48
+
49
+ ##
50
+ # Finishes consumption of `list_item`
51
+
52
+ def accept_list_item_end list_item
53
+ width = case @list_type.last
54
+ when :BULLET then
55
+ 4
56
+ when :NOTE, :LABEL then
57
+ use_prefix
58
+
59
+ 4
60
+ else
61
+ @list_index[-1] = @list_index.last.succ
62
+ 4
63
+ end
64
+
65
+ @indent -= width
66
+ end
67
+
68
+ ##
69
+ # Prepares the visitor for consuming `list_item`
70
+
71
+ def accept_list_item_start list_item
72
+ type = @list_type.last
73
+
74
+ case type
75
+ when :NOTE, :LABEL then
76
+ bullets = Array(list_item.label).map do |label|
77
+ attributes(label).strip
78
+ end.join "\n"
79
+
80
+ bullets << "\n:"
81
+
82
+ @prefix = ' ' * @indent
83
+ @indent += 4
84
+ @prefix << bullets + (' ' * (@indent - 1))
85
+ else
86
+ bullet = type == :BULLET ? '*' : @list_index.last.to_s + '.'
87
+ @prefix = (' ' * @indent) + bullet.ljust(4)
88
+
89
+ @indent += 4
90
+ end
91
+ end
92
+
93
+ ##
94
+ # Prepares the visitor for consuming `list`
95
+
96
+ def accept_list_start list
97
+ case list.type
98
+ when :BULLET, :LABEL, :NOTE then
99
+ @list_index << nil
100
+ when :LALPHA, :NUMBER, :UALPHA then
101
+ @list_index << 1
102
+ else
103
+ raise RDoc::Error, "invalid list type #{list.type}"
104
+ end
105
+
106
+ @list_width << 4
107
+ @list_type << list.type
108
+ end
109
+
110
+ ##
111
+ # Adds `rule` to the output
112
+
113
+ def accept_rule rule
114
+ use_prefix or @res << ' ' * @indent
115
+ @res << '-' * 3
116
+ @res << "\n"
117
+ end
118
+
119
+ ##
120
+ # Outputs `verbatim` indented 4 columns
121
+
122
+ def accept_verbatim verbatim
123
+ indent = ' ' * (@indent + 4)
124
+
125
+ verbatim.parts.each do |part|
126
+ @res << indent unless part == "\n"
127
+ @res << part
128
+ end
129
+
130
+ @res << "\n" unless @res =~ /\n\z/
131
+ end
132
+
133
+ end
134
+