rdoc 2.5.11 → 3.0

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 (113) hide show
  1. data.tar.gz.sig +0 -0
  2. data/.document +1 -0
  3. data/History.txt +95 -0
  4. data/Manifest.txt +13 -4
  5. data/README.txt +9 -3
  6. data/Rakefile +1 -1
  7. data/lib/rdoc.rb +15 -298
  8. data/lib/rdoc/alias.rb +65 -16
  9. data/lib/rdoc/any_method.rb +27 -150
  10. data/lib/rdoc/attr.rb +36 -115
  11. data/lib/rdoc/class_module.rb +236 -22
  12. data/lib/rdoc/code_object.rb +76 -31
  13. data/lib/rdoc/constant.rb +32 -4
  14. data/lib/rdoc/context.rb +494 -222
  15. data/lib/rdoc/encoding.rb +79 -0
  16. data/lib/rdoc/erbio.rb +37 -0
  17. data/lib/rdoc/gauntlet.rb +9 -5
  18. data/lib/rdoc/generator.rb +33 -1
  19. data/lib/rdoc/generator/darkfish.rb +284 -375
  20. data/lib/rdoc/generator/markup.rb +72 -36
  21. data/lib/rdoc/generator/ri.rb +4 -4
  22. data/lib/rdoc/generator/template/darkfish/classpage.rhtml +267 -274
  23. data/lib/rdoc/generator/template/darkfish/filepage.rhtml +91 -91
  24. data/lib/rdoc/generator/template/darkfish/index.rhtml +45 -45
  25. data/lib/rdoc/generator/template/darkfish/rdoc.css +298 -298
  26. data/lib/rdoc/include.rb +40 -1
  27. data/lib/rdoc/known_classes.rb +1 -0
  28. data/lib/rdoc/markup.rb +467 -2
  29. data/lib/rdoc/markup/attribute_manager.rb +24 -6
  30. data/lib/rdoc/markup/blank_line.rb +11 -3
  31. data/lib/rdoc/markup/document.rb +6 -0
  32. data/lib/rdoc/markup/formatter.rb +10 -0
  33. data/lib/rdoc/markup/formatter_test_case.rb +339 -3
  34. data/lib/rdoc/markup/heading.rb +3 -0
  35. data/lib/rdoc/markup/inline.rb +11 -1
  36. data/lib/rdoc/markup/list.rb +3 -0
  37. data/lib/rdoc/markup/list_item.rb +3 -0
  38. data/lib/rdoc/markup/paragraph.rb +3 -0
  39. data/lib/rdoc/markup/parser.rb +191 -237
  40. data/lib/rdoc/markup/{preprocess.rb → pre_process.rb} +50 -29
  41. data/lib/rdoc/markup/raw.rb +4 -0
  42. data/lib/rdoc/markup/rule.rb +3 -0
  43. data/lib/rdoc/markup/text_formatter_test_case.rb +116 -0
  44. data/lib/rdoc/markup/to_ansi.rb +14 -2
  45. data/lib/rdoc/markup/to_bs.rb +8 -2
  46. data/lib/rdoc/markup/to_html.rb +84 -91
  47. data/lib/rdoc/markup/to_html_crossref.rb +77 -26
  48. data/lib/rdoc/markup/to_rdoc.rb +94 -49
  49. data/lib/rdoc/markup/to_test.rb +9 -1
  50. data/lib/rdoc/markup/verbatim.rb +6 -3
  51. data/lib/rdoc/method_attr.rb +353 -0
  52. data/lib/rdoc/normal_class.rb +11 -2
  53. data/lib/rdoc/normal_module.rb +0 -5
  54. data/lib/rdoc/options.rb +373 -82
  55. data/lib/rdoc/parser.rb +59 -23
  56. data/lib/rdoc/parser/c.rb +224 -86
  57. data/lib/rdoc/parser/ruby.rb +219 -111
  58. data/lib/rdoc/parser/ruby_tools.rb +4 -1
  59. data/lib/rdoc/parser/simple.rb +9 -4
  60. data/lib/rdoc/rdoc.rb +68 -28
  61. data/lib/rdoc/require.rb +21 -0
  62. data/lib/rdoc/ri/driver.rb +20 -10
  63. data/lib/rdoc/ri/paths.rb +2 -2
  64. data/lib/rdoc/ri/store.rb +22 -5
  65. data/lib/rdoc/ruby_lex.rb +11 -12
  66. data/lib/rdoc/ruby_token.rb +2 -2
  67. data/lib/rdoc/single_class.rb +2 -1
  68. data/lib/rdoc/stats.rb +202 -162
  69. data/lib/rdoc/stats/normal.rb +51 -0
  70. data/lib/rdoc/stats/quiet.rb +59 -0
  71. data/lib/rdoc/stats/verbose.rb +45 -0
  72. data/lib/rdoc/text.rb +133 -4
  73. data/lib/rdoc/{tokenstream.rb → token_stream.rb} +0 -2
  74. data/lib/rdoc/top_level.rb +230 -39
  75. data/test/test_attribute_manager.rb +58 -7
  76. data/test/test_rdoc_alias.rb +13 -0
  77. data/test/test_rdoc_any_method.rb +43 -2
  78. data/test/test_rdoc_attr.rb +15 -8
  79. data/test/test_rdoc_class_module.rb +133 -0
  80. data/test/test_rdoc_code_object.rb +62 -5
  81. data/test/test_rdoc_context.rb +72 -26
  82. data/test/test_rdoc_encoding.rb +145 -0
  83. data/test/test_rdoc_generator_darkfish.rb +119 -0
  84. data/test/test_rdoc_generator_ri.rb +22 -2
  85. data/test/test_rdoc_include.rb +79 -0
  86. data/test/test_rdoc_markup_attribute_manager.rb +4 -4
  87. data/test/test_rdoc_markup_parser.rb +134 -95
  88. data/test/test_rdoc_markup_pre_process.rb +7 -2
  89. data/test/test_rdoc_markup_to_ansi.rb +43 -153
  90. data/test/test_rdoc_markup_to_bs.rb +42 -156
  91. data/test/test_rdoc_markup_to_html.rb +130 -58
  92. data/test/test_rdoc_markup_to_html_crossref.rb +10 -10
  93. data/test/test_rdoc_markup_to_rdoc.rb +40 -151
  94. data/test/test_rdoc_method_attr.rb +122 -0
  95. data/test/test_rdoc_normal_class.rb +1 -1
  96. data/test/test_rdoc_normal_module.rb +6 -1
  97. data/test/test_rdoc_options.rb +237 -12
  98. data/test/test_rdoc_parser.rb +3 -22
  99. data/test/test_rdoc_parser_c.rb +203 -2
  100. data/test/test_rdoc_parser_ruby.rb +403 -89
  101. data/test/test_rdoc_parser_simple.rb +25 -1
  102. data/test/test_rdoc_rdoc.rb +44 -32
  103. data/test/test_rdoc_ri_driver.rb +29 -24
  104. data/test/test_rdoc_ri_store.rb +46 -3
  105. data/test/test_rdoc_task.rb +1 -1
  106. data/test/test_rdoc_text.rb +102 -8
  107. data/test/test_rdoc_top_level.rb +13 -4
  108. data/test/xref_data.rb +8 -0
  109. data/test/xref_test_case.rb +6 -0
  110. metadata +29 -19
  111. metadata.gz.sig +0 -0
  112. data/lib/rdoc/parser/perl.rb +0 -165
  113. data/test/test_rdoc_parser_perl.rb +0 -73
