rdoc 6.17.0 → 7.2.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 (80) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +196 -0
  3. data/LEGAL.rdoc +6 -0
  4. data/README.md +90 -7
  5. data/doc/markup_reference/markdown.md +558 -0
  6. data/doc/markup_reference/rdoc.rdoc +1169 -0
  7. data/lib/rdoc/code_object/any_method.rb +15 -7
  8. data/lib/rdoc/code_object/attr.rb +2 -1
  9. data/lib/rdoc/code_object/class_module.rb +62 -11
  10. data/lib/rdoc/code_object/constant.rb +9 -0
  11. data/lib/rdoc/code_object/context/section.rb +46 -9
  12. data/lib/rdoc/code_object/context.rb +15 -4
  13. data/lib/rdoc/code_object/method_attr.rb +13 -1
  14. data/lib/rdoc/code_object/mixin.rb +3 -0
  15. data/lib/rdoc/code_object/top_level.rb +15 -1
  16. data/lib/rdoc/comment.rb +1 -1
  17. data/lib/rdoc/cross_reference.rb +31 -24
  18. data/lib/rdoc/generator/aliki.rb +141 -0
  19. data/lib/rdoc/generator/darkfish.rb +3 -1
  20. data/lib/rdoc/generator/template/aliki/_footer.rhtml +1 -1
  21. data/lib/rdoc/generator/template/aliki/_head.rhtml +9 -4
  22. data/lib/rdoc/generator/template/aliki/_header.rhtml +4 -4
  23. data/lib/rdoc/generator/template/aliki/_sidebar_pages.rhtml +1 -1
  24. data/lib/rdoc/generator/template/aliki/_sidebar_search.rhtml +3 -3
  25. data/lib/rdoc/generator/template/aliki/class.rhtml +17 -17
  26. data/lib/rdoc/generator/template/aliki/css/rdoc.css +278 -60
  27. data/lib/rdoc/generator/template/aliki/index.rhtml +1 -1
  28. data/lib/rdoc/generator/template/aliki/js/aliki.js +51 -23
  29. data/lib/rdoc/generator/template/aliki/js/bash_highlighter.js +167 -0
  30. data/lib/rdoc/generator/template/aliki/js/c_highlighter.js +1 -1
  31. data/lib/rdoc/generator/template/aliki/js/{search.js → search_controller.js} +16 -7
  32. data/lib/rdoc/generator/template/aliki/js/search_navigation.js +105 -0
  33. data/lib/rdoc/generator/template/aliki/js/search_ranker.js +239 -0
  34. data/lib/rdoc/generator/template/aliki/page.rhtml +1 -1
  35. data/lib/rdoc/generator/template/aliki/servlet_not_found.rhtml +1 -1
  36. data/lib/rdoc/generator/template/aliki/servlet_root.rhtml +1 -1
  37. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +1 -1
  38. data/lib/rdoc/generator/template/darkfish/class.rhtml +11 -11
  39. data/lib/rdoc/generator/template/darkfish/css/rdoc.css +19 -0
  40. data/lib/rdoc/markdown.kpeg +22 -12
  41. data/lib/rdoc/markdown.rb +36 -26
  42. data/lib/rdoc/markup/blank_line.rb +25 -23
  43. data/lib/rdoc/markup/element.rb +21 -0
  44. data/lib/rdoc/markup/formatter.rb +129 -106
  45. data/lib/rdoc/markup/hard_break.rb +30 -27
  46. data/lib/rdoc/markup/heading.rb +166 -77
  47. data/lib/rdoc/markup/inline_parser.rb +312 -0
  48. data/lib/rdoc/markup/parser.rb +1 -1
  49. data/lib/rdoc/markup/raw.rb +52 -55
  50. data/lib/rdoc/markup/table.rb +48 -40
  51. data/lib/rdoc/markup/to_ansi.rb +51 -4
  52. data/lib/rdoc/markup/to_bs.rb +22 -42
  53. data/lib/rdoc/markup/to_html.rb +178 -183
  54. data/lib/rdoc/markup/to_html_crossref.rb +58 -79
  55. data/lib/rdoc/markup/to_html_snippet.rb +62 -62
  56. data/lib/rdoc/markup/to_label.rb +29 -20
  57. data/lib/rdoc/markup/to_markdown.rb +61 -37
  58. data/lib/rdoc/markup/to_rdoc.rb +86 -26
  59. data/lib/rdoc/markup/to_test.rb +9 -1
  60. data/lib/rdoc/markup/to_tt_only.rb +10 -16
  61. data/lib/rdoc/markup/verbatim.rb +1 -1
  62. data/lib/rdoc/markup.rb +11 -32
  63. data/lib/rdoc/options.rb +1 -1
  64. data/lib/rdoc/parser/changelog.rb +29 -0
  65. data/lib/rdoc/parser/prism_ruby.rb +44 -32
  66. data/lib/rdoc/parser/ruby.rb +1 -1
  67. data/lib/rdoc/rubygems_hook.rb +3 -3
  68. data/lib/rdoc/text.rb +44 -5
  69. data/lib/rdoc/token_stream.rb +4 -8
  70. data/lib/rdoc/version.rb +1 -1
  71. data/rdoc.gemspec +3 -3
  72. metadata +13 -15
  73. data/CONTRIBUTING.rdoc +0 -219
  74. data/ExampleMarkdown.md +0 -39
  75. data/ExampleRDoc.rdoc +0 -210
  76. data/lib/rdoc/markup/attr_changer.rb +0 -22
  77. data/lib/rdoc/markup/attr_span.rb +0 -35
  78. data/lib/rdoc/markup/attribute_manager.rb +0 -405
  79. data/lib/rdoc/markup/attributes.rb +0 -70
  80. data/lib/rdoc/markup/regexp_handling.rb +0 -40
