RDocSupport::HyperLinkHtml (Class)

In: libraries/rdocsupport.rb
Parent: SM::ToHtml

Handle special hyperlinking requirments for RDoc formatted entries. Requires RDoc

Public Class methods

Initialize the HyperLinkHtml object.

path
location of the node
site
object representing the whole site (typically of class
     +Site+)

[Source]

    # File libraries/rdocsupport.rb, line 53
53:   def initialize
54:     super()
55:     add_tag(:CENTER, "<center>", "</center>")
56:   end

Public Instance methods

handle <br/>

[Source]

    # File libraries/rdocsupport.rb, line 59
59:   def handle_special_BR(special)
60:     return "&lt;br/&gt" if special.text[0,1] == '\\'
61:     special.text
62:   end

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.
img:
insert a <img> tag
link:
used to insert arbitrary <a> references
anchor:
used to create an anchor

[Source]

     # File libraries/rdocsupport.rb, line 73
 73:   def handle_special_HYPERLINK(special)
 74:       text = special.text.strip
 75:       return text[1..-1] if text[0,1] == '\\'
 76:       url = special.text.strip
 77:       if url =~ /([A-Za-z]+):(.*)/
 78:         type = $1
 79:         path = $2
 80:       else
 81:         type = "http"
 82:         path = url
 83:         url  = "http://#{url}"
 84:       end
 85: 
 86:       case type 
 87:       when "http"
 88:         if url =~ /\.(gif|png|jpg|jpeg|bmp)$/
 89:           "<img src=\"#{url}\"/>"
 90:         else
 91:           "<a href=\"#{url}\">#{url.sub(%r{^\w+:/*}, '')}</a>"
 92:         end
 93:       when "img"
 94:         "<img src=\"#{path}\"/>"
 95:       when "link"
 96:         "<a href=\"#{path}\">#{path}</a>"
 97:       when "anchor"
 98:         "<a name=\"#{path}\"></a>"
 99:       else
100:         "<a href=\"#{url}\">#{url.sub(%r{^\w+:/*}, '')}</a>"
101:       end
102:     end

Here’s a hyperlink where the label is different to the URL

 [[url label that may contain spaces]]

[Source]

     # File libraries/rdocsupport.rb, line 108
108:     def handle_special_TIDYLINK(special)
109:       text = special.text.strip
110:       return text[1..-1] if text[0,1] == '\\'
111:       unless text =~ /\[\[(\S+?)\s+(.+?)\]\]/
112:         return text
113:       end
114:       url   = $1
115:       label = $2
116:       label = RDocFormatter.new(label).to_html
117:       label = label.split.select{|x| x =~ /\S/}.
118:         map{|x| x.chomp}.join(' ')
119: 
120:       case url
121:       when /link:(\S+)/
122:         return %{<a href="#{$1}">#{label}</a>}
123:       when /img:(\S+)/
124:         return %{<img src="http://#{$1}" alt="#{label}" />}
125:       when /rubytalk:(\S+)/
126:         return %{<a href="http://ruby-talk.org/blade/#{$1}">#{label}</a>}
127:       when /rubygarden:(\S+)/
128:         return %{<a href="http://www.rubygarden.org/ruby?#{$1}">#{label}</a>}
129:       when /c2:(\S+)/
130:         return %{<a href="http://c2.com/cgi/wiki?#{$1}">#{label}</a>}
131:       when /isbn:(\S+)/
132:         return %{<a href="http://search.barnesandnoble.com/bookSearch/} +
133:           %{isbnInquiry.asp?isbn=#{$1}">#{label}</a>}
134:       end
135: 
136:       unless url =~ /\w+?:/
137:         url = "http://#{url}"
138:       end
139: 
140:       "<a href=\"#{url}\">#{label}</a>"
141:     end

[Validate]