require 'rdoc/markup/formatter' require 'rdoc/markup/fragments' require 'rdoc/markup/inline' 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 # @in_tt - tt nested levels count # @tt_bit - cache @in_tt = 0 @tt_bit = RDoc::Markup::Attribute.bitmap_for :TT # 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 ## # Converts a target url to one that is relative to a given path def self.gen_relative_url(path, target) from = File.dirname path to, to_file = File.split target from = from.split "/" to = to.split "/" while from.size > 0 and to.size > 0 and from[0] == to[0] do from.shift to.shift end from.fill ".." from.concat to from << to_file File.join(*from) 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 self.class.gen_relative_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 #