@@ -1,12 +1,15 @@
1
1
  require 'rdoc/markup'
2
+ require 'rdoc/encoding'
2
3
 
3
4
  ##
4
5
  # Handle common directives that can occur in a block of text:
5
6
  #
6
- # : include : filename
7
+ # \:include: filename
7
8
  #
8
- # RDoc plugin authors can register additional directives to be handled through
9
- # RDoc::Markup::PreProcess::register
9
+ # Directives can be escaped by preceding them with a backslash.
10
+ #
11
+ # RDoc plugin authors can register additional directives to be handled by
12
+ # using RDoc::Markup::PreProcess::register
10
13
 
11
14
  class RDoc::Markup::PreProcess
12
15
 
@@ -52,18 +55,25 @@ class RDoc::Markup::PreProcess
52
55
  # +code_object+. See RDoc::CodeObject#metadata
53
56
 
54
57
  def handle text, code_object = nil
55
- text.gsub!(/^([ \t]*#?[ \t]*):(\w+):([ \t]*)(.+)?\n/) do
56
- next $& if $3.empty? and $4 and $4[0, 1] == ':'
58
+ # regexp helper (square brackets for optional)
59
+ # $1 $2 $3 $4 $5
60
+ # [prefix][\]:directive:[spaces][param]newline
61
+ text.gsub!(/^([ \t]*#?[ \t]*)(\\?):(\w+):([ \t]*)(.+)?\n/) do
62
+ # skip something like ':toto::'
63
+ next $& if $4.empty? and $5 and $5[0, 1] == ':'
64
+
65
+ # skip if escaped
66
+ next "#$1:#$3:#$4#$5\n" unless $2.empty?
57
67
 
58
68
  prefix = $1
59
- directive = $2.downcase
60
- param = $4
69
+ directive = $3.downcase
70
+ param = $5
61
71
 
62
72
  case directive
63
73
  when 'include' then
64
74
  filename = param.split[0]
65
- include_file filename, prefix
66
-
75
+ encoding = if defined?(Encoding) then text.encoding else nil end
76
+ include_file filename, prefix, encoding
67
77
  else
68
78
  result = yield directive, param if block_given?
69
79
 
@@ -88,27 +98,38 @@ class RDoc::Markup::PreProcess
88
98
  end
89
99
 
90
100
  ##
91
- # Include a file, indenting it correctly.
92
-
93
- def include_file(name, indent)
94
- if full_name = find_include_file(name) then
95
- content = if defined?(Encoding) then
96
- File.binread full_name
97
- else
98
- File.read full_name
99
- end
100
- # HACK determine content type and force encoding
101
- content = content.sub(/\A# .*coding[=:].*$/, '').lstrip
102
-
103
- # strip leading '#'s, but only if all lines start with them
104
- if content =~ /^[^#]/ then
105
- content.gsub(/^/, indent)
106
- else
107
- content.gsub(/^#?/, indent)
108
- end
109
- else
101
+ # Handles the <tt>:include: _filename_</tt> directive.
102
+ #
103
+ # If the first line of the included file starts with '#', and contains
104
+ # an encoding information in the form 'coding:' or 'coding=', it is
105
+ # removed.
106
+ #
107
+ # If all lines in the included file start with a '#', this leading '#'
108
+ # is removed before inclusion. The included content is indented like
109
+ # the <tt>:include:</tt> directive.
110
+ #--
111
+ # so all content will be verbatim because of the likely space after '#'?
112
+ # TODO shift left the whole file content in that case
113
+ # TODO comment stop/start #-- and #++ in included file must be processed here
114
+
115
+ def include_file name, indent, encoding
116
+ full_name = find_include_file name
117
+
118
+ unless full_name then
110
119
  warn "Couldn't find file to include '#{name}' from #{@input_file_name}"
111
- ''
120
+ return ''
121
+ end
122
+
123
+ content = RDoc::Encoding.read_file full_name, encoding
124
+
125
+ # strip magic comment
126
+ content = content.sub(/\A# .*coding[=:].*$/, '').lstrip
127
+
128
+ # strip leading '#'s, but only if all lines start with them
129
+ if content =~ /^[^#]/ then
130
+ content.gsub(/^/, indent)
131
+ else
132
+ content.gsub(/^#?/, indent)
112
133
  end
113
134
  end
114
135
 
@@ -27,6 +27,9 @@ class RDoc::Markup::Raw
27
27
  self.class == other.class and text == other.text
28
28
  end
29
29
 
30
+ ##
31
+ # Calls #accept_raw+ on +visitor+
32
+
30
33
  def accept visitor
31
34
  visitor.accept_raw self
32
35
  end
@@ -63,3 +66,4 @@ class RDoc::Markup::Raw
63
66
  end
64
67
 
65
68
  end
69
+
@@ -3,6 +3,9 @@
3
3
 
4
4
  class RDoc::Markup::Rule < Struct.new :weight
5
5
 
6
+ ##
7
+ # Calls #accept_rule on +visitor+
8
+
6
9
  def accept visitor
7
10
  visitor.accept_rule self
8
11
  end
@@ -0,0 +1,116 @@
1
+ require 'rdoc/markup/formatter_test_case'
2
+
3
+ ##
4
+ # Test case for creating new plain-text RDoc::Markup formatters. See also
5
+ # RDoc::Markup::FormatterTestCase
6
+ #
7
+ # See test_rdoc_markup_to_rdoc.rb for a complete example.
8
+ #
9
+ # Example:
10
+ #
11
+ # class TestRDocMarkupToNewTextFormat < RDoc::Markup::TextFormatterTestCase
12
+ #
13
+ # add_visitor_tests
14
+ # add_text_tests
15
+ #
16
+ # def setup
17
+ # super
18
+ #
19
+ # @to = RDoc::Markup::ToNewTextFormat.new
20
+ # end
21
+ #
22
+ # def accept_blank_line
23
+ # assert_equal :junk, @to.res.join
24
+ # end
25
+ #
26
+ # # ...
27
+ #
28
+ # end
29
+
30
+ class RDoc::Markup::TextFormatterTestCase < RDoc::Markup::FormatterTestCase
31
+
32
+ ##
33
+ # Adds test cases to the calling TestCase.
34
+
35
+ def self.add_text_tests
36
+ self.class_eval do
37
+
38
+ ##
39
+ # Test case that calls <tt>@to.accept_heading</tt>
40
+
41
+ def test_accept_heading_indent
42
+ @to.start_accepting
43
+ @to.indent = 3
44
+ @to.accept_heading @RM::Heading.new(1, 'Hello')
45
+
46
+ accept_heading_indent
47
+ end
48
+
49
+ ##
50
+ # Test case that calls <tt>@to.accept_rule</tt>
51
+
52
+ def test_accept_rule_indent
53
+ @to.start_accepting
54
+ @to.indent = 3
55
+ @to.accept_rule @RM::Rule.new(1)
56
+
57
+ accept_rule_indent
58
+ end
59
+
60
+ ##
61
+ # Test case that calls <tt>@to.accept_verbatim</tt>
62
+
63
+ def test_accept_verbatim_indent
64
+ @to.start_accepting
65
+ @to.indent = 2
66
+ @to.accept_verbatim @RM::Verbatim.new("hi\n", " world\n")
67
+
68
+ accept_verbatim_indent
69
+ end
70
+
71
+ ##
72
+ # Test case that calls <tt>@to.accept_verbatim</tt> with a big indent
73
+
74
+ def test_accept_verbatim_big_indent
75
+ @to.start_accepting
76
+ @to.indent = 2
77
+ @to.accept_verbatim @RM::Verbatim.new("hi\n", "world\n")
78
+
79
+ accept_verbatim_big_indent
80
+ end
81
+
82
+ ##
83
+ # Test case that calls <tt>@to.accept_paragraph</tt> with an indent
84
+
85
+ def test_accept_paragraph_indent
86
+ @to.start_accepting
87
+ @to.indent = 3
88
+ @to.accept_paragraph @RM::Paragraph.new(('words ' * 30).strip)
89
+
90
+ accept_paragraph_indent
91
+ end
92
+
93
+ ##
94
+ # Test case that calls <tt>@to.accept_paragraph</tt> with a long line
95
+
96
+ def test_accept_paragraph_wrap
97
+ @to.start_accepting
98
+ @to.accept_paragraph @RM::Paragraph.new(('words ' * 30).strip)
99
+
100
+ accept_paragraph_wrap
101
+ end
102
+
103
+ ##
104
+ # Test case that calls <tt>@to.attributes</tt> with an escaped
105
+ # cross-reference. If this test doesn't pass something may be very
106
+ # wrong.
107
+
108
+ def test_attributes
109
+ assert_equal 'Dog', @to.attributes("\\Dog")
110
+ end
111
+
112
+ end
113
+ end
114
+
115
+ end
116
+
@@ -1,10 +1,13 @@
1
- require 'rdoc/markup/inline'
1
+ require 'rdoc/markup/to_rdoc'
2
2
 
3
3
  ##
4
4
  # Outputs RDoc markup with vibrant ANSI color!
5
5
 
6
6
  class RDoc::Markup::ToAnsi < RDoc::Markup::ToRdoc
7
7
 
8
+ ##
9
+ # Creates a new ToAnsi visitor that is ready to output vibrant ANSI color!
10
+
8
11
  def initialize
9
12
  super
10
13
 
@@ -23,12 +26,15 @@ class RDoc::Markup::ToAnsi < RDoc::Markup::ToRdoc
23
26
  add_tag :EM, "\e[4m", "\e[m"
24
27
  end
25
28
 
29
+ ##
30
+ # Overrides indent width to ensure output lines up correctly.
31
+
26
32
  def accept_list_item_end list_item
27
33
  width = case @list_type.last
28
34
  when :BULLET then
29
35
  2
30
36
  when :NOTE, :LABEL then
31
- @res << "\n"
37
+ @res << "\n" unless res.length == 1
32
38
  2
33
39
  else
34
40
  bullet = @list_index.last.to_s
@@ -39,6 +45,9 @@ class RDoc::Markup::ToAnsi < RDoc::Markup::ToRdoc
39
45
  @indent -= width
40
46
  end
41
47
 
48
+ ##
49
+ # Adds coloring to note and label list items
50
+
42
51
  def accept_list_item_start list_item
43
52
  bullet = case @list_type.last
44
53
  when :BULLET then
@@ -62,6 +71,9 @@ class RDoc::Markup::ToAnsi < RDoc::Markup::ToRdoc
62
71
  end
63
72
  end
64
73
 
74
+ ##
75
+ # Starts accepting with a reset screen
76
+
65
77
  def start_accepting
66
78
  super
67
79
 
@@ -1,4 +1,4 @@
1
- require 'rdoc/markup/inline'
1
+ require 'rdoc/markup/to_rdoc'
2
2
 
3
3
  ##
4
4
  # Outputs RDoc markup with hot backspace action! You will probably need a
@@ -8,6 +8,9 @@ require 'rdoc/markup/inline'
8
8
 
9
9
  class RDoc::Markup::ToBs < RDoc::Markup::ToRdoc
10
10
 
11
+ ##
12
+ # Returns a new ToBs that is ready for hot backspace action!
13
+
11
14
  def initialize
12
15
  super
13
16
 
@@ -22,8 +25,12 @@ class RDoc::Markup::ToBs < RDoc::Markup::ToRdoc
22
25
  def init_tags
23
26
  add_tag :BOLD, '+b', '-b'
24
27
  add_tag :EM, '+_', '-_'
28
+ add_tag :TT, '' , '' # we need in_tt information maintained
25
29
  end
26
30
 
31
+ ##
32
+ # Makes heading text bold.
33
+
27
34
  def accept_heading heading
28
35
  use_prefix or @res << ' ' * @indent
29
36
  @res << @headings[heading.level][0]
@@ -44,7 +51,6 @@ class RDoc::Markup::ToBs < RDoc::Markup::ToRdoc
44
51
  when '+_' then @in_em = true
45
52
  when '-_' then @in_em = false
46
53
  end
47
-
48
54
  ''
49
55
  end
50
56
 
@@ -8,6 +8,8 @@ require 'cgi'
8
8
 
9
9
  class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
10
10
 
11
+ include RDoc::Text
12
+
11
13
  ##
12
14
  # Maps RDoc::Markup::Parser::LIST_TOKENS types to HTML tags
13
15
 
@@ -15,7 +17,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
15
17
  :BULLET => ['<ul>', '</ul>'],
16
18
  :LABEL => ['<dl>', '</dl>'],
17
19
  :LALPHA => ['<ol style="display: lower-alpha">', '</ol>'],
18
- :NOTE => ['<table>', '</table>'],
20
+ :NOTE => ['<table class="rdoc-list">', '</table>'],
19
21
  :NUMBER => ['<ol>', '</ol>'],
20
22
  :UALPHA => ['<ol style="display: upper-alpha">', '</ol>'],
21
23
  }
@@ -48,6 +50,9 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
48
50
  File.join(*from)
49
51
  end
50
52
 
53
+ ##
54
+ # Creates a new formatter that will output HTML
55
+
51
56
  def initialize
52
57
  super
53
58
 
@@ -103,13 +108,15 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
103
108
  end
104
109
  end
105
110
 
111
+ # :section: Special handling
112
+
106
113
  ##
107
- # And we're invoked with a potential external hyperlink mailto:
108
- # just gets inserted. http: links are checked to see if they
114
+ # And we're invoked with a potential external hyperlink. <tt>mailto:</tt>
115
+ # just gets inserted. <tt>http:</tt> links are checked to see if they
109
116
  # reference an image. If so, that image gets inserted using an
110
- # <img> tag. Otherwise a conventional <a href> is used. We also
111
- # support a special type of hyperlink, link:, which is a reference
112
- # to a local file whose path is relative to the --op directory.
117
+ # <tt><img></tt> tag. Otherwise a conventional <tt><a href></tt> is used.
118
+ # We also support a special type of hyperlink, <tt>link:</tt>, which is a
119
+ # reference to a local file whose path is relative to the --op directory.
113
120
 
114
121
  def handle_special_HYPERLINK(special)
115
122
  url = special.text
@@ -118,7 +125,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
118
125
 
119
126
  ##
120
127
  # Here's a hypedlink where the label is different to the URL
121
- # <label>[url] or {long label}[url]
128
+ # <label>[url] or {long label}[url]
122
129
 
123
130
  def handle_special_TIDYLINK(special)
124
131
  text = special.text
@@ -130,8 +137,10 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
130
137
  gen_url url, label
131
138
  end
132
139
 
140
+ # :section: Utilities
141
+
133
142
  ##
134
- # This is a higher speed (if messier) version of wrap
143
+ # Wraps +txt+ to +line_len+
135
144
 
136
145
  def wrap(txt, line_len = 76)
137
146
  res = []
@@ -159,173 +168,150 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
159
168
  sp += 1 while sp < ep and txt[sp] == ?\s
160
169
  end
161
170
 
162
- res.join
171
+ res.join.strip
163
172
  end
164
173
 
165
- ##
166
174
  # :section: Visitor
167
175
 
176
+ ##
177
+ # Prepares the visitor for HTML generation
178
+
168
179
  def start_accepting
169
180
  @res = []
170
181
  @in_list_entry = []
171
182
  @list = []
172
183
  end
173
184
 
185
+ ##
186
+ # Returns the generated output
187
+
174
188
  def end_accepting
175
189
  @res.join
176
190
  end
177
191
 
192
+ ##
193
+ # Adds +paragraph+ to the output
194
+
178
195
  def accept_paragraph(paragraph)
179
- @res << annotate("<p>") + "\n"
180
- @res << wrap(convert_flow(@am.flow(paragraph.text)))
181
- @res << annotate("</p>") + "\n"
196
+ @res << "\n<p>"
197
+ @res << wrap(to_html(paragraph.text))
198
+ @res << "</p>\n"
182
199
  end
183
200
 
201
+ ##
202
+ # Adds +verbatim+ to the output
203
+
184
204
  def accept_verbatim(verbatim)
185
- @res << annotate("<pre>") << "\n"
186
- @res << CGI.escapeHTML(verbatim.text)
187
- @res << annotate("</pre>") << "\n"
205
+ @res << "\n<pre>"
206
+ @res << CGI.escapeHTML(verbatim.text.rstrip)
207
+ @res << "</pre>\n"
188
208
  end
189
209
 
210
+ ##
211
+ # Adds +rule+ to the output
212
+
190
213
  def accept_rule(rule)
191
214
  size = rule.weight
192
215
  size = 10 if size > 10
193
- @res << "<hr style=\"height: #{size}px\"></hr>"
216
+ @res << "<hr style=\"height: #{size}px\">\n"
194
217
  end
195
218
 
219
+ ##
220
+ # Prepares the visitor for consuming +list+
221
+
196
222
  def accept_list_start(list)
197
223
  @list << list.type
198
- @res << html_list_name(list.type, true) << "\n"
224
+ @res << html_list_name(list.type, true)
199
225
  @in_list_entry.push false
200
226
  end
201
227
 
228
+ ##
229
+ # Finishes consumption of +list+
230
+
202
231
  def accept_list_end(list)
203
232
  @list.pop
204
233
  if tag = @in_list_entry.pop
205
- @res << annotate(tag) << "\n"
234
+ @res << tag
206
235
  end
207
236
  @res << html_list_name(list.type, false) << "\n"
208
237
  end
209
238
 
239
+ ##
240
+ # Prepares the visitor for consuming +list_item+
241
+
210
242
  def accept_list_item_start(list_item)
211
243
  if tag = @in_list_entry.last
212
- @res << annotate(tag) << "\n"
244
+ @res << tag
213
245
  end
214
246
 
215
247
  @res << list_item_start(list_item, @list.last)
216
248
  end
217
249
 
250
+ ##
251
+ # Finishes consumption of +list_item+
252
+
218
253
  def accept_list_item_end(list_item)
219
254
  @in_list_entry[-1] = list_end_for(@list.last)
220
255
  end
221
256
 
222
- def accept_blank_line(blank_line)
223
- # @res << annotate("<p />") << "\n"
224
- end
225
-
226
- def accept_heading(heading)
227
- @res << convert_heading(heading.level, @am.flow(heading.text))
228
- end
229
-
230
- def accept_raw raw
231
- @res << raw.parts.join("\n")
232
- end
233
-
234
- private
235
-
236
257
  ##
237
- # Converts string +item+
258
+ # Adds +blank_line+ to the output
238
259
 
239
- def convert_string(item)
240
- in_tt? ? convert_string_simple(item) : convert_string_fancy(item)
260
+ def accept_blank_line(blank_line)
261
+ # @res << annotate("<p />") << "\n"
241
262
  end
242
263
 
243
264
  ##
244
- # Escapes HTML in +item+
265
+ # Adds +heading+ to the output
245
266
 
246
- def convert_string_simple(item)
247
- CGI.escapeHTML item
267
+ def accept_heading(heading)
268
+ @res << "\n<h#{heading.level}>"
269
+ @res << to_html(heading.text)
270
+ @res << "</h#{heading.level}>\n"
248
271
  end
249
272
 
250
273
  ##
251
- # Converts ampersand, dashes, elipsis, quotes, copyright and registered
252
- # trademark symbols to HTML escaped Unicode.
253
-
254
- def convert_string_fancy(item)
255
- # convert ampersand before doing anything else
256
- item.gsub(/&/, '&amp;').
257
-
258
- # convert -- to em-dash, (-- to en-dash)
259
- gsub(/---?/, '&#8212;'). #gsub(/--/, '&#8211;').
260
-
261
- # convert ... to elipsis (and make sure .... becomes .<elipsis>)
262
- gsub(/\.\.\.\./, '.&#8230;').gsub(/\.\.\./, '&#8230;').
274
+ # Adds +raw+ to the output
263
275
 
264
- # convert single closing quote
265
- gsub(%r{([^ \t\r\n\[\{\(])\'}, '\1&#8217;'). # }
266
- gsub(%r{\'(?=\W|s\b)}, '&#8217;').
267
-
268
- # convert single opening quote
269
- gsub(/'/, '&#8216;').
270
-
271
- # convert double closing quote
272
- gsub(%r{([^ \t\r\n\[\{\(])\"(?=\W)}, '\1&#8221;'). # }
273
-
274
- # convert double opening quote
275
- gsub(/"/, '&#8220;').
276
-
277
- # convert copyright
278
- gsub(/\(c\)/, '&#169;').
279
-
280
- # convert registered trademark
281
- gsub(/\(r\)/, '&#174;')
276
+ def accept_raw raw
277
+ @res << raw.parts.join("\n")
282
278
  end
283
279
 
284
280
  ##
285
- # Converts headings to hN elements
281
+ # CGI escapes +text+
286
282
 
287
- def convert_heading(level, flow)
288
- [annotate("<h#{level}>"),
289
- convert_flow(flow),
290
- annotate("</h#{level}>\n")].join
283
+ def convert_string(text)
284
+ CGI.escapeHTML text
291
285
  end
292
286
 
293
287
  ##
294
- # Determins the HTML list element for +list_type+ and +open_tag+
288
+ # Determines the HTML list element for +list_type+ and +open_tag+
295
289
 
296
290
  def html_list_name(list_type, open_tag)
297
291
  tags = LIST_TYPE_TO_HTML[list_type]
298
292
  raise RDoc::Error, "Invalid list type: #{list_type.inspect}" unless tags
299
- annotate tags[open_tag ? 0 : 1]
293
+ tags[open_tag ? 0 : 1]
300
294
  end
301
295
 
302
296
  ##
303
- # Starts a list item
297
+ # Returns the HTML tag for +list_type+, possible using a label from
298
+ # +list_item+
304
299
 
305
300
  def list_item_start(list_item, list_type)
306
301
  case list_type
307
302
  when :BULLET, :LALPHA, :NUMBER, :UALPHA then
308
- annotate("<li>")
309
-
303
+ "<li>"
310
304
  when :LABEL then
311
- annotate("<dt>") +
312
- convert_flow(@am.flow(list_item.label)) +
313
- annotate("</dt>") +
314
- annotate("<dd>")
315
-
305
+ "<dt>#{to_html list_item.label}</dt>\n<dd>"
316
306
  when :NOTE then
317
- annotate("<tr>") +
318
- annotate("<td valign=\"top\">") +
319
- convert_flow(@am.flow(list_item.label)) +
320
- annotate("</td>") +
321
- annotate("<td>")
307
+ "<tr><td class=\"rdoc-term\"><p>#{to_html list_item.label}</p></td>\n<td>"
322
308
  else
323
309
  raise RDoc::Error, "Invalid list type: #{list_type.inspect}"
324
310
  end
325
311
  end
326
312
 
327
313
  ##
328
- # Ends a list item
314
+ # Returns the HTML end-tag for +list_type+
329
315
 
330
316
  def list_end_for(list_type)
331
317
  case list_type
@@ -340,5 +326,12 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
340
326
  end
341
327
  end
342
328
 
329
+ ##
330
+ # Converts +item+ to HTML using RDoc::Text#to_html
331
+
332
+ def to_html item
333
+ super convert_flow @am.flow item
334
+ end
335
+
343
336
  end
344
337