rdoc 6.13.0 → 6.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/README.rdoc +3 -1
  3. data/lib/rdoc/code_object/any_method.rb +4 -4
  4. data/lib/rdoc/code_object/attr.rb +3 -3
  5. data/lib/rdoc/code_object/class_module.rb +18 -16
  6. data/lib/rdoc/code_object/constant.rb +5 -5
  7. data/lib/rdoc/code_object/context/section.rb +7 -7
  8. data/lib/rdoc/code_object/context.rb +19 -19
  9. data/lib/rdoc/code_object/method_attr.rb +6 -6
  10. data/lib/rdoc/code_object/mixin.rb +3 -3
  11. data/lib/rdoc/code_object/normal_class.rb +1 -1
  12. data/lib/rdoc/code_object/normal_module.rb +1 -1
  13. data/lib/rdoc/code_object/single_class.rb +1 -1
  14. data/lib/rdoc/code_object/top_level.rb +10 -8
  15. data/lib/rdoc/code_object.rb +3 -3
  16. data/lib/rdoc/comment.rb +6 -6
  17. data/lib/rdoc/cross_reference.rb +3 -3
  18. data/lib/rdoc/encoding.rb +4 -4
  19. data/lib/rdoc/erb_partial.rb +1 -1
  20. data/lib/rdoc/erbio.rb +2 -2
  21. data/lib/rdoc/generator/darkfish.rb +15 -15
  22. data/lib/rdoc/generator/json_index.rb +3 -3
  23. data/lib/rdoc/generator/markup.rb +12 -0
  24. data/lib/rdoc/generator/pot/message_extractor.rb +4 -4
  25. data/lib/rdoc/generator/pot/po.rb +1 -1
  26. data/lib/rdoc/generator/pot/po_entry.rb +7 -7
  27. data/lib/rdoc/generator/pot.rb +1 -1
  28. data/lib/rdoc/generator/ri.rb +1 -1
  29. data/lib/rdoc/generator/template/darkfish/_head.rhtml +5 -0
  30. data/lib/rdoc/generator/template/darkfish/css/rdoc.css +2 -0
  31. data/lib/rdoc/markup/attribute_manager.rb +5 -5
  32. data/lib/rdoc/markup/attributes.rb +3 -3
  33. data/lib/rdoc/markup/blank_line.rb +2 -2
  34. data/lib/rdoc/markup/block_quote.rb +1 -1
  35. data/lib/rdoc/markup/document.rb +8 -8
  36. data/lib/rdoc/markup/formatter.rb +12 -12
  37. data/lib/rdoc/markup/hard_break.rb +3 -3
  38. data/lib/rdoc/markup/heading.rb +4 -4
  39. data/lib/rdoc/markup/include.rb +3 -3
  40. data/lib/rdoc/markup/indented_paragraph.rb +3 -3
  41. data/lib/rdoc/markup/list.rb +4 -4
  42. data/lib/rdoc/markup/list_item.rb +4 -4
  43. data/lib/rdoc/markup/paragraph.rb +2 -2
  44. data/lib/rdoc/markup/parser.rb +11 -11
  45. data/lib/rdoc/markup/pre_process.rb +6 -6
  46. data/lib/rdoc/markup/raw.rb +5 -5
  47. data/lib/rdoc/markup/rule.rb +2 -2
  48. data/lib/rdoc/markup/table.rb +4 -4
  49. data/lib/rdoc/markup/to_ansi.rb +3 -3
  50. data/lib/rdoc/markup/to_bs.rb +6 -6
  51. data/lib/rdoc/markup/to_html.rb +21 -16
  52. data/lib/rdoc/markup/to_html_crossref.rb +5 -5
  53. data/lib/rdoc/markup/to_html_snippet.rb +17 -17
  54. data/lib/rdoc/markup/to_joined_paragraph.rb +1 -1
  55. data/lib/rdoc/markup/to_label.rb +5 -5
  56. data/lib/rdoc/markup/to_markdown.rb +12 -12
  57. data/lib/rdoc/markup/to_rdoc.rb +29 -28
  58. data/lib/rdoc/markup/to_table_of_contents.rb +3 -3
  59. data/lib/rdoc/markup/to_test.rb +1 -1
  60. data/lib/rdoc/markup/to_tt_only.rb +8 -8
  61. data/lib/rdoc/markup/verbatim.rb +3 -3
  62. data/lib/rdoc/markup.rb +3 -3
  63. data/lib/rdoc/options.rb +31 -12
  64. data/lib/rdoc/parser/c.rb +16 -16
  65. data/lib/rdoc/parser/changelog.rb +9 -9
  66. data/lib/rdoc/parser/prism_ruby.rb +1 -1
  67. data/lib/rdoc/parser/ruby.rb +43 -43
  68. data/lib/rdoc/parser/simple.rb +2 -2
  69. data/lib/rdoc/parser.rb +8 -8
  70. data/lib/rdoc/rd/inline.rb +4 -4
  71. data/lib/rdoc/rd.rb +1 -1
  72. data/lib/rdoc/rdoc.rb +8 -8
  73. data/lib/rdoc/ri/driver.rb +49 -49
  74. data/lib/rdoc/ri/paths.rb +2 -2
  75. data/lib/rdoc/ri/task.rb +1 -1
  76. data/lib/rdoc/rubygems_hook.rb +14 -11
  77. data/lib/rdoc/servlet.rb +15 -15
  78. data/lib/rdoc/stats/normal.rb +1 -1
  79. data/lib/rdoc/stats/quiet.rb +1 -1
  80. data/lib/rdoc/stats/verbose.rb +3 -3
  81. data/lib/rdoc/stats.rb +12 -12
  82. data/lib/rdoc/store.rb +30 -30
  83. data/lib/rdoc/task.rb +2 -2
  84. data/lib/rdoc/text.rb +11 -11
  85. data/lib/rdoc/token_stream.rb +1 -1
  86. data/lib/rdoc/tom_doc.rb +7 -7
  87. data/lib/rdoc/version.rb +1 -1
  88. data/man/ri.1 +2 -0
  89. metadata +17 -3
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
- require 'cgi/util'
2
+ require 'cgi/escape'
3
+ # For CGI.unescape on earlier rubies
4
+ require 'cgi/util' if RUBY_VERSION < '3.5'
3
5
 
