Skip to content

Commit 2810ec5

Browse files
authored
Merge pull request #800 from nobu/rdoc-links
Links to document texts without "rdoc-ref:" prefix
2 parents 3f2bd42 + f18b27b commit 2810ec5

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

lib/rdoc/markup/to_html.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,10 @@ def gen_url url, text
357357
url =~ /\.(gif|png|jpg|jpeg|bmp)$/ then
358358
"<img src=\"#{url}\" />"
359359
else
360+
if scheme != 'link' and /\.(?:rb|rdoc|md)\z/i =~ url
361+
url = url.sub(%r%\A([./]*)(.*)\z%) { "#$1#{$2.tr('.', '_')}.html" }
362+
end
363+
360364
text = text.sub %r%^#{scheme}:/*%i, ''
361365
text = text.sub %r%^[*\^](\d+)$%, '\1'
362366

test/rdoc/test_rdoc_markup_to_html.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,27 @@ def test_gen_url_ssl_image_url
738738
assert_equal '<img src="https://example.com/image.png" />', @to.gen_url('https://example.com/image.png', 'ignored')
739739
end
740740

741+
def test_gen_url_rdoc_file
742+
assert_equal '<a href="doc/example_rdoc.html">example</a>',
743+
@to.gen_url('doc/example.rdoc', 'example')
744+
assert_equal '<a href="../ex_doc/example_rdoc.html">example</a>',
745+
@to.gen_url('../ex.doc/example.rdoc', 'example')
746+
end
747+
748+
def test_gen_url_md_file
749+
assert_equal '<a href="doc/example_md.html">example</a>',
750+
@to.gen_url('doc/example.md', 'example')
751+
assert_equal '<a href="../ex_doc/example_md.html">example</a>',
752+
@to.gen_url('../ex.doc/example.md', 'example')
753+
end
754+
755+
def test_gen_url_rb_file
756+
assert_equal '<a href="doc/example_rb.html">example</a>',
757+
@to.gen_url('doc/example.rb', 'example')
758+
assert_equal '<a href="../ex_doc/example_rb.html">example</a>',
759+
@to.gen_url('../ex.doc/example.rb', 'example')
760+
end
761+
741762
def test_handle_regexp_HYPERLINK_link
742763
target = RDoc::Markup::RegexpHandling.new 0, 'link:README.txt'
743764

test/rdoc/test_rdoc_top_level.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ def test_hash
157157

158158
def test_http_url
159159
assert_equal 'prefix/path/top_level_rb.html', @top_level.http_url('prefix')
160+
161+
other_level = @store.add_file 'path.other/level.rb'
162+
assert_equal 'prefix/path_other/level_rb.html', other_level.http_url('prefix')
160163
end
161164

162165
def test_last_modified

0 commit comments

Comments
 (0)