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,5 +1,4 @@
1
1
  require 'strscan'
2
- require 'rdoc/text'
3
2
 
4
3
  ##
5
4
  # A recursive-descent parser for RDoc markup.
@@ -52,7 +51,9 @@ class RDoc::Markup::Parser
52
51
  attr_reader :tokens
53
52
 
54
53
  ##
55
- # Parses +str+ into a Document
54
+ # Parses +str+ into a Document.
55
+ #
56
+ # Use RDoc::Markup#parse instead of this method.
56
57
 
57
58
  def self.parse str
58
59
  parser = new
@@ -426,7 +427,7 @@ class RDoc::Markup::Parser
426
427
  [:TEXT, s.matched.sub(/\r$/, ''), *token_pos(pos)]
427
428
  end
428
429
  # --- (at least 3) and nothing else on the line => :RULE
429
- when s.scan(/(-{3,}) *$/) then
430
+ when s.scan(/(-{3,}) *\r?$/) then
430
431
  [:RULE, s[1].length - 2, *token_pos(pos)]
431
432
  # * or - followed by white space and text => :BULLET
432
433
  when s.scan(/([*-]) +(\S)/) then
@@ -451,10 +452,10 @@ class RDoc::Markup::Parser
451
452
  end
452
453
  [list_type, list_label, *token_pos(pos)]
453
454
  # [text] followed by spaces or end of line => :LABEL
454
- when s.scan(/\[(.*?)\]( +|$)/) then
455
+ when s.scan(/\[(.*?)\]( +|\r?$)/) then
455
456
  [:LABEL, s[1], *token_pos(pos)]
456
457
  # text:: followed by spaces or end of line => :NOTE
457
- when s.scan(/(.*?)::( +|$)/) then
458
+ when s.scan(/(.*?)::( +|\r?$)/) then
458
459
  [:NOTE, s[1], *token_pos(pos)]
459
460
  # anything else: :TEXT
460
461
  else s.scan(/.*/)
@@ -484,14 +485,3 @@ class RDoc::Markup::Parser
484
485
 
485
486
  end
486
487
 
487
- require 'rdoc/markup/blank_line'
488
- require 'rdoc/markup/document'
489
- require 'rdoc/markup/heading'
490
- require 'rdoc/markup/list'
491
- require 'rdoc/markup/list_item'
492
- require 'rdoc/markup/raw'
493
- require 'rdoc/markup/paragraph'
494
- require 'rdoc/markup/indented_paragraph'
495
- require 'rdoc/markup/rule'
496
- require 'rdoc/markup/verbatim'
497
-
@@ -1,6 +1,3 @@
1
- require 'rdoc/markup'
2
- require 'rdoc/encoding'
3
-
4
1
  ##
5
2
  # Handle common directives that can occur in a block of text:
6
3
  #
@@ -13,9 +10,27 @@ require 'rdoc/encoding'
13
10
 
14
11
  class RDoc::Markup::PreProcess
15
12
 
13
+ ##
14
+ # An RDoc::Options instance that will be filled in with overrides from
15
+ # directives
16
+
16
17
  attr_accessor :options
17
18
 
18
- @registered = {}
19
+ ##
20
+ # Adds a post-process handler for directives. The handler will be called
21
+ # with the result RDoc::Comment (or text String) and the code object for the
22
+ # comment (if any).
23
+
24
+ def self.post_process &block
25
+ @post_processors << block
26
+ end
27
+
28
+ ##
29
+ # Registered post-processors
30
+
31
+ def self.post_processors
32
+ @post_processors
33
+ end
19
34
 
20
35
  ##
21
36
  # Registers +directive+ as one handled by RDoc. If a block is given the
@@ -33,6 +48,16 @@ class RDoc::Markup::PreProcess
33
48
  @registered
34
49
  end
35
50
 
51
+ ##
52
+ # Clears all registered directives and post-processors
53
+
54
+ def self.reset
55
+ @post_processors = []
56
+ @registered = {}
57
+ end
58
+
59
+ reset
60
+
36
61
  ##
37
62
  # Creates a new pre-processor for +input_file_name+ that will look for
38
63
  # included files in +include_path+
@@ -44,7 +69,7 @@ class RDoc::Markup::PreProcess
44
69
  end
45
70
 
46
71
  ##
47
- # Look for directives in a chunk of +text+.
72
+ # Look for directives in the given +text+.
48
73
  #
49
74
  # Options that we don't handle are yielded. If the block returns false the
50
75
  # directive is restored to the text. If the block returns nil or no block
@@ -54,27 +79,56 @@ class RDoc::Markup::PreProcess
54
79
  # If no matching directive was registered the directive is restored to the
55
80
  # text.
56
81
  #
