@@ -112,6 +112,7 @@ def initialize(from_path, context, show_hash, hyperlink_all = false,
112112 crossref_re = hyperlink_all ? ALL_CROSSREF_REGEXP : CROSSREF_REGEXP
113113
114114 @markup . add_special crossref_re , :CROSSREF
115+ @markup . add_special /rdoc:\S +\w / , :HYPERLINK
115116
116117 @from_path = from_path
117118 @context = context
@@ -122,28 +123,18 @@ def initialize(from_path, context, show_hash, hyperlink_all = false,
122123 end
123124
124125 ##
125- # We're invoked when any text matches the CROSSREF pattern. If we find the
126- # corresponding reference, generate a hyperlink. If the name we're looking
127- # for contains no punctuation, we look for it up the module/class chain.
128- # For example, ToHtml is found, even without the <tt>RDoc::Markup::</tt>
129- # prefix, because we look for it in module Markup first.
130-
131- def handle_special_CROSSREF ( special )
132- name = special . text
133-
134- unless @hyperlink_all then
135- # This ensures that words entirely consisting of lowercase letters will
136- # not have cross-references generated (to suppress lots of erroneous
137- # cross-references to "new" in text, for instance)
138- return name if name =~ /\A [a-z]*\z /
139- end
126+ # Creates a link to the reference +name+ if the name exists. If +text+ is
127+ # given it is used as the link text, otherwise +name+ is used.
140128
129+ def cross_reference name , text = nil
141130 return @seen [ name ] if @seen . include? name
142131
143132 lookup = name
144133
145134 name = name [ 1 ..-1 ] unless @show_hash if name [ 0 , 1 ] == '#'
146135
136+ text = name unless text
137+
147138 # Find class, module, or method in class or module.
148139 #
149140 # Do not, however, use an if/elsif/else chain to do so. Instead, test
@@ -187,7 +178,7 @@ def handle_special_CROSSREF(special)
187178 ref ? $' : lookup
188179 elsif ref then
189180 if ref . document_self then
190- "<a href=\" #{ ref . as_href @from_path } \" >#{ name } </a>"
181+ "<a href=\" #{ ref . as_href @from_path } \" >#{ text } </a>"
191182 else
192183 name
193184 end
@@ -200,5 +191,43 @@ def handle_special_CROSSREF(special)
200191 out
201192 end
202193
194+ ##
195+ # We're invoked when any text matches the CROSSREF pattern. If we find the
196+ # corresponding reference, generate a hyperlink. If the name we're looking
197+ # for contains no punctuation, we look for it up the module/class chain.
198+ # For example, ToHtml is found, even without the <tt>RDoc::Markup::</tt>
199+ # prefix, because we look for it in module Markup first.
200+
201+ def handle_special_CROSSREF ( special )
202+ name = special . text
203+
204+ unless @hyperlink_all then
205+ # This ensures that words entirely consisting of lowercase letters will
206+ # not have cross-references generated (to suppress lots of erroneous
207+ # cross-references to "new" in text, for instance)
208+ return name if name =~ /\A [a-z]*\z /
209+ end
210+
211+ cross_reference name
212+ end
213+
214+ ##
215+ # Handles <tt>rdoc:</tt> scheme hyperlinks
216+
217+ def handle_special_HYPERLINK special
218+ return cross_reference $' if special . text =~ /\A rdoc:/
219+
220+ super
221+ end
222+
223+ ##
224+ # Generates links for <tt>rdoc:</tt> scheme URLs
225+
226+ def gen_url url , text
227+ super unless url =~ /\A rdoc:/
228+
229+ cross_reference $', text
230+ end
231+
203232end
204233
0 commit comments