4
6
  ##
5
7
  # Outputs RDoc markup as HTML.
@@ -42,7 +44,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
42
44
  ##
43
45
  # Creates a new formatter that will output HTML
44
46
 
45
- def initialize options, markup = nil
47
+ def initialize(options, markup = nil)
46
48
  super
47
49
 
48
50
  @code_object = nil
@@ -82,7 +84,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
82
84
  add_regexp_handling_TIDYLINK
83
85
  end
84
86
 
85
- def handle_RDOCLINK url # :nodoc:
87
+ def handle_RDOCLINK(url) # :nodoc:
86
88
  case url
87
89
  when /^rdoc-ref:/
88
90
  CGI.escapeHTML($')
@@ -98,7 +100,10 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
98
100
 
99
101
  gen_url CGI.escapeHTML(url), CGI.escapeHTML(text)
100
102
  when /^rdoc-image:/
101
- url, alt = $'.split(":", 2) # Split the string after "rdoc-image:" into url and alt
103
+ # Split the string after "rdoc-image:" into url and alt.
104
+ # "path/to/image.jpg:alt text" => ["path/to/image.jpg", "alt text"]
105
+ # "http://example.com/path/to/image.jpg:alt text" => ["http://example.com/path/to/image.jpg", "alt text"]
106
+ url, alt = $'.split(/:(?!\/)/, 2)
102
107
  if alt && !alt.empty?
103
108
  %[<img src="#{CGI.escapeHTML(url)}" alt="#{CGI.escapeHTML(alt)}">]
104
109
  else
@@ -112,7 +117,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
112
117
  ##
113
118
  # +target+ is a <code><br></code>
114
119
 
115
- def handle_regexp_HARD_BREAK target
120
+ def handle_regexp_HARD_BREAK(target)
116
121
  '<br>'
117
122
  end
118
123
 
@@ -143,7 +148,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
143
148
  # For the +rdoc-label+ scheme the footnote and label prefixes are stripped
144
149
  # when creating a link. All other contents will be linked verbatim.
145
150
 
146
- def handle_regexp_RDOCLINK target
151
+ def handle_regexp_RDOCLINK(target)
147
152
  handle_RDOCLINK target.text
148
153
  end
149
154
 
@@ -192,7 +197,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
192
197
  ##
193
198
  # Adds +block_quote+ to the output
194
199
 
195
- def accept_block_quote block_quote
200
+ def accept_block_quote(block_quote)
196
201
  @res << "\n<blockquote>"
197
202
 
198
203
  block_quote.parts.each do |part|
@@ -205,7 +210,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
205
210
  ##
206
211
  # Adds +paragraph+ to the output
207
212
 
208
- def accept_paragraph paragraph
213
+ def accept_paragraph(paragraph)
209
214
  @res << "\n<p>"
210
215
  text = paragraph.text @hard_break
211
216
  text = text.gsub(/(#{SPACE_SEPARATED_LETTER_CLASS})?\K\r?\n(?=(?(1)(#{SPACE_SEPARATED_LETTER_CLASS})?))/o) {
@@ -218,7 +223,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
218
223
  ##
219
224
  # Adds +verbatim+ to the output
220
225
 
221
- def accept_verbatim verbatim
226
+ def accept_verbatim(verbatim)
222
227
  text = verbatim.text.rstrip
223
228
 
224
229
  klass = nil
@@ -248,7 +253,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
248
253
  ##
249
254
  # Adds +rule+ to the output
250
255
 
251
- def accept_rule rule
256
+ def accept_rule(rule)
252
257
  @res << "<hr>\n"
253
258
  end
254
259
 
@@ -301,7 +306,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
301
306
  # Adds +heading+ to the output. The headings greater than 6 are trimmed to
302
307
  # level 6.
303
308
 
304
- def accept_heading heading
309
+ def accept_heading(heading)
305
310
  level = [6, heading.level].min
306
311
 
307
312
  label = heading.label @code_object
@@ -322,14 +327,14 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
322
327
  ##
323
328
  # Adds +raw+ to the output
324
329
 
325
- def accept_raw raw
330
+ def accept_raw(raw)
326
331
  @res << raw.parts.join("\n")
327
332
  end
328
333
 
329
334
  ##
330
335
  # Adds +table+ to the output
331
336
 
332
- def accept_table header, body, aligns
337
+ def accept_table(header, body, aligns)
333
338
  @res << "\n<table role=\"table\">\n<thead>\n<tr>\n"
334
339
  header.zip(aligns) do |text, align|
335
340
  @res << '<th'
@@ -362,7 +367,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
362
367
  # Generate a link to +url+ with content +text+. Handles the special cases
363
368
  # for img: and link: described under handle_regexp_HYPERLINK
364
369
 
365
- def gen_url url, text
370
+ def gen_url(url, text)
366
371
  scheme, url, id = parse_url url
367
372
 
368
373
  if %w[http https link].include?(scheme) and
@@ -436,7 +441,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
436
441
  ##
437
442
  # Returns true if text is valid ruby syntax
438
443
 
439
- def parseable? text
444
+ def parseable?(text)
440
445
  verbose, $VERBOSE = $VERBOSE, nil
441
446
  catch(:valid) do
442
447
  eval("BEGIN { throw :valid, true }\n#{text}")
@@ -450,7 +455,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
450
455
  ##
451
456
  # Converts +item+ to HTML using RDoc::Text#to_html
452
457
 
453
- def to_html item
458
+ def to_html(item)
454
459
  super convert_flow @am.flow item
455
460
  end
456
461
 
@@ -58,7 +58,7 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
58
58
  # Creates a link to the reference +name+ if the name exists. If +text+ is
59
59
  # given it is used as the link text, otherwise +name+ is used.
60
60
 
61
- def cross_reference name, text = nil, code = true, rdoc_ref: false
61
+ def cross_reference(name, text = nil, code = true, rdoc_ref: false)
62
62
  lookup = name
63
63
 
64
64
  name = name[1..-1] unless @show_hash if name[0, 1] == '#'
@@ -101,7 +101,7 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
101
101
  # Handles <tt>rdoc-ref:</tt> scheme links and allows RDoc::Markup::ToHtml to
102
102
  # handle other schemes.
103
103
 
104
- def handle_regexp_HYPERLINK target
104
+ def handle_regexp_HYPERLINK(target)
105
105
  url = target.text
106
106
 
107
107
  case url
@@ -120,7 +120,7 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
120
120
  # All other contents are handled by
121
121
  # {the superclass}[rdoc-ref:RDoc::Markup::ToHtml#handle_regexp_RDOCLINK]
122
122
 
123
- def handle_regexp_RDOCLINK target
123
+ def handle_regexp_RDOCLINK(target)
124
124
  url = target.text
125
125
 
126
126
  case url
@@ -135,7 +135,7 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
135
135
  # Generates links for <tt>rdoc-ref:</tt> scheme URLs and allows
136
136
  # RDoc::Markup::ToHtml to handle other schemes.
137
137
 
138
- def gen_url url, text
138
+ def gen_url(url, text)
139
139
  if url =~ /\Ardoc-ref:/
140
140
  name = $'
141
141
  cross_reference name, text, name == text, rdoc_ref: true
@@ -147,7 +147,7 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
147
147
  ##
148
148
  # Creates an HTML link to +name+ with the given +text+.
149
149
 
150
- def link name, text, code = true, rdoc_ref: false
150
+ def link(name, text, code = true, rdoc_ref: false)
151
151
  if !(name.end_with?('+@', '-@')) and name =~ /(.*[^#:])?@/
152
152
  name = $1
153
153
  label = $'
@@ -34,7 +34,7 @@ class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
34
34
  # next word boundary after the given number of +characters+ or +paragraphs+
35
35
  # of text have been encountered.
36
36
 
37
- def initialize options, characters = 100, paragraphs = 3, markup = nil
37
+ def initialize(options, characters = 100, paragraphs = 3, markup = nil)
38
38
  super options, markup
39
39
 
40
40
  @character_limit = characters
@@ -50,7 +50,7 @@ class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
50
50
  ##
51
51
  # Adds +heading+ to the output as a paragraph
52
52
 
53
- def accept_heading heading
53
+ def accept_heading(heading)
54
54
  @res << "<p>#{to_html heading.text}\n"
55
55
 
56
56
  add_paragraph
@@ -69,7 +69,7 @@ class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
69
69
  ##
70
70
  # Adds +paragraph+ to the output
71
71
 
72
- def accept_paragraph paragraph
72
+ def accept_paragraph(paragraph)
73
73
  para = @in_list_entry.last || "<p>"
74
74
 
75
75
  text = paragraph.text @hard_break
@@ -82,20 +82,20 @@ class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
82
82
  ##
83
83
  # Finishes consumption of +list_item+
84
84
 
85
- def accept_list_item_end list_item
85
+ def accept_list_item_end(list_item)
86
86
  end
87
87
 
88
88
  ##
89
89
  # Prepares the visitor for consuming +list_item+
90
90
 
91
- def accept_list_item_start list_item
91
+ def accept_list_item_start(list_item)
92
92
  @res << list_item_start(list_item, @list.last)
93
93
  end
94
94
 
95
95
  ##
96
96
  # Prepares the visitor for consuming +list+
97
97
 
98
- def accept_list_start list
98
+ def accept_list_start(list)
99
99
  @list << list.type
100
100
  @res << html_list_name(list.type, true)
101
101
  @in_list_entry.push ''
@@ -104,7 +104,7 @@ class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
104
104
  ##
105
105
  # Adds +verbatim+ to the output
106
106
 
107
- def accept_verbatim verbatim
107
+ def accept_verbatim(verbatim)
108
108
  throw :done if @characters >= @character_limit
109
109
  input = verbatim.text.rstrip
110
110
 
@@ -128,14 +128,14 @@ class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
128
128
  ##
129
129
  # Removes escaping from the cross-references in +target+
130
130
 
131
- def handle_regexp_CROSSREF target
131
+ def handle_regexp_CROSSREF(target)
132
132
  target.text.sub(/\A\\/, '')
133
133
  end
134
134
 
135
135
  ##
136
136
  # +target+ is a <code><br></code>
137
137
 
138
- def handle_regexp_HARD_BREAK target
138
+ def handle_regexp_HARD_BREAK(target)
139
139
  @characters -= 4
140
140
  '<br>'
141
141
  end
@@ -143,7 +143,7 @@ class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
143
143
  ##
144
144
  # Lists are paragraphs, but notes and labels have a separator
145
145
 
146
- def list_item_start list_item, list_type
146
+ def list_item_start(list_item, list_type)
147
147
  throw :done if @characters >= @character_limit
148
148
 
149
149
  case list_type
@@ -168,7 +168,7 @@ class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
168
168
  # Returns just the text of +link+, +url+ is only used to determine the link
169
169
  # type.
170
170
 
171
- def gen_url url, text
171
+ def gen_url(url, text)
172
172
  if url =~ /^rdoc-label:([^:]*)(?::(.*))?/ then
173
173
  type = "link"
174
174
  elsif url =~ /([A-Za-z]+):(.*)/ then
@@ -188,7 +188,7 @@ class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
188
188
  ##
189
189
  # In snippets, there are no lists
190
190
 
191
- def html_list_name list_type, open_tag
191
+ def html_list_name(list_type, open_tag)
192
192
  ''
193
193
  end
194
194
 
@@ -204,7 +204,7 @@ class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
204
204
  ##
205
205
  # Marks up +content+
206
206
 
207
- def convert content
207
+ def convert(content)
208
208
  catch :done do
209
209
  return super
210
210
  end
@@ -215,7 +215,7 @@ class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
215
215
  ##
216
216
  # Converts flow items +flow+
217
217
 
218
- def convert_flow flow
218
+ def convert_flow(flow)
219
219
  throw :done if @characters >= @character_limit
220
220
 
221
221
  res = []
@@ -251,7 +251,7 @@ class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
251
251
  # Maintains a bitmask to allow HTML elements to be closed properly. See
252
252
  # RDoc::Markup::Formatter.
253
253
 
254
- def on_tags res, item
254
+ def on_tags(res, item)
255
255
  @mask ^= item.turn_on
256
256
 
257
257
  super
@@ -261,7 +261,7 @@ class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
261
261
  # Maintains a bitmask to allow HTML elements to be closed properly. See
262
262
  # RDoc::Markup::Formatter.
263
263
 
264
- def off_tags res, item
264
+ def off_tags(res, item)
265
265
  @mask ^= item.turn_off
266
266
 
267
267
  super
@@ -270,7 +270,7 @@ class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
270
270
  ##
271
271
  # Truncates +text+ at the end of the first word after the character_limit.
272
272
 
273
- def truncate text
273
+ def truncate(text)
274
274
  length = text.length
275
275
  characters = @characters
276
276
  @characters += length
@@ -22,7 +22,7 @@ class RDoc::Markup::ToJoinedParagraph < RDoc::Markup::Formatter
22
22
  ##
23
23
  # Converts the parts of +paragraph+ to a single entry.
24
24
 
25
- def accept_paragraph paragraph
25
+ def accept_paragraph(paragraph)
26
26
  parts = paragraph.parts.chunk do |part|
27
27
  String === part
28
28
  end.flat_map do |string, chunk|
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- require 'cgi/util'
2
+ require 'cgi/escape'
3
3
 
4
4
  ##
5
5
  # Creates HTML-safe labels suitable for use in id attributes. Tidylinks are
@@ -13,7 +13,7 @@ class RDoc::Markup::ToLabel < RDoc::Markup::Formatter
13
13
  ##
14
14
  # Creates a new formatter that will output HTML-safe labels
15
15
 
16
- def initialize markup = nil
16
+ def initialize(markup = nil)
17
17
  super nil, markup
18
18
 
19
19
  @markup.add_regexp_handling RDoc::CrossReference::CROSSREF_REGEXP, :CROSSREF
@@ -29,7 +29,7 @@ class RDoc::Markup::ToLabel < RDoc::Markup::Formatter
29
29
  ##
30
30
  # Converts +text+ to an HTML-safe label
31
31
 
32
- def convert text
32
+ def convert(text)
33
33
  label = convert_flow @am.flow text
34
34
 
35
35
  CGI.escape(label).gsub('%', '-').sub(/^-/, '')
@@ -39,7 +39,7 @@ class RDoc::Markup::ToLabel < RDoc::Markup::Formatter
39
39
  # Converts the CROSSREF +target+ to plain text, removing the suppression
40
40
  # marker, if any
41
41
 
42
- def handle_regexp_CROSSREF target
42
+ def handle_regexp_CROSSREF(target)
43
43
  text = target.text
44
44
 
45
45
  text.sub(/^\\/, '')
@@ -48,7 +48,7 @@ class RDoc::Markup::ToLabel < RDoc::Markup::Formatter
48
48
  ##
49
49
  # Converts the TIDYLINK +target+ to just the text part
50
50
 
51
- def handle_regexp_TIDYLINK target
51
+ def handle_regexp_TIDYLINK(target)
52
52
  text = target.text
53
53
 
54
54
  return text unless text =~ /\{(.*?)\}\[(.*?)\]/ or text =~ /(\S+)\[(.*?)\]/
@@ -9,7 +9,7 @@ class RDoc::Markup::ToMarkdown < RDoc::Markup::ToRdoc
9
9
  ##
10
10
  # Creates a new formatter that will output Markdown format text
11
11
 
12
- def initialize markup = nil
12
+ def initialize(markup = nil)
13
13
  super
14
14
 
15
15
  @headings[1] = ['# ', '']
@@ -37,21 +37,21 @@ class RDoc::Markup::ToMarkdown < RDoc::Markup::ToRdoc
37
37
  ##
38
38
  # Adds a newline to the output
39
39
 
40
- def handle_regexp_HARD_BREAK target
40
+ def handle_regexp_HARD_BREAK(target)
41
41
  " \n"
42
42
  end
43
43
 
44
44
  ##
45
45
  # Finishes consumption of `list`
46
46
 
47
- def accept_list_end list
47
+ def accept_list_end(list)
48
48
  super
49
49
  end
50
50
 
51
51
  ##
52
52
  # Finishes consumption of `list_item`
53
53
 
54
- def accept_list_item_end list_item
54
+ def accept_list_item_end(list_item)
55
55
  width = case @list_type.last
56
56
  when :BULLET then
57
57
  4
@@ -72,7 +72,7 @@ class RDoc::Markup::ToMarkdown < RDoc::Markup::ToRdoc
72
72
  ##
73
73
  # Prepares the visitor for consuming `list_item`
74
74
 
75
- def accept_list_item_start list_item
75
+ def accept_list_item_start(list_item)
76
76
  type = @list_type.last
77
77
 
78
78
  case type
@@ -97,7 +97,7 @@ class RDoc::Markup::ToMarkdown < RDoc::Markup::ToRdoc
97
97
  ##
98
98
  # Prepares the visitor for consuming `list`
99
99
 
100
- def accept_list_start list
100
+ def accept_list_start(list)
101
101
  case list.type
102
102
  when :BULLET, :LABEL, :NOTE then
103
103
  @list_index << nil
@@ -114,7 +114,7 @@ class RDoc::Markup::ToMarkdown < RDoc::Markup::ToRdoc
114
114
  ##
115
115
  # Adds `rule` to the output
116
116
 
117
- def accept_rule rule
117
+ def accept_rule(rule)
118
118
  use_prefix or @res << ' ' * @indent
119
119
  @res << '-' * 3
120
120
  @res << "\n"
@@ -123,7 +123,7 @@ class RDoc::Markup::ToMarkdown < RDoc::Markup::ToRdoc
123
123
  ##
124
124
  # Outputs `verbatim` indented 4 columns
125
125
 
126
- def accept_verbatim verbatim
126
+ def accept_verbatim(verbatim)
127
127
  indent = ' ' * (@indent + 4)
128
128
 
129
129
  verbatim.parts.each do |part|
@@ -137,7 +137,7 @@ class RDoc::Markup::ToMarkdown < RDoc::Markup::ToRdoc
137
137
  ##
138
138
  # Creates a Markdown-style URL from +url+ with +text+.
139
139
 
140
- def gen_url url, text
140
+ def gen_url(url, text)
141
141
  scheme, url, = parse_url url
142
142
 
143
143
  "[#{text.sub(%r{^#{scheme}:/*}i, '')}](#{url})"
@@ -146,7 +146,7 @@ class RDoc::Markup::ToMarkdown < RDoc::Markup::ToRdoc
146
146
  ##
147
147
  # Handles <tt>rdoc-</tt> type links for footnotes.
148
148
 
149
- def handle_rdoc_link url
149
+ def handle_rdoc_link(url)
150
150
  case url
151
151
  when /^rdoc-ref:/ then
152
152
  $'
@@ -166,7 +166,7 @@ class RDoc::Markup::ToMarkdown < RDoc::Markup::ToRdoc
166
166
  ##
167
167
  # Converts the RDoc markup tidylink into a Markdown.style link.
168
168
 
169
- def handle_regexp_TIDYLINK target
169
+ def handle_regexp_TIDYLINK(target)
170
170
  text = target.text
171
171
 
172
172
  return text unless text =~ /\{(.*?)\}\[(.*?)\]/ or text =~ /(\S+)\[(.*?)\]/
@@ -184,7 +184,7 @@ class RDoc::Markup::ToMarkdown < RDoc::Markup::ToRdoc
184
184
  ##
185
185
  # Converts the rdoc-...: links into a Markdown.style links.
186
186
 
187
- def handle_regexp_RDOCLINK target
187
+ def handle_regexp_RDOCLINK(target)
188
188
  handle_rdoc_link target.text
189
189
  end
190
190
 
@@ -3,6 +3,16 @@
3
3
  # Outputs RDoc markup as RDoc markup! (mostly)
4
4
 
5
5
  class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
6
+ DEFAULT_HEADINGS = {
7
+ 1 => ['= ', ''],
8
+ 2 => ['== ', ''],
9
+ 3 => ['=== ', ''],
10
+ 4 => ['==== ', ''],
11
+ 5 => ['===== ', ''],
12
+ 6 => ['====== ', '']
13
+ }
14
+ DEFAULT_HEADINGS.default = []
15
+ DEFAULT_HEADINGS.freeze
6
16
 
7
17
  ##
8
18
  # Current indent amount for output in characters
@@ -42,23 +52,14 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
42
52
  ##
43
53
  # Creates a new formatter that will output (mostly) \RDoc markup
44
54
 
45
- def initialize markup = nil
55
+ def initialize(markup = nil)
46
56
  super nil, markup
47
57
 
48
58
  @markup.add_regexp_handling(/\\\S/, :SUPPRESSED_CROSSREF)
49
59
  @width = 78
50
60
  init_tags
51
61
 
52
- @headings = {}
53
- @headings.default = []
54
-
55
- @headings[1] = ['= ', '']
56
- @headings[2] = ['== ', '']
57
- @headings[3] = ['=== ', '']
58
- @headings[4] = ['==== ', '']
59
- @headings[5] = ['===== ', '']
60
- @headings[6] = ['====== ', '']
61
-
62
+ @headings = DEFAULT_HEADINGS.dup
62
63
  @hard_break = "\n"
63
64
  end
64
65
 
@@ -74,14 +75,14 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
74
75
  ##
75
76
  # Adds +blank_line+ to the output
76
77
 
77
- def accept_blank_line blank_line
78
+ def accept_blank_line(blank_line)
78
79
  @res << "\n"
79
80
  end
80
81
 
81
82
  ##
82
83
  # Adds +paragraph+ to the output
83
84
 
84
- def accept_block_quote block_quote
85
+ def accept_block_quote(block_quote)
85
86
  @indent += 2
86
87
 
87
88
  block_quote.parts.each do |part|
@@ -96,7 +97,7 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
96
97
  ##
97
98
  # Adds +heading+ to the output
98
99
 
99
- def accept_heading heading
100
+ def accept_heading(heading)
100
101
  use_prefix or @res << ' ' * @indent
101
102
  @res << @headings[heading.level][0]
102
103
  @res << attributes(heading.text)
@@ -107,7 +108,7 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
107
108
  ##
108
109
  # Finishes consumption of +list+
109
110
 
110
- def accept_list_end list
111
+ def accept_list_end(list)
111
112
  @list_index.pop
112
113
  @list_type.pop
113
114
  @list_width.pop
@@ -116,7 +117,7 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
116
117
  ##
117
118
  # Finishes consumption of +list_item+
118
119
 
119
- def accept_list_item_end list_item
120
+ def accept_list_item_end(list_item)
120
121
  width = case @list_type.last
121
122
  when :BULLET then
122
123
  2
@@ -140,7 +141,7 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
140
141
  ##
141
142
  # Prepares the visitor for consuming +list_item+
142
143
 
143
- def accept_list_item_start list_item
144
+ def accept_list_item_start(list_item)
144
145
  type = @list_type.last
145
146
 
146
147
  case type
@@ -173,7 +174,7 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
173
174
  ##
174
175
  # Prepares the visitor for consuming +list+
175
176
 
176
- def accept_list_start list
177
+ def accept_list_start(list)
177
178
  case list.type
178
179
  when :BULLET then
179
180
  @list_index << nil
@@ -200,7 +201,7 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
200
201
  ##
201
202
  # Adds +paragraph+ to the output
202
203
 
203
- def accept_paragraph paragraph
204
+ def accept_paragraph(paragraph)
204
205
  text = paragraph.text @hard_break
205
206
  wrap attributes text
206
207
  end
@@ -208,7 +209,7 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
208
209
  ##
209
210
  # Adds +paragraph+ to the output
210
211
 
211
- def accept_indented_paragraph paragraph
212
+ def accept_indented_paragraph(paragraph)
212
213
  @indent += paragraph.indent
213
214
  text = paragraph.text @hard_break
214
215
  wrap attributes text
@@ -218,14 +219,14 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
218
219
  ##
219
220
  # Adds +raw+ to the output
220
221
 
221
- def accept_raw raw
222
+ def accept_raw(raw)
222
223
  @res << raw.parts.join("\n")
223
224
  end
224
225
 
225
226
  ##
226
227
  # Adds +rule+ to the output
227
228
 
228
- def accept_rule rule
229
+ def accept_rule(rule)
229
230
  use_prefix or @res << ' ' * @indent
230
231
  @res << '-' * (@width - @indent)
231
232
  @res << "\n"
@@ -234,7 +235,7 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
234
235
  ##
235
236
  # Outputs +verbatim+ indented 2 columns
236
237
 
237
- def accept_verbatim verbatim
238
+ def accept_verbatim(verbatim)
238
239
  indent = ' ' * (@indent + 2)
239
240
 
240
241
  verbatim.parts.each do |part|
@@ -248,7 +249,7 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
248
249
  ##
249
250
  # Adds +table+ to the output
250
251
 
251
- def accept_table header, body, aligns
252
+ def accept_table(header, body, aligns)
252
253
  widths = header.zip(*body).map do |cols|
253
254
  cols.map(&:size).max
254
255
  end
@@ -276,7 +277,7 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
276
277
  ##
277
278
  # Applies attribute-specific markup to +text+ using RDoc::AttributeManager
278
279
 
279
- def attributes text
280
+ def attributes(text)
280
281
  flow = @am.flow text.dup
281
282
  convert_flow flow
282
283
  end
@@ -291,7 +292,7 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
291
292
  ##
292
293
  # Removes preceding \\ from the suppressed crossref +target+
293
294
 
294
- def handle_regexp_SUPPRESSED_CROSSREF target
295
+ def handle_regexp_SUPPRESSED_CROSSREF(target)
295
296
  text = target.text
296
297
  text = text.sub('\\', '') unless in_tt?
297
298
  text
@@ -300,7 +301,7 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
300
301
  ##
301
302
  # Adds a newline to the output
302
303
 
303
- def handle_regexp_HARD_BREAK target
304
+ def handle_regexp_HARD_BREAK(target)
304
305
  "\n"
305
306
  end
306
307
 
@@ -331,7 +332,7 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
331
332
  ##
332
333
  # Wraps +text+ to #width
333
334
 
334
- def wrap text
335
+ def wrap(text)
335
336
  return unless text && !text.empty?
336
337
 
337
338
  text_len = @width - @indent