Skip to content

Commit 5341dbe

Browse files
authored
Merge pull request #804 from nobu/rdoc-links-label
Allow a label in a link to another document text
2 parents 9872c4b + 424bd5d commit 5341dbe

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
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((?!https?:)(?:[^/#]*/)*+)([^/#]+)\.(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: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -739,24 +739,42 @@ def test_gen_url_ssl_image_url
739739
end
740740

741741
def test_gen_url_rdoc_file
742+
assert_equal '<a href="example_rdoc.html">example</a>',
743+
@to.gen_url('example.rdoc', 'example')
742744
assert_equal '<a href="doc/example_rdoc.html">example</a>',
743745
@to.gen_url('doc/example.rdoc', 'example')
744-
assert_equal '<a href="../ex_doc/example_rdoc.html">example</a>',
746+
assert_equal '<a href="../ex.doc/example_rdoc.html">example</a>',
745747
@to.gen_url('../ex.doc/example.rdoc', 'example')
748+
assert_equal '<a href="doc/example_rdoc.html#label-one">example</a>',
749+
@to.gen_url('doc/example.rdoc#label-one', 'example')
750+
assert_equal '<a href="../ex.doc/example_rdoc.html#label-two">example</a>',
751+
@to.gen_url('../ex.doc/example.rdoc#label-two', 'example')
746752
end
747753

748754
def test_gen_url_md_file
755+
assert_equal '<a href="example_md.html">example</a>',
756+
@to.gen_url('example.md', 'example')
749757
assert_equal '<a href="doc/example_md.html">example</a>',
750758
@to.gen_url('doc/example.md', 'example')
751-
assert_equal '<a href="../ex_doc/example_md.html">example</a>',
759+
assert_equal '<a href="../ex.doc/example_md.html">example</a>',
752760
@to.gen_url('../ex.doc/example.md', 'example')
761+
assert_equal '<a href="doc/example_md.html#label-one">example</a>',
762+
@to.gen_url('doc/example.md#label-one', 'example')
763+
assert_equal '<a href="../ex.doc/example_md.html#label-two">example</a>',
764+
@to.gen_url('../ex.doc/example.md#label-two', 'example')
753765
end
754766

755767
def test_gen_url_rb_file
768+
assert_equal '<a href="example_rb.html">example</a>',
769+
@to.gen_url('example.rb', 'example')
756770
assert_equal '<a href="doc/example_rb.html">example</a>',
757771
@to.gen_url('doc/example.rb', 'example')
758-
assert_equal '<a href="../ex_doc/example_rb.html">example</a>',
772+
assert_equal '<a href="../ex.doc/example_rb.html">example</a>',
759773
@to.gen_url('../ex.doc/example.rb', 'example')
774+
assert_equal '<a href="doc/example_rb.html#label-one">example</a>',
775+
@to.gen_url('doc/example.rb#label-one', 'example')
776+
assert_equal '<a href="../ex.doc/example_rb.html#label-two">example</a>',
777+
@to.gen_url('../ex.doc/example.rb#label-two', 'example')
760778
end
761779

762780
def test_handle_regexp_HYPERLINK_link

0 commit comments

Comments
 (0)