begin require "rdoc/markup/simple_markup" require 'rdoc/markup/simple_markup/to_html' rescue LoadError # Ruby 1.9 require "rdoc/markup" require 'rdoc/markup/to_html' module SM class SimpleMarkup < RDoc::Markup end class ToHtml description with spaces]] add_special(/((\\)?\[\[\S+?\s+.+?\]\])/,:TIDYLINK) # and external references add_special(/((\\)?(link:|anchor:|http:|mailto:|ftp:|img:|www\.)\S+\w\/?)/, :HYPERLINK) #
add_special(%r{(#{pre}
)}, :BR) # and
...
add_html("center", :CENTER) end def convert(text, handler) super.sub(/^

\n/, '').sub(/<\/p>$/, '') end end # Handle special hyperlinking requirments for RDoc formatted # entries. Requires RDoc class HyperLinkHtml < SM::ToHtml # Initialize the HyperLinkHtml object. # [path] location of the node # [site] object representing the whole site (typically of class # +Site+) def initialize super() add_tag(:CENTER, "

", "
") end # handle
def handle_special_BR(special) return "<br/>" if special.text[0,1] == '\\' special.text 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 tag. Otherwise a conventional # is used. # [img:] insert a tag # [link:] used to insert arbitrary references # [anchor:] used to create an anchor def handle_special_HYPERLINK(special) text = special.text.strip return text[1..-1] if text[0,1] == '\\' url = special.text.strip if url =~ /([A-Za-z]+):(.*)/ type = $1 path = $2 else type = "http" path = url url = "http://#{url}" end case type when "http" if url =~ /\.(gif|png|jpg|jpeg|bmp)$/ "" else "#{url.sub(%r{^\w+:/*}, '')}" end when "img" "" when "link" "#{path}" when "anchor" "" else "#{url.sub(%r{^\w+:/*}, '')}" end end # Here's a hyperlink where the label is different to the URL # [[url label that may contain spaces]] # def handle_special_TIDYLINK(special) text = special.text.strip return text[1..-1] if text[0,1] == '\\' unless text =~ /\[\[(\S+?)\s+(.+?)\]\]/ return text end url = $1 label = $2 label = RDocFormatter.new(label).to_html label = label.split.select{|x| x =~ /\S/}. map{|x| x.chomp}.join(' ') case url when /link:(\S+)/ return %{#{label}} when /img:(\S+)/ return %{#{label}} when /rubytalk:(\S+)/ return %{#{label}} when /rubygarden:(\S+)/ return %{#{label}} when /c2:(\S+)/ return %{#{label}} when /isbn:(\S+)/ return %{#{label}} end unless url =~ /\w+?:/ url = "http://#{url}" end "#{label}" end end class RDocFormatter def initialize(text) @text = text end def to_html markup = RDocMarkup.new h = HyperLinkHtml.new markup.convert(@text, h) end end end