rdoc 3.9.5 → 3.10.pre.1

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 (183) hide show
  1. data.tar.gz.sig +0 -0
  2. data/.autotest +6 -3
  3. data/History.txt +63 -13
  4. data/LICENSE.rdoc +57 -0
  5. data/Manifest.txt +60 -6
  6. data/Rakefile +24 -12
  7. data/TODO.rdoc +30 -0
  8. data/bin/rdoc +0 -2
  9. data/lib/rdoc.rb +55 -2
  10. data/lib/rdoc/alias.rb +0 -2
  11. data/lib/rdoc/anon_class.rb +0 -2
  12. data/lib/rdoc/any_method.rb +0 -3
  13. data/lib/rdoc/attr.rb +0 -2
  14. data/lib/rdoc/class_module.rb +40 -7
  15. data/lib/rdoc/code_object.rb +1 -3
  16. data/lib/rdoc/code_objects.rb +3 -21
  17. data/lib/rdoc/comment.rb +225 -0
  18. data/lib/rdoc/constant.rb +0 -2
  19. data/lib/rdoc/context.rb +37 -120
  20. data/lib/rdoc/context/section.rb +114 -0
  21. data/lib/rdoc/cross_reference.rb +16 -7
  22. data/lib/rdoc/encoding.rb +0 -2
  23. data/lib/rdoc/gauntlet.rb +1 -1
  24. data/lib/rdoc/generator.rb +7 -2
  25. data/lib/rdoc/generator/darkfish.rb +126 -20
  26. data/lib/rdoc/generator/json_index.rb +240 -0
  27. data/lib/rdoc/generator/markup.rb +17 -54
  28. data/lib/rdoc/generator/ri.rb +0 -3
  29. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +5 -0
  30. data/lib/rdoc/generator/template/darkfish/_head.rhtml +16 -0
  31. data/lib/rdoc/generator/template/darkfish/_sidebar_VCS_info.rhtml +18 -0
  32. data/lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml +9 -0
  33. data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +8 -0
  34. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +16 -0
  35. data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +12 -0
  36. data/lib/rdoc/generator/template/darkfish/_sidebar_navigation.rhtml +7 -0
  37. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +12 -0
  38. data/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml +10 -0
  39. data/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml +10 -0
  40. data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +10 -0
  41. data/lib/rdoc/generator/template/darkfish/class.rhtml +161 -0
  42. data/lib/rdoc/generator/template/darkfish/fileinfo.rhtml +32 -0
  43. data/lib/rdoc/generator/template/darkfish/images/add.png +0 -0
  44. data/lib/rdoc/generator/template/darkfish/images/delete.png +0 -0
  45. data/lib/rdoc/generator/template/darkfish/images/tag_blue.png +0 -0
  46. data/lib/rdoc/generator/template/darkfish/images/transparent.png +0 -0
  47. data/lib/rdoc/generator/template/darkfish/index.rhtml +16 -61
  48. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +99 -64
  49. data/lib/rdoc/generator/template/darkfish/js/jquery.js +15 -29
  50. data/lib/rdoc/generator/template/darkfish/js/search.js +94 -0
  51. data/lib/rdoc/generator/template/darkfish/page.rhtml +16 -0
  52. data/lib/rdoc/generator/template/darkfish/rdoc.css +126 -286
  53. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +50 -0
  54. data/lib/rdoc/generator/template/json_index/js/navigation.js +142 -0
  55. data/lib/rdoc/generator/template/json_index/js/searcher.js +228 -0
  56. data/lib/rdoc/ghost_method.rb +0 -2
  57. data/lib/rdoc/include.rb +0 -2
  58. data/lib/rdoc/markup.rb +204 -43
  59. data/lib/rdoc/markup/attr_changer.rb +25 -0
  60. data/lib/rdoc/markup/attr_span.rb +29 -0
  61. data/lib/rdoc/markup/attribute.rb +51 -0
  62. data/lib/rdoc/markup/document.rb +22 -1
  63. data/lib/rdoc/markup/formatter.rb +4 -11
  64. data/lib/rdoc/markup/formatter_test_case.rb +1 -2
  65. data/lib/rdoc/markup/heading.rb +44 -0
  66. data/lib/rdoc/markup/include.rb +42 -0
  67. data/lib/rdoc/markup/inline.rb +1 -144
  68. data/lib/rdoc/markup/list.rb +2 -1
  69. data/lib/rdoc/markup/parser.rb +6 -16
  70. data/lib/rdoc/markup/pre_process.rb +64 -10
  71. data/lib/rdoc/markup/raw.rb +1 -1
  72. data/lib/rdoc/markup/special.rb +40 -0
  73. data/lib/rdoc/markup/text_formatter_test_case.rb +0 -2
  74. data/lib/rdoc/markup/to_ansi.rb +0 -2
  75. data/lib/rdoc/markup/to_bs.rb +0 -2
  76. data/lib/rdoc/markup/to_html.rb +102 -34
  77. data/lib/rdoc/markup/to_html_crossref.rb +36 -5
  78. data/lib/rdoc/markup/to_html_snippet.rb +270 -0
  79. data/lib/rdoc/markup/to_label.rb +55 -0
  80. data/lib/rdoc/markup/to_rdoc.rb +0 -3
  81. data/lib/rdoc/markup/to_table_of_contents.rb +62 -0
  82. data/lib/rdoc/markup/to_test.rb +0 -3
  83. data/lib/rdoc/markup/to_tt_only.rb +0 -3
  84. data/lib/rdoc/markup/verbatim.rb +18 -0
  85. data/lib/rdoc/meta_method.rb +0 -2
  86. data/lib/rdoc/method_attr.rb +17 -1
  87. data/lib/rdoc/normal_class.rb +0 -2
  88. data/lib/rdoc/normal_module.rb +0 -2
  89. data/lib/rdoc/options.rb +18 -3
  90. data/lib/rdoc/parser.rb +74 -42
  91. data/lib/rdoc/parser/c.rb +79 -118
  92. data/lib/rdoc/parser/rd.rb +22 -0
  93. data/lib/rdoc/parser/ruby.rb +86 -54
  94. data/lib/rdoc/parser/simple.rb +21 -9
  95. data/lib/rdoc/parser/text.rb +11 -0
  96. data/lib/rdoc/rd.rb +95 -0
  97. data/lib/rdoc/rd/block_parser.ry +638 -0
  98. data/lib/rdoc/rd/inline.rb +71 -0
  99. data/lib/rdoc/rd/inline_parser.ry +575 -0
  100. data/lib/rdoc/rdoc.rb +8 -23
  101. data/lib/rdoc/require.rb +0 -2
  102. data/lib/rdoc/ri.rb +4 -2
  103. data/lib/rdoc/ri/driver.rb +2 -6
  104. data/lib/rdoc/ri/store.rb +0 -1
  105. data/lib/rdoc/ruby_lex.rb +43 -20
  106. data/lib/rdoc/ruby_token.rb +44 -2
  107. data/lib/rdoc/single_class.rb +0 -2
  108. data/lib/rdoc/stats.rb +0 -5
  109. data/lib/rdoc/task.rb +2 -6
  110. data/lib/rdoc/test_case.rb +59 -0
  111. data/lib/rdoc/text.rb +42 -30
  112. data/lib/rdoc/token_stream.rb +45 -0
  113. data/lib/rdoc/tom_doc.rb +232 -0
  114. data/lib/rdoc/top_level.rb +36 -4
  115. data/test/test_attribute_manager.rb +26 -29
  116. data/test/test_rdoc_any_method.rb +2 -26
  117. data/test/test_rdoc_attr.rb +4 -4
  118. data/test/test_rdoc_class_module.rb +95 -12
  119. data/test/test_rdoc_code_object.rb +10 -3
  120. data/test/test_rdoc_comment.rb +504 -0
  121. data/test/test_rdoc_context.rb +60 -11
  122. data/test/test_rdoc_context_section.rb +16 -17
  123. data/test/test_rdoc_cross_reference.rb +17 -2
  124. data/test/test_rdoc_encoding.rb +4 -7
  125. data/test/test_rdoc_generator_darkfish.rb +12 -11
  126. data/test/test_rdoc_generator_json_index.rb +255 -0
  127. data/test/test_rdoc_generator_markup.rb +56 -0
  128. data/test/test_rdoc_generator_ri.rb +8 -11
  129. data/test/test_rdoc_markup.rb +9 -5
  130. data/test/test_rdoc_markup_attribute_manager.rb +5 -8
  131. data/test/test_rdoc_markup_document.rb +34 -6
  132. data/test/test_rdoc_markup_formatter.rb +11 -13
  133. data/test/test_rdoc_markup_heading.rb +20 -0
  134. data/test/test_rdoc_markup_include.rb +19 -0
  135. data/test/test_rdoc_markup_indented_paragraph.rb +4 -5
  136. data/test/test_rdoc_markup_paragraph.rb +2 -5
  137. data/test/test_rdoc_markup_parser.rb +87 -7
  138. data/test/test_rdoc_markup_pre_process.rb +60 -9
  139. data/test/test_rdoc_markup_raw.rb +4 -6
  140. data/test/test_rdoc_markup_to_ansi.rb +1 -4
  141. data/test/test_rdoc_markup_to_bs.rb +1 -4
  142. data/test/test_rdoc_markup_to_html.rb +170 -31
  143. data/test/test_rdoc_markup_to_html_crossref.rb +89 -11
  144. data/test/test_rdoc_markup_to_html_snippet.rb +668 -0
  145. data/test/test_rdoc_markup_to_label.rb +50 -0
  146. data/test/test_rdoc_markup_to_rdoc.rb +1 -4
  147. data/test/test_rdoc_markup_to_table_of_contents.rb +90 -0
  148. data/test/test_rdoc_markup_to_tt_only.rb +1 -4
  149. data/test/test_rdoc_markup_verbatim.rb +16 -0
  150. data/test/test_rdoc_method_attr.rb +16 -1
  151. data/test/test_rdoc_options.rb +17 -7
  152. data/test/test_rdoc_parser.rb +75 -6
  153. data/test/test_rdoc_parser_c.rb +56 -104
  154. data/test/test_rdoc_parser_rd.rb +52 -0
  155. data/test/test_rdoc_parser_ruby.rb +264 -323
  156. data/test/test_rdoc_parser_simple.rb +33 -17
  157. data/test/test_rdoc_rd.rb +30 -0
  158. data/test/test_rdoc_rd_block_parser.rb +527 -0
  159. data/test/test_rdoc_rd_inline.rb +63 -0
  160. data/test/test_rdoc_rd_inline_parser.rb +173 -0
  161. data/test/test_rdoc_rdoc.rb +7 -9
  162. data/test/test_rdoc_ri_driver.rb +10 -15
  163. data/test/test_rdoc_ri_paths.rb +6 -6
  164. data/test/test_rdoc_ri_store.rb +6 -13
  165. data/test/test_rdoc_ruby_lex.rb +53 -5
  166. data/test/test_rdoc_rubygems_hook.rb +2 -1
  167. data/test/test_rdoc_stats.rb +83 -103
  168. data/test/test_rdoc_task.rb +5 -4
  169. data/test/test_rdoc_text.rb +156 -11
  170. data/test/test_rdoc_token_stream.rb +42 -0
  171. data/test/test_rdoc_tom_doc.rb +458 -0
  172. data/test/test_rdoc_top_level.rb +49 -2
  173. data/test/xref_test_case.rb +4 -8
  174. metadata +217 -111
  175. metadata.gz.sig +0 -0
  176. checksums.yaml +0 -7
  177. checksums.yaml.gz.sig +0 -0
  178. data/CVE-2013-0256.rdoc +0 -49
  179. data/LICENSE.txt +0 -57
  180. data/lib/rdoc/generator/template/darkfish/classpage.rhtml +0 -321
  181. data/lib/rdoc/generator/template/darkfish/filepage.rhtml +0 -124
  182. data/lib/rdoc/generator/template/darkfish/js/quicksearch.js +0 -114
  183. data/lib/rdoc/generator/template/darkfish/js/thickbox-compressed.js +0 -10