@@ -1,405 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- ##
4
- # Manages changes of attributes in a block of text
5
-
6
- class RDoc::Markup::AttributeManager
7
- unless ::MatchData.method_defined?(:match_length)
8
- using ::Module.new {
9
- refine(::MatchData) {
10
- def match_length(nth) # :nodoc:
11
- b, e = offset(nth)
12
- e - b if b
13
- end
14
- }
15
- }
16
- end
17
-
18
- ##
19
- # The NUL character
20
-
21
- NULL = "\000".freeze
22
-
23
- #--
24
- # We work by substituting non-printing characters in to the text. For now
25
- # I'm assuming that I can substitute a character in the range 0..8 for a 7
26
- # bit character without damaging the encoded string, but this might be
27
- # optimistic
28
- #++
29
-
30
- A_PROTECT = 004 # :nodoc:
31
-
32
- ##
33
- # Special mask character to prevent inline markup handling
34
-
35
- PROTECT_ATTR = A_PROTECT.chr # :nodoc:
36
-
37
- ##
38
- # The attributes enabled for this markup object.
39
-
40
- attr_reader :attributes
41
-
42
- ##
43
- # This maps delimiters that occur around words (such as *bold* or +tt+)
44
- # where the start and end delimiters and the same. This lets us optimize
45
- # the regexp
46
-
47
- attr_reader :matching_word_pairs
48
-
49
- ##
50
- # And this is used when the delimiters aren't the same. In this case the
51
- # hash maps a pattern to the attribute character
52
-
53
- attr_reader :word_pair_map
54
-
55
- ##
56
- # This maps HTML tags to the corresponding attribute char
57
-
58
- attr_reader :html_tags
59
-
60
- ##
61
- # A \ in front of a character that would normally be processed turns off
62
- # processing. We do this by turning \< into <#{PROTECT}
63
-
64
- attr_reader :protectable
65
-
66
- ##
67
- # And this maps _regexp handling_ sequences to a name. A regexp handling
68
- # sequence is something like a WikiWord
69
-
70
- attr_reader :regexp_handlings
71
-
72
- ##
73
- # A bits of exclusive maps
74
- attr_reader :exclusive_bitmap
75
-
76
- ##
77
- # Creates a new attribute manager that understands bold, emphasized and
78
- # teletype text.
79
-
80
- def initialize
81
- @html_tags = {}
82
- @matching_word_pairs = {}
83
- @protectable = %w[<]
84
- @regexp_handlings = []
85
- @word_pair_map = {}
86
- @exclusive_bitmap = 0
87
- @attributes = RDoc::Markup::Attributes.new
88
-
89
- add_word_pair "*", "*", :BOLD, true
90
- add_word_pair "_", "_", :EM, true
91
- add_word_pair "+", "+", :TT, true
92
-
93
- add_html "em", :EM, true
94
- add_html "i", :EM, true
95
- add_html "b", :BOLD, true
96
- add_html "tt", :TT, true
97
- add_html "code", :TT, true
98
- end
99
-
100
- ##
101
- # Return an attribute object with the given turn_on and turn_off bits set
102
-
103
- def attribute(turn_on, turn_off)
104
- RDoc::Markup::AttrChanger.new turn_on, turn_off
105
- end
106
-
107
- ##
108
- # Changes the current attribute from +current+ to +new+
109
-
110
- def change_attribute(current, new)
111
- diff = current ^ new
112
- attribute(new & diff, current & diff)
113
- end
114
-
115
- ##
116
- # Used by the tests to change attributes by name from +current_set+ to
117
- # +new_set+
118
-
119
- def changed_attribute_by_name(current_set, new_set)
120
- current = new = 0
121
- current_set.each do |name|
122
- current |= @attributes.bitmap_for(name)
123
- end
124
-
125
- new_set.each do |name|
126
- new |= @attributes.bitmap_for(name)
127
- end
128
-
129
- change_attribute(current, new)
130
- end
131
-
132
- ##
133
- # Copies +start_pos+ to +end_pos+ from the current string
134
-
135
- def copy_string(start_pos, end_pos)
136
- res = @str[start_pos...end_pos]
137
- res.gsub!(/\000/, '')
138
- res
139
- end
140
-
141
- # :nodoc:
142
- def exclusive?(attr)
143
- (attr & @exclusive_bitmap) != 0
144
- end
145
-
146
- NON_PRINTING_START = "\1" # :nodoc:
147
- NON_PRINTING_END = "\2" # :nodoc:
148
-
149
- ##
150
- # Map attributes like <b>text</b>to the sequence
151
- # \001\002<char>\001\003<char>, where <char> is a per-attribute specific
152
- # character
153
-
154
- def convert_attrs(str, attrs, exclusive = false)
155
- convert_attrs_matching_word_pairs(str, attrs, exclusive)
156
- convert_attrs_word_pair_map(str, attrs, exclusive)
157
- end
158
-
159
- # :nodoc:
160
- def convert_attrs_matching_word_pairs(str, attrs, exclusive)
161
- # first do matching ones
162
- tags = @matching_word_pairs.select { |start, bitmap|
163
- exclusive == exclusive?(bitmap)
164
- }.keys
165
- return if tags.empty?
166
- tags = "[#{tags.join("")}](?!#{PROTECT_ATTR})"
167
- all_tags = "[#{@matching_word_pairs.keys.join("")}](?!#{PROTECT_ATTR})"
168
-
169
- re = /(?:^|\W|#{all_tags})\K(#{tags})(\1*[#\\]?[\w:#{PROTECT_ATTR}.\/\[\]-]+?\S?)\1(?!\1)(?=#{all_tags}|\W|$)/
170
-
171
- 1 while str.gsub!(re) { |orig|
172
- a, w = (m = $~).values_at(1, 2)
173
- attr = @matching_word_pairs[a]
174
- if attrs.set_attrs(m.begin(2), w.length, attr)
175
- a = NULL * a.length
176
- else
177
- a = NON_PRINTING_START + a + NON_PRINTING_END
178
- end
179
- a + w + a
180
- }
181
- str.delete!(NON_PRINTING_START + NON_PRINTING_END)
182
- end
183
-
184
- # :nodoc:
185
- def convert_attrs_word_pair_map(str, attrs, exclusive)
186
- # then non-matching
187
- unless @word_pair_map.empty? then
188
- @word_pair_map.each do |regexp, attr|
189
- next unless exclusive == exclusive?(attr)
190
- 1 while str.gsub!(regexp) { |orig|
191
- w = (m = ($~))[2]
192
- updated = attrs.set_attrs(m.begin(2), w.length, attr)
193
- if updated
194
- NULL * m.match_length(1) + w + NULL * m.match_length(3)
195
- else
196
- orig
197
- end
198
- }
199
- end
200
- end
201
- end
202
-
203
- ##
204
- # Converts HTML tags to RDoc attributes
205
-
206
- def convert_html(str, attrs, exclusive = false)
207
- tags = @html_tags.select { |start, bitmap|
208
- exclusive == exclusive?(bitmap)
209
- }.keys.join '|'
210
-
211
- 1 while str.gsub!(/<(#{tags})>(.*?)<\/\1>/i) { |orig|
212
- attr = @html_tags[$1.downcase]
213
- html_length = $~.match_length(1) + 2 # "<>".length
214
- seq = NULL * html_length
215
- attrs.set_attrs($~.begin(2), $~.match_length(2), attr)
216
- seq + $2 + seq + NULL
217
- }
218
- end
219
-
220
- ##
221
- # Converts regexp handling sequences to RDoc attributes
222
-
223
- def convert_regexp_handlings(str, attrs, exclusive = false)
224
- @regexp_handlings.each do |regexp, attribute|
225
- next unless exclusive == exclusive?(attribute)
226
- str.scan(regexp) do
227
- capture = $~.size == 1 ? 0 : 1
228
-
229
- s, e = $~.offset capture
230
-
231
- attrs.set_attrs s, e - s, attribute | @attributes.regexp_handling
232
- end
233
- end
234
- end
235
-
236
- ##
237
- # Escapes regexp handling sequences of text to prevent conversion to RDoc
238
-
239
- def mask_protected_sequences
240
- # protect __send__, __FILE__, etc.
241
- @str.gsub!(/__([a-z]+)__/i,
242
- "_#{PROTECT_ATTR}_#{PROTECT_ATTR}\\1_#{PROTECT_ATTR}_#{PROTECT_ATTR}")
243
- @str.gsub!(/(\A|[^\\])\\([#{Regexp.escape @protectable.join}])/m,
244
- "\\1\\2#{PROTECT_ATTR}")
245
- @str.gsub!(/\\(\\[#{Regexp.escape @protectable.join}])/m, "\\1")
246
- end
247
-
248
- ##
249
- # Unescapes regexp handling sequences of text
250
-
251
- def unmask_protected_sequences
252
- @str.gsub!(/(.)#{PROTECT_ATTR}/, "\\1\000")
253
- end
254
-
255
- ##
256
- # Adds a markup class with +name+ for words wrapped in the +start+ and
257
- # +stop+ character. To make words wrapped with "*" bold:
258
- #
259
- # am.add_word_pair '*', '*', :BOLD
260
-
261
- def add_word_pair(start, stop, name, exclusive = false)
262
- raise ArgumentError, "Word flags may not start with '<'" if
263
- start[0, 1] == '<'
264
-
265
- bitmap = @attributes.bitmap_for name
266
-
267
- if start == stop then
268
- @matching_word_pairs[start] = bitmap
269
- else
270
- pattern = /(#{Regexp.escape start})(\S+)(#{Regexp.escape stop})/
271
- @word_pair_map[pattern] = bitmap
272
- end
273
-
274
- @protectable << start[0, 1]
275
- @protectable.uniq!
276
-
277
- @exclusive_bitmap |= bitmap if exclusive
278
- end
279
-
280
- ##
281
- # Adds a markup class with +name+ for words surrounded by HTML tag +tag+.
282
- # To process emphasis tags:
283
- #
284
- # am.add_html 'em', :EM
285
-
286
- def add_html(tag, name, exclusive = false)
287
- bitmap = @attributes.bitmap_for name
288
- @html_tags[tag.downcase] = bitmap
289
- @exclusive_bitmap |= bitmap if exclusive
290
- end
291
-
292
- ##
293
- # Adds a regexp handling for +pattern+ with +name+. A simple URL handler
294
- # would be:
295
- #
296
- # @am.add_regexp_handling(/((https?:)\S+\w)/, :HYPERLINK)
297
-
298
- def add_regexp_handling(pattern, name, exclusive = false)
299
- bitmap = @attributes.bitmap_for(name)
300
- @regexp_handlings << [pattern, bitmap]
301
- @exclusive_bitmap |= bitmap if exclusive
302
- end
303
-
304
- ##
305
- # Processes +str+ converting attributes, HTML and regexp handlings
306
-
307
- def flow(str)
308
- @str = str.dup
309
-
310
- mask_protected_sequences
311
-
312
- @attrs = RDoc::Markup::AttrSpan.new @str.length, @exclusive_bitmap
313
-
314
- convert_attrs @str, @attrs, true
315
- convert_html @str, @attrs, true
316
- convert_regexp_handlings @str, @attrs, true
317
- convert_attrs @str, @attrs
318
- convert_html @str, @attrs
319
- convert_regexp_handlings @str, @attrs
320
-
321
- unmask_protected_sequences
322
-
323
- split_into_flow
324
- end
325
-
326
- ##
327
- # Debug method that prints a string along with its attributes
328
-
329
- def display_attributes
330
- puts
331
- puts @str.tr(NULL, "!")
332
- bit = 1
333
- 16.times do |bno|
334
- line = ""
335
- @str.length.times do |i|
336
- if (@attrs[i] & bit) == 0
337
- line << " "
338
- else
339
- if bno.zero?
340
- line << "S"
341
- else
342
- line << ("%d" % (bno+1))
343
- end
344
- end
345
- end
346
- puts(line) unless line =~ /^ *$/
347
- bit <<= 1
348
- end
349
- end
350
-
351
- ##
352
- # Splits the string into chunks by attribute change
353
-
354
- def split_into_flow
355
- res = []
356
- current_attr = 0
357
-
358
- str_len = @str.length
359
-
360
- # skip leading invisible text
361
- i = 0
362
- i += 1 while i < str_len and @str[i].chr == "\0"
363
- start_pos = i
364
-
365
- # then scan the string, chunking it on attribute changes
366
- while i < str_len
367
- new_attr = @attrs[i]
368
- if new_attr != current_attr
369
- if i > start_pos
370
- res << copy_string(start_pos, i)
371
- start_pos = i
372
- end
373
-
374
- res << change_attribute(current_attr, new_attr)
375
- current_attr = new_attr
376
-
377
- if (current_attr & @attributes.regexp_handling) != 0 then
378
- i += 1 while
379
- i < str_len and (@attrs[i] & @attributes.regexp_handling) != 0
380
-
381
- res << RDoc::Markup::RegexpHandling.new(current_attr,
382
- copy_string(start_pos, i))
383
- start_pos = i
384
- next
385
- end
386
- end
387
-
388
- # move on, skipping any invisible characters
389
- begin
390
- i += 1
391
- end while i < str_len and @str[i].chr == "\0"
392
- end
393
-
394
- # tidy up trailing text
395
- if start_pos < str_len
396
- res << copy_string(start_pos, str_len)
397
- end
398
-
399
- # and reset to all attributes off
400
- res << change_attribute(current_attr, 0) if current_attr != 0
401
-
402
- res
403
- end
404
-
405
- end
@@ -1,70 +0,0 @@
1
- # frozen_string_literal: true
2
- ##
3
- # We manage a set of attributes. Each attribute has a symbol name and a bit
4
- # value.
5
-
6
- class RDoc::Markup::Attributes
7
-
8
- ##
9
- # The regexp handling attribute type. See RDoc::Markup#add_regexp_handling
10
-
11
- attr_reader :regexp_handling
12
-
13
- ##
14
- # Creates a new attributes set.
15
-
16
- def initialize
17
- @regexp_handling = 1
18
-
19
- @name_to_bitmap = [
20
- [:_REGEXP_HANDLING_, @regexp_handling],
21
- ]
22
-
23
- @next_bitmap = @regexp_handling << 1
24
- end
25
-
26
- ##
27
- # Returns a unique bit for +name+
28
-
29
- def bitmap_for(name)
30
- bitmap = @name_to_bitmap.assoc name
31
-
32
- unless bitmap then
33
- bitmap = @next_bitmap
34
- @next_bitmap <<= 1
35
- @name_to_bitmap << [name, bitmap]
36
- else
37
- bitmap = bitmap.last
38
- end
39
-
40
- bitmap
41
- end
42
-
43
- ##
44
- # Returns a string representation of +bitmap+
45
-
46
- def as_string(bitmap)
47
- return 'none' if bitmap.zero?
48
- res = []
49
-
50
- @name_to_bitmap.each do |name, bit|
51
- res << name if (bitmap & bit) != 0
52
- end
53
-
54
- res.join ','
55
- end
56
-
57
- ##
58
- # yields each attribute name in +bitmap+
59
-
60
- def each_name_of(bitmap)
61
- return enum_for __method__, bitmap unless block_given?
62
-
63
- @name_to_bitmap.each do |name, bit|
64
- next if bit == @regexp_handling
65
-
66
- yield name.to_s if (bitmap & bit) != 0
67
- end
68
- end
69
-
70
- end
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
- ##
3
- # Hold details of a regexp handling sequence
4
-
5
- class RDoc::Markup::RegexpHandling
6
-
7
- ##
8
- # Regexp handling type
9
-
10
- attr_reader :type
11
-
12
- ##
13
- # Regexp handling text
14
-
15
- attr_accessor :text
16
-
17
- ##
18
- # Creates a new regexp handling sequence of +type+ with +text+
19
-
20
- def initialize(type, text)
21
- @type, @text = type, text
22
- end
23
-
24
- ##
25
- # Regexp handlings are equal when the have the same text and type
26
-
27
- def ==(o)
28
- self.text == o.text && self.type == o.type
29
- end
30
-
31
- def inspect # :nodoc:
32
- "#<RDoc::Markup::RegexpHandling:0x%x @type=%p, @text=%p>" % [
33
- object_id, @type, text.dump]
34
- end
35
-
36
- def to_s # :nodoc:
37
- "RegexpHandling: type=#{type} text=#{text.dump}"
38
- end
39
-
40
- end