Generate a hyperlink for url, labeled with text. Handle the special cases for img: and link: described under handle_special_HYPEDLINK
# File lib/acts_as_markup/exts/rdoc.rb, line 8 def gen_url(url, text) if url =~ /([A-Za-z]+):(.*)/ type = $1 path = $2 else type = "http" path = url url = "http://#{url}" end if type == "link" if path[0,1] == '#' # is this meaningful? url = path else url = HTMLGenerator.gen_url(@from_path, path) end end if (type == "http" || type == "link") && url =~ /\.(gif|png|jpg|jpeg|bmp)$/ "<img src=\"#{url}\" />" else "<a href=\"#{url}\">#{text.sub(%r{^#{type}:/*}, '')}</a>" end end
And we’re invoked with a potential external hyperlink mailto: just gets inserted. http: links are checked to see if they reference an image. If so, that image gets inserted using an <img> tag. Otherwise a conventional <a href> is used. We also support a special type of hyperlink, link:, which is a reference to a local file whose path is relative to the –op directory.
# File lib/acts_as_markup/exts/rdoc.rb, line 40 def handle_special_HYPERLINK(special) url = special.text gen_url(url, url) end
Here’s a hypedlink where the label is different to the URL
<label>[url]
# File lib/acts_as_markup/exts/rdoc.rb, line 48 def handle_special_TIDYLINK(special) text = special.text unless text =~ /\{(.*?)\}\[(.*?)\]/ or text =~ /(\S+)\[(.*?)\]/ return text end label = $1 url = $2 gen_url(url, label) end