require 'rdoc/markup/formatter' require 'rdoc/markup/fragments' require 'rdoc/markup/inline' require 'rdoc/generator' require 'cgi' class RDoc::Markup::ToHtml < RDoc::Markup::Formatter LIST_TYPE_TO_HTML = { :BULLET => %w[], :NUMBER => %w[
], :UPPERALPHA => %w[
], :LOWERALPHA => %w[
], :LABELED => %w[
], :NOTE => %w[
], } InlineTag = Struct.new(:bit, :on, :off) def initialize super # external hyperlinks @markup.add_special(/((link:|https?:|mailto:|ftp:|www\.)\S+\w)/, :HYPERLINK) # and links of the form [] @markup.add_special(/(((\{.*?\})|\b\S+?)\[\S+?\.\S+?\])/, :TIDYLINK) init_tags end ## # Generate a hyperlink for url, labeled with text. Handle the # special cases for img: and link: described under handle_special_HYPEDLINK def gen_url(url, text) if url =~ /([A-Za-z]+):(.*)/ then type = $1 path = $2 else type = "http" path = url url = "http://#{url}" end if type == "link" then url = if path[0, 1] == '#' then # is this meaningful? path else RDoc::Generator.gen_url @from_path, path end end if (type == "http" or type == "link") and url =~ /\.(gif|png|jpg|jpeg|bmp)$/ then "" else "#{text.sub(%r{^#{type}:/*}, '')}" 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 # tag. Otherwise a conventional 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. 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 #