Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/rdoc/markup/to_html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,8 @@ def gen_url url, text
url =~ /\.(gif|png|jpg|jpeg|bmp)$/ then
"<img src=\"#{url}\" />"
else
if scheme != 'link' and /\.(?:rb|rdoc|md)\z/i =~ url
url = url.sub(%r%\A([./]*)(.*)\z%) { "#$1#{$2.tr('.', '_')}.html" }
if scheme != 'link' and %r%\A((?!https?:)(?:[^/#]*/)*+)([^/#]+)\.(rb|rdoc|md)(?=\z|#)%i =~ url
url = "#$1#{$2.tr('.', '_')}_#$3.html#$'"
end

text = text.sub %r%^#{scheme}:/*%i, ''
Expand Down
24 changes: 21 additions & 3 deletions test/rdoc/test_rdoc_markup_to_html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -739,24 +739,42 @@ def test_gen_url_ssl_image_url
end

def test_gen_url_rdoc_file
assert_equal '<a href="example_rdoc.html">example</a>',
@to.gen_url('example.rdoc', 'example')
assert_equal '<a href="doc/example_rdoc.html">example</a>',
@to.gen_url('doc/example.rdoc', 'example')
assert_equal '<a href="../ex_doc/example_rdoc.html">example</a>',
assert_equal '<a href="../ex.doc/example_rdoc.html">example</a>',
@to.gen_url('../ex.doc/example.rdoc', 'example')
assert_equal '<a href="doc/example_rdoc.html#label-one">example</a>',
@to.gen_url('doc/example.rdoc#label-one', 'example')
assert_equal '<a href="../ex.doc/example_rdoc.html#label-two">example</a>',
@to.gen_url('../ex.doc/example.rdoc#label-two', 'example')
end

def test_gen_url_md_file
assert_equal '<a href="example_md.html">example</a>',
@to.gen_url('example.md', 'example')
assert_equal '<a href="doc/example_md.html">example</a>',
@to.gen_url('doc/example.md', 'example')
assert_equal '<a href="../ex_doc/example_md.html">example</a>',
assert_equal '<a href="../ex.doc/example_md.html">example</a>',
@to.gen_url('../ex.doc/example.md', 'example')
assert_equal '<a href="doc/example_md.html#label-one">example</a>',
@to.gen_url('doc/example.md#label-one', 'example')
assert_equal '<a href="../ex.doc/example_md.html#label-two">example</a>',
@to.gen_url('../ex.doc/example.md#label-two', 'example')
end

def test_gen_url_rb_file
assert_equal '<a href="example_rb.html">example</a>',
@to.gen_url('example.rb', 'example')
assert_equal '<a href="doc/example_rb.html">example</a>',
@to.gen_url('doc/example.rb', 'example')
assert_equal '<a href="../ex_doc/example_rb.html">example</a>',
assert_equal '<a href="../ex.doc/example_rb.html">example</a>',
@to.gen_url('../ex.doc/example.rb', 'example')
assert_equal '<a href="doc/example_rb.html#label-one">example</a>',
@to.gen_url('doc/example.rb#label-one', 'example')
assert_equal '<a href="../ex.doc/example_rb.html#label-two">example</a>',
@to.gen_url('../ex.doc/example.rb#label-two', 'example')
end

def test_handle_regexp_HYPERLINK_link
Expand Down