57
- # If +code_object+ is given and the param is set as metadata on the
58
- # +code_object+. See RDoc::CodeObject#metadata
82
+ # If +code_object+ is given and the directive is unknown then the
83
+ # directive's parameter is set as metadata on the +code_object+. See
84
+ # RDoc::CodeObject#metadata for details.
59
85
 
60
86
  def handle text, code_object = nil, &block
61
- encoding = if defined?(Encoding) then text.encoding else nil end
87
+ if RDoc::Comment === text then
88
+ comment = text
89
+ text = text.text
90
+ end
91
+
92
+ encoding = text.encoding if defined?(Encoding)
93
+
62
94
  # regexp helper (square brackets for optional)
63
95
  # $1 $2 $3 $4 $5
64
96
  # [prefix][\]:directive:[spaces][param]newline
65
- text.gsub!(/^([ \t]*(?:#|\/?\*)?[ \t]*)(\\?):(\w+):([ \t]*)(.+)?\n/) do
97
+ text.gsub!(/^([ \t]*(?:#|\/?\*)?[ \t]*)(\\?):(\w+):([ \t]*)(.+)?(\r?\n|$)/) do
66
98
  # skip something like ':toto::'
67
99
  next $& if $4.empty? and $5 and $5[0, 1] == ':'
68
100
 
69
101
  # skip if escaped
70
102
  next "#$1:#$3:#$4#$5\n" unless $2.empty?
71
103
 
104
+ # This is not in handle_directive because I didn't want to pass another
105
+ # argument into it
106
+ if comment and $3 == 'markup' then
107
+ next "#{$1.strip}\n" unless $5
108
+ comment.format = $5.downcase
109
+ next "#{$1.strip}\n"
110
+ end
111
+
72
112
  handle_directive $1, $3, $5, code_object, encoding, &block
73
113
  end
74
114
 
115
+ comment = text unless comment
116
+
117
+ self.class.post_processors.each do |handler|
118
+ handler.call comment, code_object
119
+ end
120
+
75
121
  text
76
122
  end
77
123
 
124
+ ##
125
+ # Performs the actions described by +directive+ and its parameter +param+.
126
+ #
127
+ # +code_object+ is used for directives that operate on a class or module.
128
+ # +prefix+ is used to ensure the replacement for handled directives is
129
+ # correct. +encoding+ is used for the <tt>include</tt> directive.
130
+ #
131
+ # For a list of directives in RDoc see RDoc::Markup.
78
132
  #--
79
133
  # When 1.8.7 support is ditched prefix can be defaulted to ''
80
134
 
@@ -92,7 +146,7 @@ class RDoc::Markup::PreProcess
92
146
  blankline
93
147
  when 'category' then
94
148
  if RDoc::Context === code_object then
95
- section = code_object.add_section param, ''
149
+ section = code_object.add_section param
96
150
  code_object.temporary_section = section
97
151
  end
98
152
 
@@ -24,7 +24,7 @@ class RDoc::Markup::Raw
24
24
  end
25
25
 
26
26
  def == other # :nodoc:
27
- self.class == other.class and text == other.text
27
+ self.class == other.class and @parts == other.parts
28
28
  end
29
29
 
30
30
  ##
@@ -0,0 +1,40 @@
1
+ ##
2
+ # Hold details of a special sequence
3
+
4
+ class RDoc::Markup::Special
5
+
6
+ ##
7
+ # Special type
8
+
9
+ attr_reader :type
10
+
11
+ ##
12
+ # Special text
13
+
14
+ attr_accessor :text
15
+
16
+ ##
17
+ # Creates a new special sequence of +type+ with +text+
18
+
19
+ def initialize(type, text)
20
+ @type, @text = type, text
21
+ end
22
+
23
+ ##
24
+ # Specials are equal when the have the same text and type
25
+
26
+ def ==(o)
27
+ self.text == o.text && self.type == o.type
28
+ end
29
+
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]
33
+ end
34
+
35
+ def to_s # :nodoc:
36
+ "Special: type=#{type}, name=#{RDoc::Markup::Attribute.as_string type}, text=#{text.dump}"
37
+ end
38
+
39
+ end
40
+
@@ -1,5 +1,3 @@
1
- require 'rdoc/markup/formatter_test_case'
2
-
3
1
  ##
4
2
  # Test case for creating new plain-text RDoc::Markup formatters. See also
5
3
  # RDoc::Markup::FormatterTestCase
@@ -1,5 +1,3 @@
1
- require 'rdoc/markup/to_rdoc'
2
-
3
1
  ##
4
2
  # Outputs RDoc markup with vibrant ANSI color!
5
3
 
@@ -1,5 +1,3 @@
1
- require 'rdoc/markup/to_rdoc'
2
-
3
1
  ##
4
2
  # Outputs RDoc markup with hot backspace action! You will probably need a
5
3
  # pager to use this output format.
@@ -1,10 +1,7 @@
1
- require 'rdoc/markup/formatter'
2
- require 'rdoc/markup/inline'
3
-
4
1
  require 'cgi'
5
2
 
6
3
  ##
7
- # Outputs RDoc markup as HTML
4
+ # Outputs RDoc markup as HTML.
8
5
 
9
6
  class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
10
7
 
@@ -16,18 +13,24 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
16
13
  # Maps RDoc::Markup::Parser::LIST_TOKENS types to HTML tags
17
14
 
18
15
  LIST_TYPE_TO_HTML = {
19
- :BULLET => ['<ul>', '</ul>'],
20
- :LABEL => ['<dl class="rdoc-list">', '</dl>'],
21
- :LALPHA => ['<ol style="display: lower-alpha">', '</ol>'],
22
- :NOTE => ['<table class="rdoc-list">', '</table>'],
23
- :NUMBER => ['<ol>', '</ol>'],
24
- :UALPHA => ['<ol style="display: upper-alpha">', '</ol>'],
16
+ :BULLET => ['<ul>', '</ul>'],
17
+ :LABEL => ['<dl class="rdoc-list label-list">', '</dl>'],
18
+ :LALPHA => ['<ol style="list-style-type: lower-alpha">', '</ol>'],
19
+ :NOTE => ['<dl class="rdoc-list note-list">', '</dl>'],
20
+ :NUMBER => ['<ol>', '</ol>'],
21
+ :UALPHA => ['<ol style="list-style-type: upper-alpha">', '</ol>'],
25
22
  }
26
23
 
27
24
  attr_reader :res # :nodoc:
28
25
  attr_reader :in_list_entry # :nodoc:
29
26
  attr_reader :list # :nodoc:
30
27
 
28
+ ##
29
+ # The RDoc::CodeObject HTML is being generated for. This is used to
30
+ # generate namespaced URI fragments
31
+
32
+ attr_accessor :code_object
33
+
31
34
  ##
32
35
  # Path to this document for relative links
33
36
 
@@ -65,14 +68,18 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
65
68
  def initialize markup = nil
66
69
  super
67
70
 
68
- @th = nil
71
+ @code_object = nil
72
+ @from_path = ''
69
73
  @in_list_entry = nil
70
74
  @list = nil
71
- @from_path = ''
75
+ @th = nil
72
76
 
73
77
  # external links
74
78
  @markup.add_special(/((link:|https?:|mailto:|ftp:|www\.)\S+\w)/, :HYPERLINK)
75
79
 
80
+ # internal links
81
+ @markup.add_special(/rdoc-[a-z]+:\S+/, :RDOCLINK)
82
+
76
83
  # and links of the form <text>[<url>]
77
84
  @markup.add_special(/(((\{.*?\})|\b\S+?)\[\S+?\])/, :TIDYLINK)
78
85
 
@@ -101,6 +108,39 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
101
108
  gen_url url, url
102
109
  end
103
110
 
111
+ ##
112
+ # +special+ is an rdoc-schemed link that will be converted into a hyperlink.
113
+ #
114
+ # For the +rdoc-ref+ scheme the named reference will be returned without
115
+ # creating a link.
116
+ #
117
+ # For the +rdoc-label+ scheme the footnote and label prefixes are stripped
118
+ # when creating a link. All other contents will be linked verbatim.
119
+
120
+ def handle_special_RDOCLINK special
121
+ url = special.text
122
+
123
+ case url
124
+ when /\Ardoc-ref:/
125
+ $'
126
+ when /\Ardoc-label:/
127
+ text = $'
128
+
129
+ text = case text
130
+ when /\Alabel-/ then $'
131
+ when /\Afootmark-/ then "^#{$'}"
132
+ when /\Afoottext-/ then "*#{$'}"
133
+ else text
134
+ end
135
+
136
+ gen_url url, text
137
+ else
138
+ url =~ /\Ardoc-[a-z]+:/
139
+
140
+ $'
141
+ end
142
+ end
143
+
104
144
  ##
105
145
  # This +special+ is a link where the label is different from the URL
106
146
  # <tt>label[url]</tt> or <tt>{long label}[url]</tt>
@@ -147,10 +187,24 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
147
187
  ##
148
188
  # Adds +verbatim+ to the output
149
189
 
150
- def accept_verbatim(verbatim)
151
- @res << "\n<pre>"
152
- @res << CGI.escapeHTML(verbatim.text.rstrip)
153
- @res << "</pre>\n"
190
+ def accept_verbatim verbatim
191
+ text = verbatim.text.rstrip
192
+
193
+ @res << if verbatim.ruby? or parseable? text then
194
+ options = RDoc::RDoc.current.options if RDoc::RDoc.current
195
+
196
+ begin
197
+ tokens = RDoc::RubyLex.tokenize text, options
198
+
199
+ "\n<pre class=\"ruby\">" \
200
+ "#{RDoc::TokenStream.to_html tokens}" \
201
+ "</pre>\n"
202
+ rescue RDoc::RubyLex::Error
203
+ "\n<pre>#{CGI.escapeHTML text}</pre>\n"
204
+ end
205
+ else
206
+ "\n<pre>#{CGI.escapeHTML text}</pre>\n"
207
+ end
154
208
  end
155
209
 
156
210
  ##
@@ -208,12 +262,19 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
208
262
  end
209
263
 
210
264
  ##
211
- # Adds +heading+ to the output
265
+ # Adds +heading+ to the output. The headings greater than 6 are trimmed to
266
+ # level 6.
267
+
268
+ def accept_heading heading
269
+ level = [6, heading.level].min
270
+
271
+ label = heading.label
272
+ label = [@code_object.aref, label].compact.join '-' if
273
+ @code_object and @code_object.respond_to? :aref
212
274
 
213
- def accept_heading(heading)
214
- @res << "\n<h#{heading.level}>"
275
+ @res << "\n<h#{level} id=\"#{label}\">"
215
276
  @res << to_html(heading.text)
216
- @res << "</h#{heading.level}>\n"
277
+ @res << "</h#{level}>\n"
217
278
  end
218
279
 
219
280
  ##
@@ -233,11 +294,15 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
233
294
  end
234
295
 
235
296
  ##
236
- # Generate a link for +url+, labeled with +text+. Handles the special cases
297
+ # Generate a link to +url+ with content +text+. Handles the special cases
237
298
  # for img: and link: described under handle_special_HYPERLINK
238
299
 
239
- def gen_url(url, text)
240
- if url =~ /([A-Za-z]+):(.*)/ then
300
+ def gen_url url, text
301
+ if url =~ /^rdoc-label:([^:]*)(?::(.*))?/ then
302
+ type = "link"
303
+ path = "##{$1}"
304
+ id = " id=\"#{$2}\"" if $2
305
+ elsif url =~ /([A-Za-z]+):(.*)/ then
241
306
  type = $1
242
307
  path = $2
243
308
  else
@@ -258,7 +323,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
258
323
  url =~ /\.(gif|png|jpg|jpeg|bmp)$/ then
259
324
  "<img src=\"#{url}\" />"
260
325
  else
261
- "<a href=\"#{url}\">#{text.sub(%r{^#{type}:/*}, '')}</a>"
326
+ "<a#{id} href=\"#{url}\">#{text.sub(%r{^#{type}:/*}, '')}</a>"
262
327
  end
263
328
  end
264
329
 
@@ -275,9 +340,9 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
275
340
  # Maps attributes to HTML tags
276
341
 
277
342
  def init_tags
278
- add_tag :BOLD, "<b>", "</b>"
279
- add_tag :TT, "<tt>", "</tt>"
280
- add_tag :EM, "<em>", "</em>"
343
+ add_tag :BOLD, "<strong>", "</strong>"
344
+ add_tag :TT, "<code>", "</code>"
345
+ add_tag :EM, "<em>", "</em>"
281
346
  end
282
347
 
283
348
  ##
@@ -288,10 +353,8 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
288
353
  case list_type
289
354
  when :BULLET, :LALPHA, :NUMBER, :UALPHA then
290
355
  "<li>"
291
- when :LABEL then
292
- "<dt>#{to_html list_item.label}</dt>\n<dd>"
293
- when :NOTE then
294
- "<tr><td class=\"rdoc-term\"><p>#{to_html list_item.label}</p></td>\n<td>"
356
+ when :LABEL, :NOTE then
357
+ "<dt>#{to_html list_item.label}\n<dd>"
295
358
  else
296
359
  raise RDoc::Error, "Invalid list type: #{list_type.inspect}"
297
360
  end
@@ -304,15 +367,20 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
304
367
  case list_type
305
368
  when :BULLET, :LALPHA, :NUMBER, :UALPHA then
306
369
  "</li>"
307
- when :LABEL then
370
+ when :LABEL, :NOTE then
308
371
  "</dd>"
309
- when :NOTE then
310
- "</td></tr>"
311
372
  else
312
373
  raise RDoc::Error, "Invalid list type: #{list_type.inspect}"
313
374
  end
314
375
  end
315
376
 
377
+ ##
378
+ # Returns true if Ripper is available it can create a sexp from +text+
379
+
380
+ def parseable? text
381
+ text =~ /\b(def|class|module|require)\b|=>|\{\s?\||do \|/
382
+ end
383
+
316
384
  ##
317
385
  # Converts +item+ to HTML using RDoc::Text#to_html
318
386