27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/wikilink/converter/utils.rb', line 27
def link_to(name, url, attributes = {})
attributes[:class] = Array(attributes[:class]).flatten.join(' ').split.uniq.join(' ')
attributes.delete(:class) if attributes[:class].empty?
attributes = attributes.inject('') do |memo, (key, value)|
memo + key.to_s + '="' + CGI.escape_html(value) + '" '
end
url, fragment = url.split('#', 2)
if fragment
url << '#' + URI.encode(fragment, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
end
%Q{<a #{attributes}href="#{url}">#{CGI.escape_html name}</a>}
end
|