From 810008293fd8ce3a9d3d62dcf2f2229b98c2bd49 Mon Sep 17 00:00:00 2001 From: drbrain Date: Sun, 16 Dec 2012 23:07:49 +0000 Subject: * lib/rdoc.rb: Updated VERSION. * lib/rdoc/markup/attribute_manager.rb: Removed useless empty check. * lib/rdoc/markup/to_markdown.rb: Support links from other formats. * lib/rdoc/markup/formatter.rb: ditto. * lib/rdoc/markup/to_html.rb: ditto. * test/rdoc/test_rdoc_markup_formatter.rb: Test for above. * test/rdoc/test_rdoc_markup_to_html.rb: ditto. * test/rdoc/test_rdoc_markup_to_markdown.rb: ditto. * lib/rdoc/rd/block_parser.rb: Improved footnote display. Worked around bug in footnote conversion to Markdown. * test/rdoc/test_rdoc_rd_block_parser.rb: Test for above. * lib/rdoc/rd/inline_parser.rb: Fixed bug with emphasis inside verbatim. * test/rdoc/test_rdoc_rd_inline_parser.rb: Test for above. * test/rdoc/test_rdoc_parser_rd.rb: Use mu_pp, use shortcut methods. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38418 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/rdoc/markup/formatter.rb | 75 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) (limited to 'lib/rdoc/markup/formatter.rb') diff --git a/lib/rdoc/markup/formatter.rb b/lib/rdoc/markup/formatter.rb index a5f639c28c..b668746c7a 100644 --- a/lib/rdoc/markup/formatter.rb +++ b/lib/rdoc/markup/formatter.rb @@ -17,6 +17,30 @@ class RDoc::Markup::Formatter InlineTag = Struct.new(:bit, :on, :off) + ## + # 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 "/" + + from.delete '.' + to.delete '.' + + 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 + ## # Creates a new Formatter @@ -35,6 +59,7 @@ class RDoc::Markup::Formatter @tt_bit = @attributes.bitmap_for :TT @hard_break = '' + @from_path = '.' end ## @@ -51,6 +76,26 @@ class RDoc::Markup::Formatter end end + ## + # Adds a special for links of the form rdoc-...: + + def add_special_RDOCLINK + @markup.add_special(/rdoc-[a-z]+:\S+/, :RDOCLINK) + end + + ## + # Adds a special for links of the form {}[] and [] + + def add_special_TIDYLINK + @markup.add_special(/(?: + \{.*?\} | # multi-word label + \b[^\s{}]+? # single-word label + ) + + \[\S+?\] # link target + /x, :TIDYLINK) + end + ## # Add a new set of tags for an attribute. We allow separate start and end # tags for flexibility @@ -178,6 +223,36 @@ class RDoc::Markup::Formatter end end + ## + # Extracts and a scheme, url and an anchor id from +url+ and returns them. + + def parse_url url + case url + when /^rdoc-label:([^:]*)(?::(.*))?/ then + scheme = 'link' + path = "##{$1}" + id = " id=\"#{$2}\"" if $2 + when /([A-Za-z]+):(.*)/ then + scheme = $1.downcase + path = $2 + when /^#/ then + else + scheme = 'http' + path = url + url = "http://#{url}" + end + + if scheme == 'link' then + url = if path[0, 1] == '#' then # is this meaningful? + path + else + self.class.gen_relative_url @from_path, path + end + end + + [scheme, url, id] + end + ## # Is +tag+ a tt tag? -- cgit v1.2.3