Skip to content

Commit 85bb2d3

Browse files
committed
Allow a label in a link to another document text
1 parent ec17a3e commit 85bb2d3

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/rdoc/markup/to_html.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,8 @@ 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" }
360+
if scheme != 'link' and %r%\A([./]*+)(.*?\.)(rb|rdoc|md)(?=\z|#)%i =~ url
361+
url = "#$1#{$2.tr('.', '_')}#$3.html#{$'}"
362362
end
363363

364364
text = text.sub %r%^#{scheme}:/*%i, ''

test/rdoc/test_rdoc_markup_to_html.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,20 +743,32 @@ def test_gen_url_rdoc_file
743743
@to.gen_url('doc/example.rdoc', 'example')
744744
assert_equal '<a href="../ex_doc/example_rdoc.html">example</a>',
745745
@to.gen_url('../ex.doc/example.rdoc', 'example')
746+
assert_equal '<a href="doc/example_rdoc.html#label-one">example</a>',
747+
@to.gen_url('doc/example.rdoc#label-one', 'example')
748+
assert_equal '<a href="../ex_doc/example_rdoc.html#label-two">example</a>',
749+
@to.gen_url('../ex.doc/example.rdoc#label-two', 'example')
746750
end
747751

748752
def test_gen_url_md_file
749753
assert_equal '<a href="doc/example_md.html">example</a>',
750754
@to.gen_url('doc/example.md', 'example')
751755
assert_equal '<a href="../ex_doc/example_md.html">example</a>',
752756
@to.gen_url('../ex.doc/example.md', 'example')
757+
assert_equal '<a href="doc/example_md.html#label-one">example</a>',
758+
@to.gen_url('doc/example.md#label-one', 'example')
759+
assert_equal '<a href="../ex_doc/example_md.html#label-two">example</a>',
760+
@to.gen_url('../ex.doc/example.md#label-two', 'example')
753761
end
754762

755763
def test_gen_url_rb_file
756764
assert_equal '<a href="doc/example_rb.html">example</a>',
757765
@to.gen_url('doc/example.rb', 'example')
758766
assert_equal '<a href="../ex_doc/example_rb.html">example</a>',
759767
@to.gen_url('../ex.doc/example.rb', 'example')
768+
assert_equal '<a href="doc/example_rb.html#label-one">example</a>',
769+
@to.gen_url('doc/example.rb#label-one', 'example')
770+
assert_equal '<a href="../ex_doc/example_rb.html#label-two">example</a>',
771+
@to.gen_url('../ex.doc/example.rb#label-two', 'example')
760772
end
761773

762774
def test_handle_regexp_HYPERLINK_link

0 commit comments

Comments
 (0)