lib/yard/templates/helpers/html_helper.rb in yard-0.5.4 vs lib/yard/templates/helpers/html_helper.rb in yard-0.5.5
- old
+ new
@@ -120,37 +120,31 @@
# @param [String] text the text to resolve links in
# @return [String] HTML with linkified references
def resolve_links(text)
code_tags = 0
text.gsub(/<(\/)?(pre|code|tt)|\{(\S+?)(?:\s(.*?\S))?\}(?=[\W<]|.+<\/|$)/) do |str|
- tag = $2
- closed = $1
+ closed, tag, name, title = $1, $2, $3, $4
if tag
code_tags += (closed ? -1 : 1)
next str
end
next str unless code_tags == 0
- name = $3
- title = $4 || name
-
- case name
- when %r{://}, /^mailto:/
- link_url(name, title, :target => '_parent')
- when /^file:(\S+?)(?:#(\S+))?$/
- link_file($1, title == name ? $1 : title, $2)
+ if object.is_a?(String)
+ object
else
- if object.is_a?(String)
- obj = name
+ link = linkify(name, title)
+ if link == name || link == title
+ match = text[/(.{0,20}\{.*?#{Regexp.quote name}.*?\}.{0,20})/, 1]
+ log.warn "In file `#{object.file}':#{object.line}: Cannot resolve link to #{name} from text" + (match ? ":" : ".")
+ log.warn '...' + match.gsub(/\n/,"\n\t") + '...' if match
+ end
+
+ if name =~ %r{://} || name =~ /^(mailto|file):/
+ link
else
- obj = Registry.resolve(object, name, true, true)
- if obj.is_a?(CodeObjects::Proxy)
- match = text[/(.{0,20}\{.*?#{Regexp.quote name}.*?\}.{0,20})/, 1]
- log.warn "In file `#{object.file}':#{object.line}: Cannot resolve link to #{obj.path} from text" + (match ? ":" : ".")
- log.warn '...' + match.gsub(/\n/,"\n\t") + '...' if match
- end
- "<tt>" + linkify(obj, title) + "</tt>"
+ "<tt>" + link + "</tt>"
end
end
end
end
@@ -197,20 +191,20 @@
title = h(object.relative_path(obj))
else
title = h(obj.to_s)
end
return title unless serializer
-
return title if obj.is_a?(CodeObjects::Proxy)
-
+
link = url_for(obj, anchor, relative)
link ? link_url(link, title, :title => "#{obj.path} (#{obj.type})") : title
end
def link_url(url, title = nil, params = {})
+ title ||= url
params = SymbolHash.new(false).update(
:href => url,
- :title => h(title || url)
+ :title => h(title)
).update(params)
"<a #{tag_attrs(params)}>#{title}</a>"
end
def tag_attrs(opts = {})