diff options
author | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-02-12 22:23:00 +0000 |
---|---|---|
committer | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-02-12 22:23:00 +0000 |
commit | 33fc7dc3cfa98bbbc4b5c615edb23c37f588b5e4 (patch) | |
tree | eb49501cbc096c12759bc4d92d080dfdfd196710 /lib/rdoc/markup/to_html.rb | |
parent | a8589e18fc1824fa642febc61532a1d2b8418716 (diff) | |
download | ruby-33fc7dc3cfa98bbbc4b5c615edb23c37f588b5e4.tar.gz ruby-33fc7dc3cfa98bbbc4b5c615edb23c37f588b5e4.tar.xz ruby-33fc7dc3cfa98bbbc4b5c615edb23c37f588b5e4.zip |
Separate HTML linking and crossreferencing into separate files.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@15453 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rdoc/markup/to_html.rb')
-rw-r--r-- | lib/rdoc/markup/to_html.rb | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/lib/rdoc/markup/to_html.rb b/lib/rdoc/markup/to_html.rb index 4fe16f8e9..3a500a4f0 100644 --- a/lib/rdoc/markup/to_html.rb +++ b/lib/rdoc/markup/to_html.rb @@ -20,10 +20,73 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter def initialize super + # external hyperlinks + @markup.add_special(/((link:|https?:|mailto:|ftp:|www\.)\S+\w)/, :HYPERLINK) + + # and links of the form <text>[<url>] + @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 + HTML.gen_url @from_path, path + end + end + + if (type == "http" or type == "link") and + url =~ /\.(gif|png|jpg|jpeg|bmp)$/ then + "<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. + + 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] or {long label}[url] + + def handle_special_TIDYLINK(special) + text = special.text + + return text unless text =~ /\{(.*?)\}\[(.*?)\]/ or text =~ /(\S+)\[(.*?)\]/ + + label = $1 + url = $2 + gen_url url, label + end + + ## # Set up the standard mapping of attributes to HTML tags def init_tags |