@@ -1,6 +1,3 @@
1
- require 'rdoc/markup/to_html'
2
- require 'rdoc/cross_reference'
3
-
4
1
  ##
5
2
  # Subclass of the RDoc::Markup::ToHtml class that supports looking up method
6
3
  # names, classes, etc to create links. RDoc::CrossReference is used to
@@ -41,8 +38,8 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
41
38
  @cross_reference = RDoc::CrossReference.new context
42
39
 
43
40
  @markup.add_special crossref_re, :CROSSREF
44
- @markup.add_special(/rdoc-ref:\S+\w/, :HYPERLINK)
45
41
 
42
+ @context = context
46
43
  @from_path = from_path
47
44
  @hyperlink_all = hyperlink_all
48
45
  @show_hash = show_hash
@@ -57,6 +54,8 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
57
54
 
58
55
  name = name[1..-1] unless @show_hash if name[0, 1] == '#'
59
56
 
57
+ name = "#{CGI.unescape $'} at #{$1}" if name =~ /(.*[^#:])@/
58
+
60
59
  text = name unless text
61
60
 
62
61
  link lookup, text
@@ -92,6 +91,25 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
92
91
  super
93
92
  end
94
93
 
94
+ ##
95
+ # +special+ is an rdoc-schemed link that will be converted into a hyperlink.
96
+ # For the rdoc-ref scheme the cross-reference will be looked up and the
97
+ # given name will be used.
98
+ #
99
+ # All other contents are handled by
100
+ # {the superclass}[rdoc-ref:RDoc::Markup::ToHtml#handle_special_RDOCLINK]
101
+
102
+ def handle_special_RDOCLINK special
103
+ url = special.text
104
+
105
+ case url
106
+ when /\Ardoc-ref:/ then
107
+ cross_reference $'
108
+ else
109
+ super
110
+ end
111
+ end
112
+
95
113
  ##
96
114
  # Generates links for <tt>rdoc-ref:</tt> scheme URLs and allows
97
115
  # RDoc::Markup::ToHtml to handle other schemes.
@@ -106,13 +124,26 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
106
124
  # Creates an HTML link to +name+ with the given +text+.
107
125
 
108
126
  def link name, text
127
+ if name =~ /(.*[^#:])@/ then
128
+ name = $1
129
+ label = $'
130
+ end
131
+
109
132
  ref = @cross_reference.resolve name, text
110
133
 
111
134
  case ref
112
135
  when String then
113
136
  ref
114
137
  else
115
- "<a href=\"#{ref.as_href @from_path}\">#{text}</a>"
138
+ path = ref.as_href @from_path
139
+
140
+ if path =~ /#/ then
141
+ path << "-label-#{label}"
142
+ else
143
+ path << "#label-#{label}"
144
+ end if label
145
+
146
+ "<a href=\"#{path}\">#{text}</a>"
116
147
  end
117
148
  end
118
149
 
@@ -0,0 +1,270 @@
1
+ ##
2
+ # Outputs RDoc markup as paragraphs with inline markup only.
3
+
4
+ class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
5
+
6
+ ##
7
+ # After this many characters the input will be cut off.
8
+
9
+ attr_reader :character_limit
10
+
11
+ ##
12
+ # The number of characters seen so far.
13
+
14
+ attr_reader :characters # :nodoc:
15
+
16
+ ##
17
+ # The attribute bitmask
18
+
19
+ attr_reader :mask
20
+
21
+ ##
22
+ # After this many paragraphs the input will be cut off.
23
+
24
+ attr_reader :paragraph_limit
25
+
26
+ ##
27
+ # Count of paragraphs found
28
+
29
+ attr_reader :paragraphs
30
+
31
+ ##
32
+ # Creates a new ToHtmlSnippet formatter that will cut off the input on the
33
+ # next word boundary after the given number of +characters+ or +paragraphs+
34
+ # of text have been encountered.
35
+
36
+ def initialize characters = 100, paragraphs = 3, markup = nil
37
+ super markup
38
+
39
+ @character_limit = characters
40
+ @paragraph_limit = paragraphs
41
+
42
+ @characters = 0
43
+ @mask = 0
44
+ @paragraphs = 0
45
+
46
+ @markup.add_special RDoc::CrossReference::CROSSREF_REGEXP, :CROSSREF
47
+ end
48
+
49
+ ##
50
+ # Adds +heading+ to the output as a paragraph
51
+
52
+ def accept_heading heading
53
+ @res << "<p>#{to_html heading.text}\n"
54
+
55
+ add_paragraph
56
+ end
57
+
58
+ ##
59
+ # Raw content is untrusted and ignored.
60
+
61
+ def accept_raw raw
62
+ end
63
+
64
+ ##
65
+ # Rules are ignored
66
+
67
+ def accept_rule rule
68
+ end
69
+
70
+ def accept_paragraph paragraph
71
+ para = @in_list_entry.last || "<p>"
72
+
73
+ @res << "#{para}#{wrap to_html paragraph.text}\n"
74
+
75
+ add_paragraph
76
+ end
77
+
78
+ ##
79
+ # Finishes consumption of +list_item+
80
+
81
+ def accept_list_item_end list_item
82
+ end
83
+
84
+ ##
85
+ # Prepares the visitor for consuming +list_item+
86
+
87
+ def accept_list_item_start list_item
88
+ @res << list_item_start(list_item, @list.last)
89
+ end
90
+
91
+ ##
92
+ # Prepares the visitor for consuming +list+
93
+
94
+ def accept_list_start list
95
+ @list << list.type
96
+ @res << html_list_name(list.type, true)
97
+ @in_list_entry.push ''
98
+ end
99
+
100
+ ##
101
+ # Adds +verbatim+ to the output
102
+
103
+ def accept_verbatim verbatim
104
+ throw :done if @characters >= @character_limit
105
+ input = verbatim.text.rstrip
106
+
107
+ text = truncate input
108
+ text << ' ...' unless text == input
109
+
110
+ super RDoc::Markup::Verbatim.new text
111
+
112
+ add_paragraph
113
+ end
114
+
115
+ ##
116
+ # Prepares the visitor for HTML snippet generation
117
+
118
+ def start_accepting
119
+ super
120
+
121
+ @characters = 0
122
+ end
123
+
124
+ ##
125
+ # Removes escaping from the cross-references in +special+
126
+
127
+ def handle_special_CROSSREF special
128
+ special.text.sub(/\A\\/, '')
129
+ end
130
+
131
+ ##
132
+ # Lists are paragraphs, but notes and labels have a separator
133
+
134
+ def list_item_start list_item, list_type
135
+ throw :done if @characters >= @character_limit
136
+
137
+ case list_type
138
+ when :BULLET, :LALPHA, :NUMBER, :UALPHA then
139
+ "<p>"
140
+ when :LABEL, :NOTE then
141
+ start = "<p>#{to_html list_item.label} &mdash; "
142
+ @characters += 1 # try to include the label
143
+ start
144
+ else
145
+ raise RDoc::Error, "Invalid list type: #{list_type.inspect}"
146
+ end
147
+ end
148
+
149
+ ##
150
+ # Returns just the text of +link+, +url+ is only used to determine the link
151
+ # type.
152
+
153
+ def gen_url url, text
154
+ if url =~ /^rdoc-label:([^:]*)(?::(.*))?/ then
155
+ type = "link"
156
+ elsif url =~ /([A-Za-z]+):(.*)/ then
157
+ type = $1
158
+ else
159
+ type = "http"
160
+ end
161
+
162
+ if (type == "http" or type == "https" or type == "link") and
163
+ url =~ /\.(gif|png|jpg|jpeg|bmp)$/ then
164
+ ''
165
+ else
166
+ text.sub(%r%^#{type}:/*%, '')
167
+ end
168
+ end
169
+
170
+ ##
171
+ # In snippets, there are no lists
172
+
173
+ def html_list_name list_type, open_tag
174
+ ''
175
+ end
176
+
177
+ ##
178
+ # Throws +:done+ when paragraph_limit paragraphs have been encountered
179
+
180
+ def add_paragraph
181
+ @paragraphs += 1
182
+
183
+ throw :done if @paragraphs >= @paragraph_limit
184
+ end
185
+
186
+ ##
187
+ # Marks up +content+
188
+
189
+ def convert content
190
+ catch :done do
191
+ return super
192
+ end
193
+
194
+ end_accepting
195
+ end
196
+
197
+ ##
198
+ # Converts flow items +flow+
199
+
200
+ def convert_flow flow
201
+ throw :done if @characters >= @character_limit
202
+
203
+ res = []
204
+ @mask = 0
205
+
206
+ flow.each do |item|
207
+ case item
208
+ when RDoc::Markup::AttrChanger then
209
+ off_tags res, item
210
+ on_tags res, item
211
+ when String then
212
+ text = convert_string item
213
+ res << truncate(text)
214
+ when RDoc::Markup::Special then
215
+ text = convert_special item
216
+ res << truncate(text)
217
+ else
218
+ raise "Unknown flow element: #{item.inspect}"
219
+ end
220
+
221
+ if @characters >= @character_limit then
222
+ off_tags res, RDoc::Markup::AttrChanger.new(0, @mask)
223
+ break
224
+ end
225
+ end
226
+
227
+ res << ' ...' if @characters >= @character_limit
228
+
229
+ res.join
230
+ end
231
+
232
+ ##
233
+ # Maintains a bitmask to allow HTML elements to be closed properly. See
234
+ # RDoc::Markup::Formatter.
235
+
236
+ def on_tags res, item
237
+ @mask ^= item.turn_on
238
+
239
+ super
240
+ end
241
+
242
+ ##
243
+ # Maintains a bitmask to allow HTML elements to be closed properly. See
244
+ # RDoc::Markup::Formatter.
245
+
246
+ def off_tags res, item
247
+ @mask ^= item.turn_off
248
+
249
+ super
250
+ end
251
+
252
+ ##
253
+ # Truncates +text+ at the end of the first word after the character_limit.
254
+
255
+ def truncate text
256
+ length = text.length
257
+ characters = @characters
258
+ @characters += length
259
+
260
+ return text if @characters < @character_limit
261
+
262
+ remaining = @character_limit - characters
263
+
264
+ text =~ /\A(.{#{remaining},}?)(\s|$)/m # TODO word-break instead of \s?
265
+
266
+ $1
267
+ end
268
+
269
+ end
270
+
@@ -0,0 +1,55 @@
1
+ require 'cgi'
2
+
3
+ ##
4
+ # Creates HTML-safe labels suitable for use in id attributes. Tidylinks are
5
+ # converted to their link part and cross-reference links have the suppression
6
+ # marks removed (\\SomeClass is converted to SomeClass).
7
+
8
+ class RDoc::Markup::ToLabel < RDoc::Markup::Formatter
9
+
10
+ ##
11
+ # Creates a new formatter that will output HTML-safe labels
12
+
13
+ def initialize markup = nil
14
+ super
15
+
16
+ @markup.add_special RDoc::CrossReference::CROSSREF_REGEXP, :CROSSREF
17
+ @markup.add_special(/(((\{.*?\})|\b\S+?)\[\S+?\])/, :TIDYLINK)
18
+
19
+ add_tag :BOLD, '', ''
20
+ add_tag :TT, '', ''
21
+ add_tag :EM, '', ''
22
+ end
23
+
24
+ ##
25
+ # Converts +text+ to an HTML-safe label
26
+
27
+ def convert text
28
+ label = convert_flow @am.flow text
29
+
30
+ CGI.escape label
31
+ end
32
+
33
+ ##
34
+ # Converts the CROSSREF +special+ to plain text, removing the suppression
35
+ # marker, if any
36
+
37
+ def handle_special_CROSSREF special
38
+ text = special.text
39
+
40
+ text.sub(/^\\/, '')
41
+ end
42
+
43
+ ##
44
+ # Converts the TIDYLINK +special+ to just the text part
45
+
46
+ def handle_special_TIDYLINK special
47
+ text = special.text
48
+
49
+ return text unless text =~ /\{(.*?)\}\[(.*?)\]/ or text =~ /(\S+)\[(.*?)\]/
50
+
51
+ $1
52
+ end
53
+
54
+ end
55
+
@@ -1,6 +1,3 @@
1
- require 'rdoc/markup/formatter'
2
- require 'rdoc/markup/inline'
3
-
4
1
  ##
5
2
  # Outputs RDoc markup as RDoc markup! (mostly)
6
3
 
@@ -0,0 +1,62 @@
1
+ ##
2
+ # Extracts just the RDoc::Markup::Heading elements from a
3
+ # RDoc::Markup::Document to help build a table of contents
4
+
5
+ class RDoc::Markup::ToTableOfContents < RDoc::Markup::Formatter
6
+
7
+ @to_toc = nil
8
+
9
+ ##
10
+ # Singleton for ToC generation
11
+
12
+ def self.to_toc
13
+ @to_toc ||= new
14
+ end
15
+
16
+ ##
17
+ # Output accumulator
18
+
19
+ attr_reader :res
20
+
21
+ ##
22
+ # Adds +heading+ to the table of contents
23
+
24
+ def accept_heading heading
25
+ @res << heading
26
+ end
27
+
28
+ ##
29
+ # Returns the table of contents
30
+
31
+ def end_accepting
32
+ @res
33
+ end
34
+
35
+ ##
36
+ # Prepares the visitor for text generation
37
+
38
+ def start_accepting
39
+ @res = []
40
+ end
41
+
42
+ ##
43
+ # Ignores the content of nodes that aren't headings
44
+
45
+ def ignore node
46
+ end
47
+
48
+ # :stopdoc:
49
+ alias accept_raw ignore
50
+ alias accept_rule ignore
51
+ alias accept_blank_line ignore
52
+ alias accept_paragraph ignore
53
+ alias accept_verbatim ignore
54
+ alias accept_list_end ignore
55
+ alias accept_list_item_start ignore
56
+ alias accept_list_item_end ignore
57
+ alias accept_list_end_bullet ignore
58
+ alias accept_list_start ignore
59
+ # :startdoc:
60
+
61
+ end
62
+