@@ -63,8 +63,8 @@ def cross_reference name, text = nil, code = true
6363
6464 name = name [ 1 ..-1 ] unless @show_hash if name [ 0 , 1 ] == '#'
6565
66- if !( name . end_with? ( '+@' , '-@' ) ) and name =~ /(.*[^#:])@/
67- text ||= " #{ CGI . unescape $' } at <code>#{ $1} </code>"
66+ if !( name . end_with? ( '+@' , '-@' ) ) and name =~ /(.*[^#:])? @/
67+ text ||= [ CGI . unescape ( $' ) , ( " at <code>#{ $1} </code>" if $~ . begin ( 1 ) ) ] . join ( "" )
6868 code = false
6969 else
7070 text ||= name
@@ -139,35 +139,34 @@ def gen_url url, text
139139 # Creates an HTML link to +name+ with the given +text+.
140140
141141 def link name , text , code = true
142- if !( name . end_with? ( '+@' , '-@' ) ) and name =~ /(.*[^#:])@/
142+ if !( name . end_with? ( '+@' , '-@' ) ) and name =~ /(.*[^#:])? @/
143143 name = $1
144144 label = $'
145145 end
146146
147- ref = @cross_reference . resolve name , text
147+ ref = @cross_reference . resolve name , text if name
148148
149149 case ref
150150 when String then
151151 ref
152152 else
153- path = ref . as_href @from_path
153+ path = ref ? ref . as_href ( @from_path ) : + ""
154154
155155 if code and RDoc ::CodeObject === ref and !( RDoc ::TopLevel === ref )
156156 text = "<code>#{ CGI . escapeHTML text } </code>"
157157 end
158158
159- if path =~ /#/ then
160- path << "-label-#{ label } "
161- elsif ref . sections and
162- ref . sections . any? { |section | label == section . title } then
163- path << "##{ label } "
164- else
165- if ref . respond_to? ( :aref )
159+ if label
160+ if path =~ /#/
161+ path << "-label-#{ label } "
162+ elsif ref &.sections &.any? { |section | label == section . title }
163+ path << "##{ label } "
164+ elsif ref . respond_to? ( :aref )
166165 path << "##{ ref . aref } -label-#{ label } "
167166 else
168167 path << "#label-#{ label } "
169168 end
170- end if label
169+ end
171170
172171 "<a href=\" #{ path } \" >#{ text } </a>"
173172 end
0 commit comments